adopted to graphviz version 10.0.1 and MACOS Sonoma
[luagraph.git] / src / gr_graph.h
blobe3e3042005e6bd67e04af0b999301cf9a5679fd6
1 #ifndef GR_GRAPH_INCL
2 #define GR_GRAPH_INCL
4 #include "lua.h"
5 #include "lauxlib.h"
7 /*
8 * Userdata in graph objects
9 */
10 #include "graphviz/gvcext.h"
11 #include "graphviz/gvc.h"
12 #include "graphviz/cgraph.h"
14 /*
15 * Set DOTRACE to 1 to track internal operations
17 #define DOTRACE 0
18 #if DOTRACE == 1
19 #define TRACE(fmt, ...) printf(fmt, __VA_ARGS__)
20 #else
21 #define TRACE(fmt, ...)
22 #endif
25 * Just to be sure we have it
27 #ifndef FALSE
28 #define FALSE (0)
29 #endif
30 #ifndef TRUE
31 #define TRUE (1)
32 #endif
34 #define ALIVE (1)
35 #define DEAD (0)
37 #define GR_SUCCESS (0)
38 #define GR_ERROR (1)
41 * Userdata checking options
43 #define STRICT (1)
44 #define NONSTRICT (0)
47 * LuaGRAPH's representation of graph objects
49 struct gr_graph_s {
50 int type;
51 Agraph_t *g;
52 char *name; /* only for debugging */
53 int status;
54 Agedge_t *lastedge;
56 typedef struct gr_graph_s gr_graph_t;
58 struct gr_node_s {
59 int type;
60 Agnode_t *n;
61 char *name; /* only for debugging */
62 int status;
64 typedef struct gr_node_s gr_node_t;
66 struct gr_edge_s {
67 int type;
68 Agedge_t *e;
69 char *name; /* only for debugging */
70 int status;
72 typedef struct gr_edge_s gr_edge_t;
74 union gr_object_s {
75 int type;
76 gr_graph_t g;
77 gr_node_t n;
78 gr_edge_t e;
79 struct {
80 int type;
81 void *p;
82 char *name; /* only for debugging */
83 int status;
84 } p;
86 typedef union gr_object_s gr_object_t;
88 /* callback structure */
89 struct gr_callback_s {
90 int typ;
91 lua_CFunction func;
93 typedef struct gr_callback_s gr_callback_t;
95 /* handler for __index metamethod */
96 typedef int (index_handler_t)(lua_State *L);
99 * Callback functions
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)
119 #else
120 #define register_metainfo(L, f) luaL_register(L, NULL, f)
121 #endif
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
157 * userdata objects.
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);
170 #endif