Skip to content

Commit

Permalink
Merge pull request #34 from gilzoide/bugfix/exported-hgdn-symbols
Browse files Browse the repository at this point in the history
Remove need for exported hgdn symbols
  • Loading branch information
gilzoide authored Jan 4, 2023
2 parents 9880052 + 526b97f commit ee771e4
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## [Unreleased](https://github.com/gilzoide/godot-lua-pluginscript/compare/0.5.0...HEAD)
### Fixed

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

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ build/%/liblua_pluginscript.so: $(BUILT_OBJS) build/%/luajit/src/libluajit.a

build/%/lua_pluginscript.dll: TARGET_SYS = Windows
build/%/lua_pluginscript.dll: EXE = .exe
build/%/lua_pluginscript.dll: CFLAGS += -DLUAJIT_DYNAMICALLY_LINKED
build/%/lua_pluginscript.dll: $(BUILT_OBJS) build/%/lua51.dll
$(_CC) -o $@ $^ -shared $(CFLAGS) $(LDFLAGS)
$(call STRIP_CMD,$@)
Expand Down
1 change: 1 addition & 0 deletions src/cache_lua_libs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ local setthreadfunc, touserdata
-- FFI
local ffi_cast, ffi_cdef, ffi_copy, ffi_gc, ffi_istype, ffi_metatype, ffi_new, ffi_sizeof, ffi_string, ffi_typeof
= ffi.cast, ffi.cdef, ffi.copy, ffi.gc, ffi.istype, ffi.metatype, ffi.new, ffi.sizeof, ffi.string, ffi.typeof
local clib = ffi.C

