Executing Lua closure from Go

Đang mở
#44 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
18/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
go, lua
Lĩnh vực
compilers

Hướng nghiên cứu

Start with the calls in the report: l.Register, l.ToValue(1), l.PushLightUserData and l.Call in the go-lua API. The question is whether a Lua closure saved as a Go value can be pushed back and invoked, and why the push yields a nil call. Done means a reproducible test that stores a closure from a Lua callback and calls it later from Go, or a clear statement of what the API supports.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

If I have a *lua.State where I register a function:

l := lua.NewState()

var closure interface{} 
l.Register("myCallback", func(l *lua.State) int {
    closure = l.ToValue(1)
    return 0
})

is it possible to call the function in Lua and pass a closure that can be executed later:

myCallback(function()
  print("hello!")
end)

So then I can call l.Call() on the body of the script which executes my callback to my registered function. Then I tried pushing it back on the stack and calling:

l.PushLightUserData(closure)
l.Call(0, 0)

However, I get this error:

runtime error: [string "main"]:4: attempt to call a nil value

I checked closure and verified that it's a *luaClosure.

Is it possible to save a closure and call it later from Go?


/cc @aybabtme

Ngôn ngữ chính
Go
Star
3.5k
Fork
217
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Shopify/go-lua

Tất cả issue của Shopify/go-lua

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.