Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stuck when xpcall #464

Open
Junyang-Liu opened this issue Dec 6, 2023 · 3 comments · May be fixed by #467
Open

stuck when xpcall #464

Junyang-Liu opened this issue Dec 6, 2023 · 3 comments · May be fixed by #467

Comments

@Junyang-Liu
Copy link

Junyang-Liu commented Dec 6, 2023

  1. What version of GopherLua are you using?

[email protected]

  1. What version of Go are you using? :

go version go1.21.4 darwin/amd64

  1. What operating system and processor architecture are you using?

Mac OS Catalina 10.15.3 x86_64

  1. What did you do?

i do this: (go) L.DoFile -> (lua)xpcall -> (lua)dofile
here the code
golang:

   L := lua.NewState()
   defer L.Close()

   if err := L.DoFile("init.lua"); err != nil {
   	fmt.Println(err.Error())
   }

init.lua

xpcall(dofile, printErr, "first.lua")	-- not work

first.lua

print("sth.")
  1. What did you expect to see?

:L.DoFile should return,and first.lua should run

  1. What did you see instead?

:go stuck there, only happens when xpcall -> dofile

➜  goluadofile ls
first.lua init.lua  run.go
➜  goluadofile go run ./run.go
start go run
[init] start
run_path:	init
^Csignal: interrupt

always stuck until ^C to interrupt it.

  1. here are all source code files:
    run.go
package main

import (
	"fmt"

	lua "github.com/yuin/gopher-lua"
)

func main() {
	fmt.Println("start go run")

	L := lua.NewState()
	defer L.Close()

	if err := L.DoFile("init.lua"); err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println("end go run")
}

init.lua

local function printErr(err)
	print(err)
	print(debug.traceback())
end

local function test( ... )
	print("is test function run, args: ", ...)
end

run_path = "init"
print("[init] start")


print("run_path:", run_path)

-- xpcall(test, printErr, "test")	-- work fine

-- dofile("first.lua")			-- work fine

-- pcall(dofile, "first.lua")	-- work fine

xpcall(dofile, printErr, "first.lua")	-- not work


print("run_path:", run_path)

print("[init] end")

first.lua

print("[first] start")
run_path = "first"
print("[first] end")
  1. I don’t know if I set lua.NewState() up wrong, never mind to give more information
@waschik waschik linked a pull request Dec 14, 2023 that will close this issue
@waschik
Copy link
Contributor

waschik commented Dec 14, 2023

As fare as I see there are currently zero arguments passed to function in xpcall. So above test is similar to

dofile()

And this reads from stdin. I do not know why I can not stop reading with ctrl+d (Linux) but you can see it reads from stdin if you enter for example a b and enter.

I tried to fix the problem with attached pull request. Might create a merge conflict if another commit is merged which adds to issues.lua is merged. But this should be trivially be solved.

@waschik
Copy link
Contributor

waschik commented Dec 14, 2023

This issue is a duplicate of #454.

@Junyang-Liu
Copy link
Author

As fare as I see there are currently zero arguments passed to function in xpcall. So above test is similar to

dofile()

And this reads from stdin. I do not know why I can not stop reading with ctrl+d (Linux) but you can see it ready from stdin if you enter for example a b and enter.

thats true, stdin.

I tried to fix the problem with attached pull request. Might create a merge conflict if another commit is merged which adds to issues.lua is merged. But this should be trivially be solved.

Super! 🚀
@waschik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants