Open Oolks opened 1 year ago
Hi @OoIks.
This happens because Godot Strings are not translated to Lua strings automatically (cdata
is the name LuaJIT gives to any FFI-defined type, which includes anything related to Godot).
I let it be like that because it avoided marshalling (copying/converting data to/from Lua/Godot) and Godot's String class has more functionality than Lua's built-in string type. In hindsight, this was probably a bad design choice, people would expect a string in Lua to be of Lua's string type, regardless if it comes from Godot data.
Now, to fix your problem right now, just call tostring
passing your code
variable and it will be converted to a Lua string, which loadstring
accepts:
function Executor:execute(code)
if code == nil or code == "" then
return false
end
-- Code to execute
local temp_code = loadstring(tostring(code))
-- ^ here!
-- ... rest of your code ...
end
E 0:00:13.272 loadstring: bad argument #1 to 'loadstring' (function expected, got cdata) stack traceback: [string "res://Scripts/Core/Scripting/Executor.lua"]:10: in function 'execute'