Split entrypoints in half.
This commit is contained in:
parent
1721b8f1c9
commit
fbc11c00eb
|
@ -6,7 +6,7 @@ as it has an entrypoint that looks like the following, where xxxxx is the plugin
|
||||||
|
|
||||||
#include "lite_xl_plugin_api.h"
|
#include "lite_xl_plugin_api.h"
|
||||||
|
|
||||||
int lua_open_xxxxx(lua_State* L, void* XL) {
|
int lua_open_lite_xl_xxxxx(lua_State* L, void* XL) {
|
||||||
lite_xl_plugin_init(XL);
|
lite_xl_plugin_init(XL);
|
||||||
...
|
...
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -27,7 +27,7 @@ echo "as it has an entrypoint that looks like the following, where xxxxx is the
|
||||||
echo
|
echo
|
||||||
echo '#include "lite_xl_plugin_api.h"'
|
echo '#include "lite_xl_plugin_api.h"'
|
||||||
echo
|
echo
|
||||||
echo "int lua_open_xxxxx(lua_State* L, void* XL) {"
|
echo "int lua_open_lite_xl_xxxxx(lua_State* L, void* XL) {"
|
||||||
echo " lite_xl_plugin_init(XL);"
|
echo " lite_xl_plugin_init(XL);"
|
||||||
echo " ..."
|
echo " ..."
|
||||||
echo " return 1;"
|
echo " return 1;"
|
||||||
|
|
|
@ -683,26 +683,34 @@ static void* api_require(const char* symbol) {
|
||||||
|
|
||||||
static int f_load_native_plugin(lua_State* L) {
|
static int f_load_native_plugin(lua_State* L) {
|
||||||
size_t sname, namelen, pathlen;
|
size_t sname, namelen, pathlen;
|
||||||
char olib[512];
|
int results;
|
||||||
|
char olib[512]; olib[sizeof(olib)-1] = 0;
|
||||||
const char* name = luaL_checklstring(L, -2, &namelen);
|
const char* name = luaL_checklstring(L, -2, &namelen);
|
||||||
const char* path = luaL_checklstring(L, -1, &pathlen);
|
const char* path = luaL_checklstring(L, -1, &pathlen);
|
||||||
void* library = SDL_LoadObject(path);
|
void* library = SDL_LoadObject(path);
|
||||||
if (name == 0 || !library)
|
if (name == 0 || !library)
|
||||||
return luaL_error(L, "Unable to load %s: %s", name, SDL_GetError());
|
return luaL_error(L, "Unable to load %s: %s", name, SDL_GetError());
|
||||||
for (sname = namelen - 1; sname > 0 && name[sname] != '.'; --sname);
|
|
||||||
snprintf(olib, sizeof(olib), "lua_open_%s", &name[sname+1]); olib[511] = 0;
|
|
||||||
int (*entrypoint)(lua_State* L, void*) = SDL_LoadFunction(library, olib);
|
|
||||||
if (!entrypoint) {
|
|
||||||
return luaL_error(L, "Unable to load %s: Can't find entrypoint. Requires a "
|
|
||||||
"function defined as int %s(lua_State* L, void* XL)",
|
|
||||||
name, olib);
|
|
||||||
}
|
|
||||||
lua_pushlightuserdata(L, library);
|
lua_pushlightuserdata(L, library);
|
||||||
lua_setfield(L, LUA_REGISTRYINDEX, name);
|
lua_setfield(L, LUA_REGISTRYINDEX, name);
|
||||||
if (entrypoint(L, api_require) == 0)
|
for (sname = namelen - 1; sname > 0 && name[sname] != '.'; --sname);
|
||||||
|
snprintf(olib, sizeof(olib), "lua_open_lite_xl_%s", &name[sname+1]);
|
||||||
|
int (*ext_entrypoint)(lua_State* L, void*) = SDL_LoadFunction(library, olib);
|
||||||
|
if (!ext_entrypoint) {
|
||||||
|
snprintf(olib, sizeof(olib), "lua_open_%s", &name[sname+1]);
|
||||||
|
int (*entrypoint)(lua_State* L) = SDL_LoadFunction(library, olib);
|
||||||
|
if (!entrypoint) {
|
||||||
|
return luaL_error(L, "Unable to load %s: Can't find entrypoint. Requires a "
|
||||||
|
"function defined as int lua_open_lite_xl_%s(lua_State* L, void* XL)",
|
||||||
|
name, &name[sname+1]);
|
||||||
|
}
|
||||||
|
results = entrypoint(L);
|
||||||
|
} else {
|
||||||
|
results = ext_entrypoint(L, api_require);
|
||||||
|
}
|
||||||
|
if (!results)
|
||||||
return luaL_error(L, "Unable to load %s: Your entrypoint must return at "
|
return luaL_error(L, "Unable to load %s: Your entrypoint must return at "
|
||||||
" least one value.", name);
|
" least one value.", name);
|
||||||
return 1;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue