Skip to content

Commit ee771e4

Browse files
authored
Merge pull request #34 from gilzoide/bugfix/exported-hgdn-symbols
Remove need for exported hgdn symbols
2 parents 9880052 + 526b97f commit ee771e4

11 files changed

+24
-56
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## [Unreleased](https://github.com/gilzoide/godot-lua-pluginscript/compare/0.5.0...HEAD)
33
### Fixed
44

5+
- Plugin initialization on Windows ([#31](https://github.com/gilzoide/godot-lua-pluginscript/issues/31))
56
- [build] Fixed `make dist` dependencies to include LuaJIT's `jit/*.lua` files
67
- [build] Fixed `make unzip-to-build` to only copy contents from `build` folder
78

Makefile

-1
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

+1
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_basis.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ methods.FLIP_Z = ffi_new('godot_basis', { elements = { 1, 0, 0, 0, 1, 0, 0, 0, -
170170

171171
--- Metamethods
172172
-- @section metamethods
173-
Basis = ffi.metatype('godot_basis', {
173+
Basis = ffi_metatype('godot_basis', {
174174
--- Basis constructor, called by the idiom `Basis(...)`.
175175
--
176176
-- * `Basis()`: `IDENTITY` basis matrix

src/godot_class.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ local ClassWrapper_cache = setmetatable({}, {
171171
--- MethodBind metatype, wrapper for `godot_method_bind`.
172172
-- These are returned by `ClassWrapper:__index` and GDNative's `godot_method_bind_get_method`.
173173
-- @type MethodBind
174-
local MethodBind = ffi.metatype('godot_method_bind', {
174+
local MethodBind = ffi_metatype('godot_method_bind', {
175175
--- Calls the method in `object`.
176176
-- @function __call
177177
-- @tparam Object object

src/godot_ffi.lua

+6-14
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/godot_quat.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ methods.IDENTITY = ffi_new('godot_quat', { elements = { 0, 0, 0, 1 } })
121121

122122
--- Metamethods
123123
-- @section metamethods
124-
Quat = ffi.metatype('godot_quat', {
124+
Quat = ffi_metatype('godot_quat', {
125125
--- Quat constructor, called by the idiom `Quat(...)`.
126126
--
127127
-- * `Quat()`: `IDENTITY` quaternion (`Quat() == Quat(0, 0, 0, 1)`)

src/godot_string_name.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local methods = {
4646
-- @return[type=const void *]
4747
get_data_unique_pointer = api.godot_string_name_get_data_unique_pointer,
4848
}
49-
StringName = ffi.metatype('godot_string_name', {
49+
StringName = ffi_metatype('godot_string_name', {
5050
--- StringName constructor, called by the idiom `StringName(name)`.
5151
-- @function __new
5252
-- @param[opt=""] name Name, stringified with `GD.str`

src/language_gdnative.c

+10-35
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;
@@ -276,7 +272,7 @@ static void lps_instance_notification(godot_pluginscript_instance_data *data, in
276272
}
277273

278274
// In-editor callbacks
279-
godot_string lps_get_template_source_code(godot_pluginscript_language_data *data, const godot_string *class_name, const godot_string *base_class_name) {
275+
static godot_string lps_get_template_source_code(godot_pluginscript_language_data *data, const godot_string *class_name, const godot_string *base_class_name) {
280276
godot_string ret;
281277
hgdn_core_api->godot_string_new(&ret);
282278
LPS_PUSH_CALLBACK(lps_L, "get_template_source_code");
@@ -289,7 +285,7 @@ godot_string lps_get_template_source_code(godot_pluginscript_language_data *data
289285
return ret;
290286
}
291287

292-
godot_bool lps_validate(godot_pluginscript_language_data *data, const godot_string *script, int *line_error, int *col_error, godot_string *test_error, const godot_string *path, godot_pool_string_array *functions) {
288+
static godot_bool lps_validate(godot_pluginscript_language_data *data, const godot_string *script, int *line_error, int *col_error, godot_string *test_error, const godot_string *path, godot_pool_string_array *functions) {
293289
LPS_PUSH_CALLBACK(lps_L, "validate");
294290
lua_pushlightuserdata(lps_L, (void *) script);
295291
lua_pushlightuserdata(lps_L, (void *) line_error);
@@ -306,7 +302,7 @@ godot_bool lps_validate(godot_pluginscript_language_data *data, const godot_stri
306302
return success;
307303
}
308304

309-
godot_string lps_make_function(godot_pluginscript_language_data *data, const godot_string *class_name, const godot_string *name, const godot_pool_string_array *args) {
305+
static godot_string lps_make_function(godot_pluginscript_language_data *data, const godot_string *class_name, const godot_string *name, const godot_pool_string_array *args) {
310306
godot_string ret;
311307
hgdn_core_api->godot_string_new(&ret);
312308
LPS_PUSH_CALLBACK(lps_L, "make_function");
@@ -320,7 +316,7 @@ godot_string lps_make_function(godot_pluginscript_language_data *data, const god
320316
return ret;
321317
}
322318

323-
void lps_register_in_editor_callbacks(godot_pluginscript_language_desc *desc) {
319+
static void lps_register_in_editor_callbacks(godot_pluginscript_language_desc *desc) {
324320
desc->get_template_source_code = &lps_get_template_source_code;
325321
desc->validate = &lps_validate;
326322
desc->make_function = &lps_make_function;
@@ -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

+1-1
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

+1-1
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)