-
|
Hi, I’ve been exploring modding in Godot using LuaStates, and I have a couple of questions.
I'm trying to create a game with moddable characters, but I’m still figuring out how to attach character and weapon scripts without risking OS access or other risky GDScript libraries. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hey @Acanixz, thanks for the question.
When you use But anyway, you are correct, you only have a "full Godot script" if you load it as a Resource in Godot (like The table itself isn't special, the var lua_script = load("res://some_lua_script.lua")
assert(lua_script is LuaScript)
var script_table = some_lua_state.do_string(lua_script.source_code)
assert(script_table is LuaTable)
# actually this could be a LuaError if you use the `export` function
# and if you don't really return anything, it would be null
The LuaState used by the LuaScriptingLanguage (which is what you called a "full Godot script") has all Lua/Godot libraries opened, just like GDScript has everything available. This is quite necessary to write Godot scripts. If you need a Godot script written in Lua to run Lua code in a sandboxed environment, you can use Lua's mechanisms for that, like passing an environment table to load or loadfile. You can find lots of discussions around programs calling untrusted Lua code with sandboxed environments in the internet.
You can either create a One way is to not really let people write "character and weapon scripts" directly, but rather have some way for Lua code to affect your characters and weapons that you have tight control over. You can expose your own global functions for them or expect that user scripts define some callback functions for you to call. We can discuss more about designing such a modding system specifically for your use case if you'd like. |
Beta Was this translation helpful? Give feedback.
Hey @Acanixz, thanks for the question.
When you use
do_string, the code will be loaded and executed right away, just like if you loaded the chunk in Lua with load and called the returned function. If your script returns a table, then yeah the result of running such code withdo_stringwould be aLuaTable.But anyway, you are correct, you only have a "full Godot script" if you load it as a Resource in Godot (like
var lua_script = load("res://some_lua_script.lua")) …