8 * Userdata in graph objects
10 #include "graphviz/gvcext.h"
11 #include "graphviz/gvc.h"
12 #include "graphviz/cgraph.h"
15 * Set DOTRACE to 1 to track internal operations
19 #define TRACE(fmt, ...) printf(fmt, __VA_ARGS__)
21 #define TRACE(fmt, ...)
25 * Just to be sure we have it
37 #define GR_SUCCESS (0)
41 * Userdata checking options
47 * LuaGRAPH's representation of graph objects
52 char *name
; /* only for debugging */
56 typedef struct gr_graph_s gr_graph_t
;
61 char *name
; /* only for debugging */
64 typedef struct gr_node_s gr_node_t
;
69 char *name
; /* only for debugging */
72 typedef struct gr_edge_s gr_edge_t
;
82 char *name
; /* only for debugging */
86 typedef union gr_object_s gr_object_t
;
88 /* callback structure */
89 struct gr_callback_s
{
93 typedef struct gr_callback_s gr_callback_t
;
95 /* handler for __index metamethod */
96 typedef int (index_handler_t
)(lua_State
*L
);
101 void cb_insert(struct Agraph_s
*g
, struct Agobj_s
*obj
, void *L
);
102 void cb_delete(Agraph_t
*g
, Agobj_t
*obj
, void *L
);
103 void cb_modify(Agraph_t
*g
, Agobj_t
*obj
, void *L
, Agsym_t
*sym
);
106 * Helper for auto naming.
108 unsigned int newid(void);
111 * Userdata to/from graph object conversion, retrival and creation
113 gr_object_t
*toobject(lua_State
*L
, int narg
, const char *type
, int strict
);
114 #define tograph(L, m, s) (&toobject(L, m, "graph", s)->g)
115 #define tonode(L, m, s) (&toobject(L, m, "node", s)->n)
116 #define toedge(L, m, s) (&toobject(L, m, "edge", s)->e)
117 #if LUA_VERSION_NUM >= 502
118 #define register_metainfo(L, f) luaL_setfuncs(L, f, 0)
120 #define register_metainfo(L, f) luaL_register(L, NULL, f)
123 int set_object(lua_State
*L
, void *key
);
124 int get_object(lua_State
*L
, void *key
);
125 int del_object(lua_State
*L
, void *key
);
128 * Graph object creation
130 int new_object(lua_State
*L
, const char *kind
, const luaL_Reg
*reg_rmembers
,
131 const luaL_Reg
*reg_methods
, const luaL_Reg
*reg_metamethods
,
132 index_handler_t
*index_handler
);
133 int new_edge(lua_State
*L
);
134 int new_node(lua_State
*L
);
137 * __index, __newindex metamethod handlers
139 int object_index_handler(lua_State
*L
);
140 int object_newindex_handler(lua_State
*L
);
141 int getval(lua_State
*L
);
144 * object delete/create methods
146 int gr_delete_node(lua_State
*L
);
147 int gr_create_node(lua_State
*L
);
148 int gr_delete_edge(lua_State
*L
);
151 * Generic object member/method handlers
153 int get_object_type(lua_State
*L
);
156 * generic function to be called in __gc metamethods of
159 int gr_collect(lua_State
*L
);
162 * generic status property - for all objects.
164 int gr_status(lua_State
*L
);
167 * Set the status of an object 1=alive 0=dead
169 int set_status(lua_State
*L
, void *key
, int status
);