From e13529444fcbbef190a98fd909e9a87929289f4b Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Mon, 20 Sep 2021 23:42:39 -0400 Subject: [PATCH] Less C code, and more namespacing is better. --- data/core/start.lua | 1 + src/api/system.c | 3 ++- src/main.c | 3 --- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/data/core/start.lua b/data/core/start.lua index 2b340d5d..a84b4faa 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -22,6 +22,7 @@ package.path = USERDIR .. '/?/init.lua;' .. package.path local dynamic_suffix = MACOS and 'lib' or (WINDOWS and 'dll' or 'so') package.cpath = DATADIR .. '/?.' .. dynamic_suffix .. ";" .. USERDIR .. '/?.' .. dynamic_suffix +package.native_plugins = {} package.searchers[3] = function(modname) local path = package.searchpath(modname, package.cpath) if not path then return nil end diff --git a/src/api/system.c b/src/api/system.c index e35e4558..68d25ae9 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -690,7 +690,8 @@ static int f_load_native_plugin(lua_State* L) { void* library = SDL_LoadObject(path); if (name == 0 || !library) return luaL_error(L, "Unable to load %s: %s", name, SDL_GetError()); - lua_getfield(L, LUA_REGISTRYINDEX, "native_plugins"); + lua_getglobal(L, "package"); + lua_getfield(L, -1, "native_plugins"); lua_pushlightuserdata(L, library); lua_setfield(L, -2, name); lua_pop(L, 1); diff --git a/src/main.c b/src/main.c index 4a95a76b..4b15ef34 100644 --- a/src/main.c +++ b/src/main.c @@ -152,9 +152,6 @@ init_lua: lua_setglobal(L, "LINUX"); #endif - lua_newtable(L); - lua_setfield(L, LUA_REGISTRYINDEX, "native_plugins"); - const char *init_lite_code = \ "local core\n" "xpcall(function()\n"