wesnoth / jessene

A lua module for the Godot engine written in GDNative.
MIT License
14 stars 4 forks source link

I Got It Working, But Found A Potential Freeze With Invalid Lua #6

Open ghost opened 5 years ago

ghost commented 5 years ago

I don't know what I did to get the module to work (probably the part where I renamed the gdns file to LuaScript.gdns instead of just Lua.gdns). This is aside from my merging the latest commit of Godot 3.2-dev with my copy of Godot (which fixed a freeze on all GDNativeLibraries).

However, I noticed loading an invalid Lua file freezes the game as a whole.

Trying to load this file causes the freeze.

local class = require 'lua.class' -- Import the system class library
godot.Node = require 'godot.Node' -- Make sure to import the base class

local NewScript = class.extends(godot.Node) -- Create the user subclass

function NewScript:_ready()
    print("Hello Lua")
end

function NewScript:_process(delta)

end

function NewScript:command(variable)
    return "Variable: %s" % variable
end

function NewScript:get_class()
    return "Test Lua"
end

return NewScript

This file works fine.

function sum(...)
    result = 0
    local arg = {...}
    for i,v in ipairs(arg) do
       result = result + v
    end
    return result
end
ghost commented 5 years ago

The original file was from a lua module to be compiled into Godot.

This matters as I plan on sandboxing the Lua programs and letting players write lua for automation in their game. Also, the code would run server-side, so it is not good if the server freezes due to invalid lua.

ghost commented 5 years ago

With a valid lua script, if changes are made rapidly for testing, it can freeze the main thread of the game.

I managed to pull an error with Error: script not loaded (test_sandbox) where I am testing cSum(1, 3) with a sandboxed lua function I am working on. I am going to try to put this on a separate thread and lower its priority so it doesn't make my game run at 90% cpu when the script freezes up. I'll report if this workaround works.