X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=libextl%2Fluaextl.c;h=a2cc2b92759133a4d31fb7f87225a79bc52a3f69;hp=c53fde6fe74135cfdfda0b3fba924967c30d0ddd;hb=de22e45179cb3bafa490294d31d47f361047a30a;hpb=803afbc1cd633f6c025bcd9537e9b7e9aedadd0d diff --git a/libextl/luaextl.c b/libextl/luaextl.c index c53fde6..a2cc2b9 100644 --- a/libextl/luaextl.c +++ b/libextl/luaextl.c @@ -444,7 +444,7 @@ bool dopath(const char *what); static bool extl_init_obj_info(lua_State *st) { static ExtlExportedFnSpec dummy[]={ - {NULL, NULL, NULL, NULL, NULL, FALSE, FALSE} + {NULL, NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE} }; extl_register_class("Obj", dummy, NULL); @@ -1746,7 +1746,7 @@ static int extl_l1_call_handler2(lua_State *st) D(fprintf(stderr, "%s called\n", spec->name)); - if(!lua_checkstack(st, MAX_PARAMS+1)){ + if(!lua_checkstack(st, MAX_PARAMS+1)){ extl_warn(TR("Stack full.")); return 0; } @@ -1828,7 +1828,7 @@ static int extl_l1_call_handler(lua_State *st) return 0; } - if(param.spec->fn==NULL){ + if(!param.spec->registered){ extl_warn(TR("Called function has been unregistered.")); return 0; } @@ -1962,22 +1962,14 @@ static bool extl_do_register_function(lua_State *st, RegData *data) lua_rawgeti(st, LUA_REGISTRYINDEX, data->table); ind=-3; } - - lua_pushstring(st, spec->name); - - spec2=lua_newuserdata(st, sizeof(ExtlExportedFnSpec)); - memcpy(spec2, spec, sizeof(ExtlExportedFnSpec)); + lua_pushstring(st, spec->name); - lua_getregistry(st); - lua_pushvalue(st, -2); /* Get spec2 */ - lua_pushfstring(st, "luaextl_%s_%s_upvalue", - data->cls, spec->name); - lua_rawset_check(st, -3); /* Set registry.luaextl_fn_upvalue=spec2 */ - lua_pop(st, 1); /* Pop registry */ + lua_pushlightuserdata(st, spec); lua_pushcclosure(st, extl_l1_call_handler, 1); + lua_rawset_check(st, ind); - + return TRUE; } @@ -1998,6 +1990,7 @@ static bool extl_do_register_functions(ExtlExportedFnSpec *spec, int max, ®data)){ return FALSE; } + spec[i].registered=TRUE; } return TRUE; @@ -2018,28 +2011,8 @@ bool extl_register_functions(ExtlExportedFnSpec *spec) static bool extl_do_unregister_function(lua_State *st, RegData *data) { - ExtlExportedFnSpec *spec=data->spec, *spec2; + ExtlExportedFnSpec *spec=data->spec; int ind=LUA_GLOBALSINDEX; - - lua_getregistry(st); - lua_pushfstring(st, "luaextl_%s_%s_upvalue", - data->cls, spec->name); - lua_pushvalue(st, -1); - lua_gettable(st, -3); /* Get registry.luaextl_fn_upvalue */ - spec2=lua_touserdata(st, -1); - - if(spec2==NULL) - return FALSE; - - spec2->ispec=NULL; - spec2->ospec=NULL; - spec2->fn=NULL; - spec2->name=NULL; - spec2->l2handler=NULL; - - lua_pop(st, 1); /* Pop the upvalue */ - lua_pushnil(st); - lua_rawset_check(st, -3); /* Clear registry.luaextl_fn_upvalue */ if(data->table!=LUA_NOREF){ lua_rawgeti(st, LUA_REGISTRYINDEX, data->table); @@ -2069,6 +2042,7 @@ static void extl_do_unregister_functions(ExtlExportedFnSpec *spec, int max, regdata.spec=&(spec[i]); extl_cpcall(l_st, (ExtlCPCallFn*)extl_do_unregister_function, ®data); + spec[i].registered=FALSE; } }