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);
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;
}
return 0;
}
- if(param.spec->fn==NULL){
+ if(!param.spec->registered){
extl_warn(TR("Called function has been unregistered."));
return 0;
}
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;
}
®data)){
return FALSE;
}
+ spec[i].registered=TRUE;
}
return TRUE;
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);
regdata.spec=&(spec[i]);
extl_cpcall(l_st, (ExtlCPCallFn*)extl_do_unregister_function,
®data);
+ spec[i].registered=FALSE;
}
}