[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Purpose for replace explicit linkage to lua dlls (lua52.dll, lua53.dll etc)
- From: Alexander Kluev <akluev@...>
- Date: Tue, 21 Jul 2015 01:24:35 +0300
Hello, dear lua developers!
currently any C library have to be explicit linked to corresponding lua dll such as lua52.dll, lua53.dll etc
so once compiled C lib is depended from some version of lua core lib and may not compatible with current lua environment
for example user ivnoke 5.3 based lua interpreter and via "require" load 5.2 based C library
solution for solve this problem is passing to luaopen_* function struct with pointer to lua api functions instead explicit linkage to lua*.dll
// new struct in lua.h
struct LuaAPI
{
int version;
void (*pushcfunction)(lua_State *L, lua_CFunction f);
int (*lua_gettop (lua_State *L);
// and other
};
// in user C library
#include <lua.h>
const LuaAPI *saved_api_ptr;
int luaopen_myLib(lua_State *L, const LuaAPI *api) {
saved_api_ptr = api;
...
api->pushcfunction(L, myfunc);
...
}
int myfunc(lua_State *L) {
saved_api_ptr->pushnumber(L, 123);
...
}