WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
361 stars 27 forks source link

Bug Report:Pulling a global function from a thread will not call it from that thread. #157

Closed RadiantUwU closed 11 months ago

RadiantUwU commented 11 months ago

Describe the bug The bug is from where the function is being called.

The function first is grabbed, checked, a reference is then made, returning a callable to LuaAPI and the func ref. Now if you pause here, you will notice that even if a LuaCoroutine or the main LuaAPI gets the reference, it will always reference the main LuaAPI and never the other.

To Reproduce Steps to reproduce the behavior:

extends Node

func print_(s: String)->void:
    print(s)

func _ready():
    var api := LuaAPI.new()
    api.bind_libraries(["coroutine","basic","base"])
    api.push_variant("print",print_)
    var coro := api.new_coroutine()
    api.do_string("""
    function print_running_coroutine()
        print(tostring(coroutine.running()))
    end
    """)
    var api_reference:Callable = api.pull_variant("print_running_coroutine")
    var coro_reference:Callable = coro.pull_variant("print_running_coroutine")
    api_reference.call([])
    coro_reference.call([])

Result:

thread: 0xe209d68
thread: 0xe209d68

Expected behavior Result expected:

thread: 0xe209d68
thread: 0xe321c92

Environment (please complete the following information):

Additional context N/A

RadiantUwU commented 11 months ago

I'll try to fix it later myself

Trey2k commented 11 months ago

This is because Lua Courtines all share the state of the parent LuaAPI object. Being able to call specific methods or pull variables from the coroutine is a convenience feature, but will have no difference from pulling it from the parent state.

RadiantUwU commented 11 months ago

This is because Lua Courtines all share the state of the parent LuaAPI object. Being able to call specific methods or pull variables from the coroutine is a convenience feature, but will have no difference from pulling it from the parent state.

I still kinda see it as an issue which is why i want to fix it

Trey2k commented 11 months ago

I still kinda see it as an issue which is why i want to fix it

Well, good luck. This is just how lua was designed. Coroutines are not a full lua state. They are a process within the state and can access it.