WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
371 stars 28 forks source link

Vector2.floor() not working on main branch #99

Closed Griiimon closed 1 year ago

Griiimon commented 1 year ago

local vec= Vector2(10.5, 1) vec= vec.floor()

will produce a "attempt to call a nil value (field 'floor')" as does any other gdscript Vector2/3 method i tried so far

Trey2k commented 1 year ago

Hello, thanks for submitting an issue. Unfortunately I can not seem to reproduce this behavior. Can you please tell me which version of the module you are using and what platform you are on?

The following outputs (10, 1) from the Linux engine nightly build:

extends Node2D

var lua: LuaAPI

func _ready() -> void:
    lua = LuaAPI.new()
    lua.do_string("""
    local vec = Vector2(10.5, 1)
    vec = vec.floor()
    print(vec)
    """)
Griiimon commented 1 year ago

Sorry for posting this issue without any context. Total noob move.

So this is the latest GDExtension nightly running on Windows 10 64Bit. Godot v.4.0.2.

func _ready():
    var lua= LuaAPI.new()

    var err: LuaError = lua.do_string("""
    local vec= Vector3(10.5,0,1)
    vec= vec.floor()
    print(vec)
    """)

    if err is LuaError:
        print("ERROR %d: %s" % [err.type, err.message])
        return

func _lua_print(message: String):
    print(message)

Output:

ERROR 2: [LUA_ERRRUN - runtime error ] [string "..."]:3: attempt to call a nil value (field 'floor') stack traceback:

Edit: Same issue with Godot v.4.0.0-stable

Trey2k commented 1 year ago

Sorry for posting this issue without any context. Total noob move.

No problem at all man!

So this is the latest GDExtension nightly running on Windows 10. Godot v.4.0.2.

Okay so GDExtension for this addon is still very alpha. There are still many blocking bugs for us in godot-cpp which isnt getting much work done on it. I maintain a fork of godot-cpp which applies enough fixes to make it compile pretty much. I will see if this is a issue I can fix in a bit. Thanks again for reporting it!

Griiimon commented 1 year ago

Thanks for your answer.

I heard that about godot-cpp, it's a bummer. But other than that the extension performs pretty much flawlessly for me so far and i did quite a bit of stuff with it already. Except maybe getting very non-descriptive LuaErrors when i missed a closing bracket or something, that don't include a line number.

Is Windows Editor the version I should use if I want an even more stable implementation?

Trey2k commented 1 year ago

Is Windows Editor the version I should use if I want an even more stable implementation?

Very much so yes. The editor and template builds are built with luaAPI as a core engine module instead if a extension.

The error messages is fundamental GDExension issue. (Atleast when it comes to gdscript calls from lua) as there is no protected call option for Variants currently like there is with modules. Meaning we don't have the option of capturing the error message often.

There is also a issue present in both that I have yet to find a fix for. That being the luap call sometimes gives useless error messages. But I think that's just lua.

I am glad to hear that it's working well enough and have high hope GDextension will become more stable with time. Especially once godot 4 is more fleshed out and broken in.

Griiimon commented 1 year ago

Got it.

Btw: Thank you so much for providing this addon. It saved me a lot of headaches already and I wish I'd found it sooner because my other attempts at implementing scripting languages were a nightmare compared to this. It saves me so much time that I can spend on the actual meat of my project, as it should be.

Trey2k commented 1 year ago

No problem at all, glad you find it useful. Let me know if you run into any other issues!

I will keep you updated regarding this one.

Trey2k commented 1 year ago

Update on this issue, I have done some digging into it and this may be a larger issue than originally thought. Our current method of copying the memory directly into lua userdata does not seem to work for a GDExtension variant. I don't know why that is yet. It also is working in the case that the Variant originates from GDScript.

Trey2k commented 1 year ago

I have now found the root cause of this issue. We currently use the has_method function on Variant to test if the variant indeed has the method. In GDExtension it seems to wrongfully report false if the argument you pass to it is a Variant and not a String() Reported upstream: https://github.com/godotengine/godot-cpp/issues/1120

I think this can be worked around easily enough however.