lua-users home
lua-l archive

Re: How to make ROMable Lua data

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Sorry, but I don't understand how setting a metatable for the lightuserdata type is equivalent to my patch.
Sorry, I wasn't very clear on that. I meant only the part of your patch that
implements light tables and functions.
set "__call" to something like this (sorry, this is not an actual code, i'm
just making it up here from memory):
int lightCall(lua_State *L) {
 CFunction *p = lua_topointer(L, 1);
 if (!ptr_in_code_segment(p)) return luaL_error(L, "not a function");
 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
 return lua_gettop(L);
}
Now any CFunction pointer will be callable if pushed as lightuserdata.
Make something similar that does __len and __index for luaL_Reg pointers.
This way lightuserdata can act both as function and as table.
Most of what your patch does, and what cannot be accomplished by a
metatable, is initializing global environment so libraries do not
create lots of tables in RAM.
--j<

AltStyle によって変換されたページ (->オリジナル) /