-
Notifications
You must be signed in to change notification settings - Fork 38
(wip) Add the ability to push a global module to lua, close #197 #198
Conversation
So my only concern with the current implementation is functionally this would behave the same as pushing an object or dictionary as a global with all the module methods. Ideally we would implment it as an actual library that can be obtained via require if we are going to separate it. My only concern then us in unsure of a use case where you would not want the module already made available for the user buy they have access to require. |
I do agree that making it available from require would be the best. I am working on it but for now I am unsuccessful. My main issue is that we have to use So libraries could look as follow: I did a promising prototyping tonight but gonna try further tomorrow. But of course I am wondering if there would be any way to perform it in a less tricky way? As this would add really a lot of complexity. My initial version is much simpler though. Anyway thank you for your answer. |
It is pretty dirty but here is what I came up with. EDIT: I do not prevent yet the dev to register multiple libraries with the same name. So only the first one will be loaded. |
It's provided via the package library in lua |
Thank you,
Even by doing
So it remains mysterious to me! |
I am curious as to what version of the addon you are using. I just tested on my end and this code runs without error. extends Node
var lua: LuaAPI = LuaAPI.new()
func _ready():
lua.bind_libraries(["base", "package"])
var err: LuaError = lua.do_string("""
require "base"
print("test")
""")
if err is LuaError:
print("ERROR %d: %s" % [err.type, err.message])
return |
I ran your code with the latest gdextension available on the GitHub page, and still have the issue. Same on a brand new git clone, then submodule init, update from the repo.
This code give me that:
So it is like the problem is about all modules....
from:
|
Hello sir! As I have been trying to use the #194 patch without success. Compilation ok but unable to load the project, I have done my own workaround Fix loadLuaLibrary for MAc OS which seems to compile fine and I have been able to test. |
b085238
to
2e1e283
Compare
Not sure if I'm misunderstanding something but this seems to be the same use case as extends Node
var lua: LuaAPI = LuaAPI.new()
func message():
print("hello world")
func _ready():
lua.push_variant("MyNode", self)
var err: LuaError = lua.do_string("""
MyNode.message()
""") As described in the OP, it seems this does what you want? You could obviously obscure some functions by packing them into an array like: lua.push_variant("MyModule", [function_1, function_2]) And this would work the same way. Why are you specifically wanting to use For the stated use case, |
Hello Sir, sorry for the delay.
So I want to be able to have nested named tables of functions. EDIT: Currently it works as follow:
|
This looks completely unnecessary to my point of view, as all you need to do is api.push_variant("module_name",{
"function_name_1":function_1,
"function_name_2":function_2
}) and it is wayyy straight forward. |
As you prefer... I agree to the fact that it is a lot of troubles for a luxury. |
GDScript recently started to allow lua-like dictionary creation. api.push_variant("module_name",{
function_name_1=function_1,
function_name_2=function_2
}) is now valid too. |
Pull request of a possible implementation to fix #197.
It allows to push a global as follow:
push_module('my_module_name', [[function_name_1, function_1], [function_name_2, function_2]])
then we can use it in lua as follow:
my_module_name. function_name_1()
my_module_name. function_name_2()
It is not registered as a library as since the latest lua release it is a bit tricky.
This PR is WIP and intended for discussion. Yet no unit test and my understanding of Godot_luaAPI is still limited so things might be not ready to merge!
Commits will be squashed of course before any merge.
Thank you for Godot_luaAPI which is an awesome tool!