-- Weak tables
local weak_kv = { __mode = 'kv' }
Expand Down
2 changes: 1 addition & 1 deletion src/godot_basis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ methods.FLIP_Z = ffi_new('godot_basis', { elements = { 1, 0, 0, 0, 1, 0, 0, 0, -

--- Metamethods
-- @section metamethods
Basis = ffi.metatype('godot_basis', {
Basis = ffi_metatype('godot_basis', {
--- Basis constructor, called by the idiom `Basis(...)`.
--
-- * `Basis()`: `IDENTITY` basis matrix
Expand Down
2 changes: 1 addition & 1 deletion src/godot_class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ local ClassWrapper_cache = setmetatable({}, {
--- MethodBind metatype, wrapper for `godot_method_bind`.
-- These are returned by `ClassWrapper:__index` and GDNative's `godot_method_bind_get_method`.
-- @type MethodBind
local MethodBind = ffi.metatype('godot_method_bind', {
local MethodBind = ffi_metatype('godot_method_bind', {
--- Calls the method in `object`.
-- @function __call
-- @tparam Object object
Expand Down
20 changes: 6 additions & 14 deletions src/godot_ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1411,20 +1411,12 @@ typedef struct godot_pluginscript_language_desc {
void (*profiling_frame)(godot_pluginscript_language_data *p_data);
godot_pluginscript_script_desc script_desc;
} godot_pluginscript_language_desc;

// Global API pointers
const godot_gdnative_core_api_struct *hgdn_core_api;
const godot_gdnative_core_1_1_api_struct *hgdn_core_1_1_api;
const godot_gdnative_core_1_2_api_struct *hgdn_core_1_2_api;
const godot_gdnative_core_1_3_api_struct *hgdn_core_1_3_api;
godot_object *hgdn_library;
]]

local pluginscript_callbacks, in_editor, active_library_path = ...
local clib = active_library_path and ffi.load(active_library_path, true) or ffi.C

local api = clib.hgdn_core_api
local api_1_1 = clib.hgdn_core_1_1_api
local api_1_2 = clib.hgdn_core_1_2_api
local api_1_3 = clib.hgdn_core_1_3_api
local pluginscript_callbacks, in_editor, api, api_1_1, api_1_2, api_1_3, gdnativelibrary = ...

api = ffi.cast('godot_gdnative_core_api_struct *', api)
api_1_1 = ffi.cast('godot_gdnative_core_1_1_api_struct *', api_1_1)
api_1_2 = ffi.cast('godot_gdnative_core_1_2_api_struct *', api_1_2)
api_1_3 = ffi.cast('godot_gdnative_core_1_3_api_struct *', api_1_3)
gdnativelibrary = ffi.cast('godot_object *', gdnativelibrary)
2 changes: 1 addition & 1 deletion src/godot_quat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ methods.IDENTITY = ffi_new('godot_quat', { elements = { 0, 0, 0, 1 } })

--- Metamethods
-- @section metamethods
Quat = ffi.metatype('godot_quat', {
Quat = ffi_metatype('godot_quat', {
--- Quat constructor, called by the idiom `Quat(...)`.
--
-- * `Quat()`: `IDENTITY` quaternion (`Quat() == Quat(0, 0, 0, 1)`)
Expand Down
2 changes: 1 addition & 1 deletion src/godot_string_name.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local methods = {
-- @return[type=const void *]
get_data_unique_pointer = api.godot_string_name_get_data_unique_pointer,
}
StringName = ffi.metatype('godot_string_name', {
StringName = ffi_metatype('godot_string_name', {
--- StringName constructor, called by the idiom `StringName(name)`.
-- @function __new
-- @param[opt=""] name Name, stringified with `GD.str`
Expand Down
45 changes: 10 additions & 35 deletions src/language_gdnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ extern const size_t LUA_INIT_SCRIPT_SIZE;
HGDN_PRINT_ERROR(prefix ": %s", lua_tostring(L, -1)); \
lua_pop(L, 1)

#ifdef LUAJIT_DYNAMICALLY_LINKED
// Active shared library path, for loading symbols in FFI
static hgdn_string lps_active_library_path;
#endif
static bool lps_in_editor;
static int lps_pcall_error_handler_index;
static lua_State *lps_L;
Expand Down Expand Up @@ -136,12 +132,12 @@ static godot_pluginscript_language_data *lps_language_init() {
lua_setfield(L, LUA_REGISTRYINDEX, PLUGINSCRIPT_CALLBACKS_KEY);

lua_pushboolean(L, lps_in_editor);
#ifdef LUAJIT_DYNAMICALLY_LINKED
lua_pushlstring(L, lps_active_library_path.ptr, lps_active_library_path.length);
#else
lua_pushnil(L);
#endif
if (lua_pcall(L, 3, 0, lps_pcall_error_handler_index) != LUA_OK) {
lua_pushlightuserdata(L, (void *) hgdn_core_api);
lua_pushlightuserdata(L, (void *) hgdn_core_1_1_api);
lua_pushlightuserdata(L, (void *) hgdn_core_1_2_api);
lua_pushlightuserdata(L, (void *) hgdn_core_1_3_api);
lua_pushlightuserdata(L, (void *) hgdn_library);
if (lua_pcall(L, 7, 0, lps_pcall_error_handler_index) != LUA_OK) {
LPS_PCALL_CONSUME_ERROR(L, "Error in Lua language initialization script");
}
return L;
Expand Down Expand Up @@ -276,7 +272,7 @@ static void lps_instance_notification(godot_pluginscript_instance_data *data, in
}

// In-editor callbacks
godot_string lps_get_template_source_code(godot_pluginscript_language_data *data, const godot_string *class_name, const godot_string *base_class_name) {
static godot_string lps_get_template_source_code(godot_pluginscript_language_data *data, const godot_string *class_name, const godot_string *base_class_name) {
godot_string ret;
hgdn_core_api->godot_string_new(&ret);
LPS_PUSH_CALLBACK(lps_L, "get_template_source_code");
Expand All @@ -289,7 +285,7 @@ godot_string lps_get_template_source_code(godot_pluginscript_language_data *data
return ret;
}

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) {
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) {
LPS_PUSH_CALLBACK(lps_L, "validate");
lua_pushlightuserdata(lps_L, (void *) script);
lua_pushlightuserdata(lps_L, (void *) line_error);
Expand All @@ -306,7 +302,7 @@ godot_bool lps_validate(godot_pluginscript_language_data *data, const godot_stri
return success;
}

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) {
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) {
godot_string ret;
hgdn_core_api->godot_string_new(&ret);
LPS_PUSH_CALLBACK(lps_L, "make_function");
Expand All @@ -320,7 +316,7 @@ godot_string lps_make_function(godot_pluginscript_language_data *data, const god
return ret;
}

void lps_register_in_editor_callbacks(godot_pluginscript_language_desc *desc) {
static void lps_register_in_editor_callbacks(godot_pluginscript_language_desc *desc) {
desc->get_template_source_code = &lps_get_template_source_code;
desc->validate = &lps_validate;
desc->make_function = &lps_make_function;
Expand Down Expand Up @@ -384,31 +380,10 @@ GDN_EXPORT void PREFIX_SYMBOL(gdnative_init)(godot_gdnative_init_options *option
lps_register_in_editor_callbacks(&lps_language_desc);
}

#ifdef LUAJIT_DYNAMICALLY_LINKED
godot_object *OS = hgdn_core_api->godot_global_get_singleton("OS");
if (hgdn_variant_get_bool_own(hgdn_object_call(OS, "has_feature", "standalone"))) {
godot_variant exepath_var = hgdn_object_callv(OS, "get_executable_path", NULL);
godot_string exepath = hgdn_core_api->godot_variant_as_string(&exepath_var);
godot_string exedir = hgdn_core_api->godot_string_get_base_dir(&exepath);
godot_string library_filepath = hgdn_core_api->godot_string_get_file(options->active_library_path);
lps_active_library_path = hgdn_string_get_own(hgdn_core_api->godot_string_plus_file(&exedir, &library_filepath));
hgdn_core_api->godot_string_destroy(&library_filepath);
hgdn_core_api->godot_string_destroy(&exedir);
hgdn_core_api->godot_string_destroy(&exepath);
hgdn_core_api->godot_variant_destroy(&exepath_var);
}
else {
lps_active_library_path = hgdn_string_get(options->active_library_path);
}
#endif

hgdn_pluginscript_api->godot_pluginscript_register_language(&lps_language_desc);
}

GDN_EXPORT void PREFIX_SYMBOL(gdnative_terminate)(godot_gdnative_terminate_options *options) {
#ifdef LUAJIT_DYNAMICALLY_LINKED
hgdn_string_destroy(&lps_active_library_path);
#endif
hgdn_gdnative_terminate(options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/late_globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GD = {
--- (`const godot_gdnative_core_1_2_api_struct *`) GDNative core API 1.2
api_1_2 = api_1_2,
--- (`Object`) [GDNativeLibrary](https://docs.godotengine.org/en/stable/classes/class_gdnativelibrary.html) instance
gdnativelibrary = clib.hgdn_library,
gdnativelibrary = gdnativelibrary,
--- `Enumerations.Error`
Error = Error,
--- `Enumerations.VariantType`
Expand Down
2 changes: 1 addition & 1 deletion src/lua_object_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
-- @module lua_object_wrapper
-- @local

local library_resource_dir = clib.hgdn_library.resource_path:get_base_dir()
local library_resource_dir = gdnativelibrary.resource_path:get_base_dir()

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

0 comments on commit ee771e4

Please sign in to comment.