partial implementation of lua_version...

It's a bit more reliable than before, but... not really that much better!
This commit is contained in:
ThePhD 2015-05-24 23:31:18 -04:00
parent 8b13e6df6f
commit b8d81cb927

View File

@ -271,9 +271,32 @@ inline void luaL_traceback(lua_State *L, lua_State *L1,
} }
#endif #endif
inline const lua_Number *lua_version(lua_State *L) {
static const lua_Number version = LUA_VERSION_NUM;
if (L == NULL) return &version;
// TODO: wonky hacks to get at the inside of the incomplete type lua_State?
//else return L->l_G->version;
else return &version;
}
inline void luaL_checkversion(lua_State *L) { inline static void luaL_checkversion_(lua_State *L, lua_Number ver) {
(void)L; const lua_Number* v = lua_version(L);
if (v != lua_version(NULL))
luaL_error(L, "multiple Lua VMs detected");
else if (*v != ver)
luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
ver, *v);
/* check conversions number -> integer types */
lua_pushnumber(L, -(lua_Number)0x1234);
if (lua_tointeger(L, -1) != -0x1234 ||
lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
luaL_error(L, "bad conversion number->int;"
" must recompile Lua with proper settings");
lua_pop(L, 1);
}
inline void luaL_checkversion(lua_State* L) {
luaL_checkversion_(L, LUA_VERSION_NUM);
} }
#ifndef SOL_LUAJIT #ifndef SOL_LUAJIT