|
----- Original Message ----- From: Roberto Ierusalimschy Date: 12/10/2009 10:50 AM
I prefer the exports table being available in the lua_State. I was just trying to be explicit about my example for discussion's purposes.What I would like to see (and experimented with once) is for Lua to load the Lua module and call the luaopen_ function by passing in a structure of pointers to all the exported Lua functions. struct lua_Exports { ... void (*lua_pushvalue) (lua_State *L, int idx); }; int luaopen_mymodule(lua_State *L, lua_Exports *exports);A variation of that idea is to have lua_Exports accessible via lua_State, so that it does not need to be passed as an extra argument to luaopen. (E.g., it may be the first pointer in lua_State.)
Before Lua had modules and before LuaPlus was LuaPlus, I had implemented a form of this approach for dynamically loadable modules. There was no cost on Windows, as I recall, as a DLL accessing another DLL uses a function pointer table anyway. (In fact, delay loaded DLLs on Windows use the function pointer table to load the DLL... when the DLL is loaded, the proper pointers are filled in.) If the function pointer table is assigned to global variables, it should be just as fast.Do you know the performance impact of this approach?
lua_exports(L)->lua_pushvalue(L) would require an extra dereference. I don't know how Linux/Mac OS X resolves this stuff.It was mentioned that Tcl does this now. It might be worth some investigation as to what they do.
Josh