godot_luaAPI
godot_luaAPI copied to clipboard
Argument type checking for Godot functions with strict types.
Hellow again... I don't want to be too demanding but..........
I want you to make wrong argument detector like in default Lua:
For example if we load function
into string.sub
we will got next output:
> string.sub(print,1)
stdin:1: bad argument #1 to 'sub' (string expected, got function)
stack traceback:
[C]: in function 'sub'
stdin:1: in main chunk
[C]: in ?
But if I load int
value into my Godot func blit(text :String, textColor, backColor):
like that: blit(1,print,1)
-> it will simply refuse to run and not even sent an error or message like "hey! you just load wrong arg to func
".
Of course I can create that thing my self and I have done it allready (see the picture) but
blit
function is one of the most called so I MUST optimise it VERY WELL becase it's original is written in C++
.
I have done some perfomance checks (simple fractal calc function) and run fract(2000) for both Godot and Lua 300 times to calculate mid value:
So there are results:
Results. Debug version:
Godot : 0.40313333333333 sec
LuaAPI: 0.0085425333332902 sec
Release version:
Godot : 0.24503333333333 sec
LuaAPI: 0.00816905 sec
Test source code:
extends Node
func fact(num :int) -> int:
var rez := 1
for i in num:
rez = rez*(i+1)
return rez
func test() -> int:
var st = Time.get_ticks_msec()
for i in 2000:
fact(i)
var nd = Time.get_ticks_msec()
return nd-st
func _init():
print("LuaAPI.test:")
var a = LuaAPI.new()
a.bind_libraries(["base","os"])
a.push_variant("func",func():push_error("Error"))
var rez = a.do_string("""
function fact(num)
local rez = 1
for i=1,num do
rez = rez*i
end
return rez
end
function test()
local st = os.clock()
for i=0,2000 do
fact(i)
end
local nd = os.clock()
return nd-st
end
local data = 0
for i=1,300 do
data = data + test()
end
print("Lua factor: ", data/300) --mid value
""")
var data = 0
for i in 300:
data = data + test()
print("Godot: ",data/300.0/100.0)
So as you can see GDscript is INCREDIBLY SLOW comparring to Lua, so a single argument type check can ruin evrything.
blit
is important text function used by Pine3D and other CraftOS programs to render 2D/3D stuff (yea I am talking about Game that run on CraftOS inside another Game).
And it need to be called ~19*20 times per second to achive ~20 FPS inside CraftOS Games...
So it's very important for me to have that bad argument
detector for Godot strict typed functions...
If you decide to add that feature (then thank you very much), you don't need to do that check for all classes that exist in Godot.
A simple check for Lua only types {nil,number,string, ...}
should be enought...
Thank you for your attention...