lua-users home
lua-l archive

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


----- Original Message -----
From: Joshua Jensen
Date: 12/10/2009 11:12 AM
----- Original Message -----
From: Roberto Ierusalimschy
Date: 12/10/2009 10:50 AM
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.)
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.
Another thought with this... existing Lua modules can continue to compile like so:

lua.h:

#if LUA_BUILD_AS_DLL &&  LUA_LIB

    #if LUA_EXPORTS_GLOBALS_TABLE

        extern void (*lua_pushvalue)(lua_State *L, int idx);

    #else /* !LUA_EXPORTS_GLOBALS_TABLE */

        #define lua_pushvalue(L) (lua_exports((L))->lua_pushvalue((L)))

    #endif /* LUA_EXPORTS_GLOBALS_TABLE */

#else /* !(LUA_BUILD_AS_DLL &&  LUA_LIB) */

/* the standard lua.h */

#endif

If people use the new #define for their modules, they can take advantage of the "high performance" globals (one dereference less). Otherwise, the existing modules just work as they have done with a minor performance decrease.

Josh