void typel_pushinst(lua_State *state, typel_class *type, void *self, void *param) { if(!self) { lua_pushnil(state); return 0; } typel_inst *inst; CALLOC(inst,typel_inst,1); lua_pushlightuserdata(state,inst); inst->self = self; inst->type = type; sl_pushref(state, typel_mtref); // set the metatable lua_setmetatable(state, -2); lua_newtable(state); // create a new data table and store a ref inst->dataref = luaL_ref(state, LUA_REGISTRYINDEX); if(type->init) { type->init(state, inst->self, inst->dataref, param); } //else { luaL_error(state,"dataref no longer exists"); } }