Skip to content

Commit d4d0ffb

Browse files
committed
Pass pointers as arguments instead of FFI symbols
This way we don't need to worry about exporting said symbols. This change also deprecates the need of current library path.
1 parent 9880052 commit d4d0ffb

6 files changed

Lines changed: 15 additions & 48 deletions

File tree

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ build/%/liblua_pluginscript.so: $(BUILT_OBJS) build/%/luajit/src/libluajit.a
183183

184184
build/%/lua_pluginscript.dll: TARGET_SYS = Windows
185185
build/%/lua_pluginscript.dll: EXE = .exe
186-
build/%/lua_pluginscript.dll: CFLAGS += -DLUAJIT_DYNAMICALLY_LINKED
187186
build/%/lua_pluginscript.dll: $(BUILT_OBJS) build/%/lua51.dll
188187
$(_CC) -o $@ $^ -shared $(CFLAGS) $(LDFLAGS)
189188
$(call STRIP_CMD,$@)

src/cache_lua_libs.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ local setthreadfunc, touserdata
5454
-- FFI
5555
local ffi_cast, ffi_cdef, ffi_copy, ffi_gc, ffi_istype, ffi_metatype, ffi_new, ffi_sizeof, ffi_string, ffi_typeof
5656
= ffi.cast, ffi.cdef, ffi.copy, ffi.gc, ffi.istype, ffi.metatype, ffi.new, ffi.sizeof, ffi.string, ffi.typeof
57+
local clib = ffi.C
5758

5859
-- Weak tables
5960
local weak_kv = { __mode = 'kv' }

src/godot_ffi.lua

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,20 +1411,12 @@ typedef struct godot_pluginscript_language_desc {
14111411
void (*profiling_frame)(godot_pluginscript_language_data *p_data);
14121412
godot_pluginscript_script_desc script_desc;
14131413
} godot_pluginscript_language_desc;
1414-
1415-
// Global API pointers
1416-
const godot_gdnative_core_api_struct *hgdn_core_api;
1417-
const godot_gdnative_core_1_1_api_struct *hgdn_core_1_1_api;
1418-
const godot_gdnative_core_1_2_api_struct *hgdn_core_1_2_api;
1419-
const godot_gdnative_core_1_3_api_struct *hgdn_core_1_3_api;
1420-
godot_object *hgdn_library;
14211414
]]
14221415

1423-
local pluginscript_callbacks, in_editor, active_library_path = ...
1424-
local clib = active_library_path and ffi.load(active_library_path, true) or ffi.C
1425-
1426-
local api = clib.hgdn_core_api
1427-
local api_1_1 = clib.hgdn_core_1_1_api
1428-
local api_1_2 = clib.hgdn_core_1_2_api
1429-
local api_1_3 = clib.hgdn_core_1_3_api
1416+
local pluginscript_callbacks, in_editor, api, api_1_1, api_1_2, api_1_3, gdnativelibrary = ...
14301417

1418+
api = ffi.cast('godot_gdnative_core_api_struct *', api)
1419+
api_1_1 = ffi.cast('godot_gdnative_core_1_1_api_struct *', api_1_1)
1420+
api_1_2 = ffi.cast('godot_gdnative_core_1_2_api_struct *', api_1_2)
1421+
api_1_3 = ffi.cast('godot_gdnative_core_1_3_api_struct *', api_1_3)
1422+
gdnativelibrary = ffi.cast('godot_object *', gdnativelibrary)

src/language_gdnative.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ extern const size_t LUA_INIT_SCRIPT_SIZE;
4848
HGDN_PRINT_ERROR(prefix ": %s", lua_tostring(L, -1)); \
4949
lua_pop(L, 1)
5050

