refactor api_require function into a machine generated file

This commit is contained in:
takase1121
2021-11-06 19:24:12 +08:00
parent a9d7ddc6e1
commit 9003a9124a
2 changed files with 167 additions and 44 deletions
+1 -44
View File
@@ -7,6 +7,7 @@
#include <sys/stat.h>
#include "api.h"
#include "rencache.h"
#include "api_require.h"
#ifdef _WIN32
#include <direct.h>
#include <windows.h>
@@ -651,50 +652,6 @@ static int f_set_window_opacity(lua_State *L) {
return 1;
}
// Symbol table for native plugin loading. Allows for a statically
// bound lua library to be used by native plugins.
typedef struct {
const char* symbol;
void* address;
} lua_function_node;
#define P(FUNC) { "lua_" #FUNC, (void*)(lua_##FUNC) }
#define U(FUNC) { "luaL_" #FUNC, (void*)(luaL_##FUNC) }
static void* api_require(const char* symbol) {
static lua_function_node nodes[] = {
P(absindex), P(arith), P(atpanic), P(callk), P(checkstack),
P(close), P(compare), P(concat), P(copy), P(createtable), P(dump),
P(error), P(gc), P(getallocf), P(getctx), P(getfield), P(getglobal),
P(gethook), P(gethookcount), P(gethookmask), P(getinfo), P(getlocal),
P(getmetatable), P(getstack), P(gettable), P(gettop), P(getupvalue),
P(getuservalue), P(insert), P(isnumber), P(isstring), P(isuserdata),
P(len), P(load), P(newstate), P(newthread), P(newuserdata), P(next),
P(pcallk), P(pushboolean), P(pushcclosure), P(pushfstring), P(pushinteger),
P(pushlightuserdata), P(pushlstring), P(pushnil), P(pushnumber),
P(pushstring), P(pushthread), P(pushunsigned), P(pushvalue),
P(pushvfstring), P(rawequal), P(rawget), P(rawgeti), P(rawgetp), P(rawlen),
P(rawset), P(rawseti), P(rawsetp), P(remove), P(replace), P(resume),
P(setallocf), P(setfield), P(setglobal), P(sethook), P(setlocal),
P(setmetatable), P(settable), P(settop), P(setupvalue), P(setuservalue),
P(status), P(tocfunction), P(tointegerx), P(tolstring), P(toboolean),
P(tonumberx), P(topointer), P(tothread), P(tounsignedx), P(touserdata),
P(type), P(typename), P(upvalueid), P(upvaluejoin), P(version), P(xmove),
P(yieldk), U(checkversion_), U(getmetafield), U(callmeta), U(tolstring),
U(argerror), U(checknumber), U(optnumber), U(checkinteger),
U(checkunsigned), 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(len), U(setfuncs), U(getsubtable), U(buffinit),
U(prepbuffsize), U(addlstring), U(addstring), U(addvalue), U(pushresult),
U(pushresultsize), U(buffinitsize)
};
for (int i = 0; i < sizeof(nodes) / sizeof(lua_function_node); ++i) {
if (strcmp(nodes[i].symbol, symbol) == 0)
return nodes[i].address;
}
return NULL;
}
static int f_load_native_plugin(lua_State *L) {
char entrypoint_name[512]; entrypoint_name[sizeof(entrypoint_name) - 1] = '\0';
int result;