gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
300 stars 21 forks source link

Do you know what the problem could be loading a multithreading library called effil? #27

Open kunrii opened 2 years ago

kunrii commented 2 years ago

I have a simple script in lua:

local Nodeee = { extends = "Node", }

effil = require("effil")

function foo(name) print(name .. " another thread!") end

thr = effil.thread(foo)("Thr")

thr:wait()

return Nodeee

Which produces the following error:

E 0:00:00.435 Error loading script metadata: Thr stack traceback: [string "res://Nodeee.lua"]:14: in main chunk in script_load @ "res://Nodeee.lua" <C++ Source> ?:-1

The effil.dll file is located inside the res:// folder. Do you mind taking a guess at what the problem could be?

Edit: wrong error

gilzoide commented 2 years ago

Hmm, I've never used effil, but we can look at the error message to get some info.

So, somehow it seems the string Thr is involved in the error, so the call to the thread must be happening. Maybe it is erroring right there, but maybe it's the wait, whichever line is 14 might be the culprit.

The effil.dll file is located inside the res:// folder.

If effil = require("effil") didn't error, your setup should be fine and the problem is probably somewhere else.

gilzoide commented 2 years ago

As a side note, be careful when using effil with Godot related stuff.

Since effil creates a brand new Lua state per thread, these new states will probably not have defined global stuff like the GD table and types like Vector2, Array, etc. This could be dealt with by making a way to require Godot definitions, the functionality used to open the plugin's lua_State can be reused to open new states as well, but it is not possible right now.

Also, effil says here that:

Userdata and Lua threads (coroutines) are not supported.

All Godot objects are LuaJIT's C data, so I don't know how effil deals with them. Maybe it will be able to pass such data to threads, maybe it will not.

kunrii commented 2 years ago

I think it's not effil, since I can run the same script with my version of luajit just fine. I tried both Godot 64 bit windows and 32 bit windows with both versions of the effil library and it fails to run with the same error, error "loading script metadata" on the call to the thread method.