51-
#ifdef LUAJIT_DYNAMICALLY_LINKED
52-
// Active shared library path, for loading symbols in FFI
53-
static hgdn_string lps_active_library_path;
54-
#endif
5551
static bool lps_in_editor;
5652
static int lps_pcall_error_handler_index;
5753
static lua_State *lps_L;
@@ -136,12 +132,12 @@ static godot_pluginscript_language_data *lps_language_init() {
136132
lua_setfield(L, LUA_REGISTRYINDEX, PLUGINSCRIPT_CALLBACKS_KEY);
137133

138134
lua_pushboolean(L, lps_in_editor);
139-
#ifdef LUAJIT_DYNAMICALLY_LINKED
140-
lua_pushlstring(L, lps_active_library_path.ptr, lps_active_library_path.length);
141-
#else
142-
lua_pushnil(L);
143-
#endif
144-
if (lua_pcall(L, 3, 0, lps_pcall_error_handler_index) != LUA_OK) {
135+
lua_pushlightuserdata(L, (void *) hgdn_core_api);
136+
lua_pushlightuserdata(L, (void *) hgdn_core_1_1_api);
137+
lua_pushlightuserdata(L, (void *) hgdn_core_1_2_api);
138+
lua_pushlightuserdata(L, (void *) hgdn_core_1_3_api);
139+
lua_pushlightuserdata(L, (void *) hgdn_library);
140+
if (lua_pcall(L, 7, 0, lps_pcall_error_handler_index) != LUA_OK) {
145141
LPS_PCALL_CONSUME_ERROR(L, "Error in Lua language initialization script");
146142
}
147143
return L;
@@ -384,31 +380,10 @@ GDN_EXPORT void PREFIX_SYMBOL(gdnative_init)(godot_gdnative_init_options *option
384380
lps_register_in_editor_callbacks(&lps_language_desc);
385381
}
386382

387-
#ifdef LUAJIT_DYNAMICALLY_LINKED
388-
godot_object *OS = hgdn_core_api->godot_global_get_singleton("OS");
389-
if (hgdn_variant_get_bool_own(hgdn_object_call(OS, "has_feature", "standalone"))) {
390-
godot_variant exepath_var = hgdn_object_callv(OS, "get_executable_path", NULL);
391-
godot_string exepath = hgdn_core_api->godot_variant_as_string(&exepath_var);
392-
godot_string exedir = hgdn_core_api->godot_string_get_base_dir(&exepath);
393-
godot_string library_filepath = hgdn_core_api->godot_string_get_file(options->active_library_path);
394-
lps_active_library_path = hgdn_string_get_own(hgdn_core_api->godot_string_plus_file(&exedir, &library_filepath));
395-
hgdn_core_api->godot_string_destroy(&library_filepath);
396-
hgdn_core_api->godot_string_destroy(&exedir);
397-
hgdn_core_api->godot_string_destroy(&exepath);
398-
hgdn_core_api->godot_variant_destroy(&exepath_var);
399-
}
400-
else {
401-
lps_active_library_path = hgdn_string_get(options->active_library_path);
402-
}
403-
#endif
404-
405383
hgdn_pluginscript_api->godot_pluginscript_register_language(&lps_language_desc);
406384
}
407385

408386
GDN_EXPORT void PREFIX_SYMBOL(gdnative_terminate)(godot_gdnative_terminate_options *options) {
409-
#ifdef LUAJIT_DYNAMICALLY_LINKED
410-
hgdn_string_destroy(&lps_active_library_path);
411-
#endif
412387
hgdn_gdnative_terminate(options);
413388
}
414389

src/late_globals.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ GD = {
3535
--- (`const godot_gdnative_core_1_2_api_struct *`) GDNative core API 1.2
3636
api_1_2 = api_1_2,
3737
--- (`Object`) [GDNativeLibrary](https://docs.godotengine.org/en/stable/classes/class_gdnativelibrary.html) instance
38-
gdnativelibrary = clib.hgdn_library,
38+
gdnativelibrary = gdnativelibrary,
3939
--- `Enumerations.Error`
4040
Error = Error,
4141
--- `Enumerations.VariantType`

src/lua_object_wrapper.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
-- @module lua_object_wrapper
2727
-- @local
2828

29-
local library_resource_dir = clib.hgdn_library.resource_path:get_base_dir()
29+
local library_resource_dir = gdnativelibrary.resource_path:get_base_dir()
3030

3131
--- Global cache of Lua object wrappers
3232
local lps_lua_object_references = setmetatable({}, weak_kv)

0 commit comments

Comments
 (0)