14 #include "lixp_debug.h"
15 #include "lixp_util.h"
16 #include "lixp_instance.h"
19 /* ------------------------------------------------------------------------
20 * lua: x = ixp.new("unix!/tmp/ns.bart.:0/wmii") -- create a new ixp object
22 static int l_new (lua_State
*L
)
28 adr
= luaL_checkstring (L
, 1);
30 DBGF("** ixp.new ([%s]) **\n", adr
);
34 return lixp_pusherror (L
, "could not open ixp connection");
36 ixp
= (struct ixp
*)lua_newuserdata(L
, sizeof (struct ixp
));
38 luaL_getmetatable (L
, L_IXP_MT
);
39 lua_setmetatable (L
, -2);
41 ixp
->address
= strdup (adr
);
47 static int l_ixp_gc (lua_State
*L
)
49 struct ixp
*ixp
= lixp_checkixp (L
, 1);
51 DBGF("** ixp:__gc (%p [%s]) **\n", ixp
, ixp
->address
);
53 ixp_unmount (ixp
->client
);
54 free ((char*)ixp
->address
);
59 /* ------------------------------------------------------------------------
60 * the class method table
62 static const luaL_reg class_table
[] =
69 /* ------------------------------------------------------------------------
70 * the instance method table
72 static const luaL_reg instance_table
[] =
74 { "__tostring", l_ixp_tostring
},
77 { "write", l_ixp_write
},
78 { "read", l_ixp_read
},
80 { "create", l_ixp_create
},
81 { "remove", l_ixp_remove
},
83 { "iread", l_ixp_iread
},
84 { "idir", l_ixp_idir
},
86 { "stat", l_ixp_stat
},
91 /* ------------------------------------------------------------------------
94 static int lixp_init_ixp_class (lua_State
*L
)
96 luaL_newmetatable(L
, L_IXP_MT
);
98 // setup the __index and __gc field
99 lua_pushstring (L
, "__index");
100 lua_pushvalue (L
, -2); // pushes the new metatable
101 lua_settable (L
, -3); // metatable.__index = metatable
103 luaL_openlib (L
, NULL
, instance_table
, 0);
104 luaL_openlib (L
, "ixp", class_table
, 0);
107 luaL_register (L
, MYNAME
, R
);
108 lua_pushliteral (L
, "version");
109 lua_pushliteral (L
, MYVERSION
);
110 lua_settable (L
, -3);
115 /* ------------------------------------------------------------------------
118 LUALIB_API
int luaopen_ixp (lua_State
*L
)
120 lixp_init_iread_mt (L
);
121 lixp_init_idir_mt (L
);
123 return lixp_init_ixp_class (L
);