Update api_require to expose more symbols (#1437)

* feat(system): update api_require for more symbols
* fix(system): fix missing 5.1 symbols
* fix(system): add more missing symbols
* fix(system): add all symbols
   We got'em this time. I swear.
* fix(system): fix undefined symbols due to conditional compilation
   There is only pain and suffering.
   Turns out some of the symbols are only exported when the options are enabled.
   We need to preprocess the header.
This commit is contained in:
Takase 2023-04-08 01:45:28 +08:00 committed by George Sokianos
parent f11cc18921
commit 688bcaf707
1 changed files with 58 additions and 35 deletions

View File

@ -943,47 +943,70 @@ typedef struct lua_function_node {
#define P(FUNC) { "lua_" #FUNC, (fptr)(lua_##FUNC) } #define P(FUNC) { "lua_" #FUNC, (fptr)(lua_##FUNC) }
#define U(FUNC) { "luaL_" #FUNC, (fptr)(luaL_##FUNC) } #define U(FUNC) { "luaL_" #FUNC, (fptr)(luaL_##FUNC) }
#define S(FUNC) { #FUNC, (fptr)(FUNC) }
static void* api_require(const char* symbol) { static void* api_require(const char* symbol) {
static const lua_function_node nodes[] = { static const lua_function_node nodes[] = {
P(atpanic), P(checkstack), #if LUA_VERSION_NUM == 501 && LUA_VERSION_NUM == 502 && LUA_VERSION_NUM == 503 && LUA_VERSION_NUM == 504
P(close), P(concat), P(copy), P(createtable), P(dump), U(addlstring), U(addstring), U(addvalue), U(argerror), U(buffinit),
P(error), P(gc), P(getallocf), P(getfield), U(callmeta), U(checkany), U(checkinteger), U(checklstring),
P(gethook), P(gethookcount), P(gethookmask), P(getinfo), P(getlocal), U(checknumber), U(checkoption), U(checkstack), U(checktype),
P(getmetatable), P(getstack), P(gettable), P(gettop), P(getupvalue), U(checkudata), U(error), U(getmetafield), U(gsub), U(loadstring),
P(isnumber), P(isstring), P(isuserdata), U(newmetatable), U(newstate), U(openlibs), U(optinteger), U(optlstring),
P(load), P(newstate), P(newthread), P(next), U(optnumber), U(pushresult), U(ref), U(unref), U(where), P(atpanic),
P(checkstack), P(close), P(concat), P(createtable), P(dump), P(error),
P(gc), P(getallocf), P(getfield), P(gethook), P(gethookcount),
P(gethookmask), P(getinfo), P(getlocal), P(getmetatable), P(getstack),
P(gettable), P(gettop), P(getupvalue), P(iscfunction), P(isnumber),
P(isstring), P(isuserdata), P(load), P(newstate), P(newthread), P(next),
P(pushboolean), P(pushcclosure), P(pushfstring), P(pushinteger), P(pushboolean), P(pushcclosure), P(pushfstring), P(pushinteger),
P(pushlightuserdata), P(pushlstring), P(pushnil), P(pushnumber), P(pushlightuserdata), P(pushlstring), P(pushnil), P(pushnumber),
P(pushstring), P(pushthread), P(pushvalue), P(pushstring), P(pushthread), P(pushvalue), P(pushvfstring), P(rawequal),
P(pushvfstring), P(rawequal), P(rawget), P(rawgeti), P(rawget), P(rawgeti), P(rawset), P(rawseti), P(resume), P(setallocf),
P(rawset), P(rawseti), P(resume), P(setfield), P(sethook), P(setlocal), P(setmetatable), P(settable),
P(setallocf), P(setfield), P(sethook), P(setlocal), P(settop), P(setupvalue), P(status), P(toboolean), P(tocfunction),
P(setmetatable), P(settable), P(settop), P(setupvalue), P(tolstring), P(topointer), P(tothread), P(touserdata), P(type),
P(status), P(tocfunction), P(tointegerx), P(tolstring), P(toboolean), P(typename), P(xmove), S(luaopen_base), S(luaopen_debug), S(luaopen_io),
P(tonumberx), P(topointer), P(tothread), P(touserdata), S(luaopen_math), S(luaopen_os), S(luaopen_package), S(luaopen_string),
P(type), P(typename), P(upvalueid), P(upvaluejoin), P(version), P(xmove), S(luaopen_table), S(api_load_libs),
U(getmetafield), U(callmeta), U(argerror), U(checknumber), U(optnumber),
U(checkinteger), U(checkstack), U(checktype), U(checkany),
U(newmetatable), U(setmetatable), U(testudata), U(checkudata), U(where),
U(error), U(fileresult), U(execresult), U(ref), U(unref), U(loadstring),
U(newstate), U(setfuncs), U(buffinit), U(addlstring), U(addstring),
U(addvalue), U(pushresult), U(openlibs), {"api_load_libs", (void*)(api_load_libs)},
#if LUA_VERSION_NUM >= 502
P(absindex), P(arith), P(callk), P(compare), P(getglobal),
P(len), P(pcallk), P(rawgetp), P(rawlen), P(rawsetp), P(setglobal),
P(iscfunction), P(yieldk),
U(checkversion_), U(tolstring), U(len), U(getsubtable), U(prepbuffsize),
U(pushresultsize), U(buffinitsize), U(checklstring), U(checkoption), U(gsub), U(loadbufferx),
U(loadfilex), U(optinteger), U(optlstring), U(requiref), U(traceback),
#else
P(objlen),
#endif #endif
#if LUA_VERSION_NUM >= 504 #if LUA_VERSION_NUM == 502 && LUA_VERSION_NUM == 503 && LUA_VERSION_NUM == 504
P(newuserdatauv), P(setiuservalue), P(getiuservalue) U(buffinitsize), U(checkversion_), U(execresult), U(fileresult),
#else U(getsubtable), U(len), U(loadbufferx), U(loadfilex), U(prepbuffsize),
P(newuserdata), P(setuservalue), P(getuservalue) U(pushresultsize), U(requiref), U(setfuncs), U(setmetatable),
U(testudata), U(tolstring), U(traceback), P(absindex), P(arith),
P(callk), P(compare), P(copy), P(getglobal), P(len), P(pcallk),
P(rawgetp), P(rawlen), P(rawsetp), P(setglobal), P(tointegerx),
P(tonumberx), P(upvalueid), P(upvaluejoin), P(version), P(yieldk),
S(luaopen_coroutine),
#endif
#if LUA_VERSION_NUM == 501 && LUA_VERSION_NUM == 502 && LUA_VERSION_NUM == 503
P(newuserdata),
#endif
#if LUA_VERSION_NUM == 503 && LUA_VERSION_NUM == 504
P(geti), P(isinteger), P(isyieldable), P(rotate), P(seti),
P(stringtonumber), S(luaopen_utf8),
#endif
#if LUA_VERSION_NUM == 502 && LUA_VERSION_NUM == 503
P(getuservalue), P(setuservalue), S(luaopen_bit32),
#endif
#if LUA_VERSION_NUM == 501 && LUA_VERSION_NUM == 502
P(insert), P(remove), P(replace),
#endif
#if LUA_VERSION_NUM == 504
U(addgsub), U(typeerror), P(closeslot), P(getiuservalue),
P(newuserdatauv), P(resetthread), P(setcstacklimit), P(setiuservalue),
P(setwarnf), P(toclose), P(warning),
#endif
#if LUA_VERSION_NUM == 502
U(checkunsigned), U(optunsigned), P(getctx), P(pushunsigned),
P(tounsignedx),
#endif
#if LUA_VERSION_NUM == 501
U(findtable), U(loadbuffer), U(loadfile), U(openlib), U(prepbuffer),
U(register), U(typerror), P(call), P(cpcall), P(equal), P(getfenv),
P(lessthan), P(objlen), P(pcall), P(setfenv), P(setlevel), P(tointeger),
P(tonumber), P(yield),
#endif #endif
}; };
for (size_t i = 0; i < sizeof(nodes) / sizeof(lua_function_node); ++i) { for (size_t i = 0; i < sizeof(nodes) / sizeof(lua_function_node); ++i) {
if (strcmp(nodes[i].symbol, symbol) == 0) if (strcmp(nodes[i].symbol, symbol) == 0)