parent
f03acc8b5c
commit
69d7e91fb6
|
@ -24,21 +24,25 @@
|
||||||
|
|
||||||
static void *uh_create_userdata(lua_State *L, size_t size, const luaL_Reg *reg, lua_CFunction gc)
|
static void *uh_create_userdata(lua_State *L, size_t size, const luaL_Reg *reg, lua_CFunction gc)
|
||||||
{
|
{
|
||||||
void *ret = lua_newuserdata(L, size);
|
void *obj = lua_newuserdata(L, size);
|
||||||
|
|
||||||
memset(ret, 0, size);
|
memset(obj, 0, size);
|
||||||
lua_createtable(L, 0, 2);
|
|
||||||
|
/* creare metatable */
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
/* metatable.__index = metatable */
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
lua_pushcfunction(L, gc);
|
lua_pushcfunction(L, gc);
|
||||||
lua_setfield(L, -2, "__gc");
|
lua_setfield(L, -2, "__gc");
|
||||||
lua_pushvalue(L, -1);
|
|
||||||
lua_setmetatable(L, -3);
|
|
||||||
lua_pushvalue(L, -2);
|
|
||||||
luaI_openlib(L, NULL, reg, 1);
|
|
||||||
lua_pushvalue(L, -2);
|
|
||||||
|
|
||||||
return ret;
|
luaL_setfuncs(L, reg, 0);
|
||||||
|
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void add_all_var(struct uh_client *cl, lua_State *L)
|
static inline void add_all_var(struct uh_client *cl, lua_State *L)
|
||||||
|
@ -276,7 +280,7 @@ static const luaL_Reg uhttpd_fun[] = {
|
||||||
|
|
||||||
int luaopen_uhttpd(lua_State *L)
|
int luaopen_uhttpd(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_createtable(L, 1, 0);
|
lua_newtable(L);
|
||||||
lua_setglobal(L, "__uh_action_cb");
|
lua_setglobal(L, "__uh_action_cb");
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
|
@ -26,14 +26,9 @@
|
||||||
/* Compatibility defines */
|
/* Compatibility defines */
|
||||||
#if LUA_VERSION_NUM <= 501
|
#if LUA_VERSION_NUM <= 501
|
||||||
|
|
||||||
#define lua_setuservalue(L, i) lua_setfenv((L), (i))
|
|
||||||
#define lua_getuservalue(L, i) lua_getfenv((L), (i))
|
|
||||||
|
|
||||||
/* NOTE: this only works if nups == 0! */
|
/* NOTE: this only works if nups == 0! */
|
||||||
#define luaL_setfuncs(L, fns, nups) luaL_register((L), NULL, (fns))
|
#define luaL_setfuncs(L, fns, nups) luaL_register((L), NULL, (fns))
|
||||||
|
|
||||||
#define lua_rawlen(L, i) lua_objlen((L), (i))
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct lua_uh_server {
|
struct lua_uh_server {
|
||||||
|
|
Loading…
Reference in New Issue