Executing Lua closure from Go

オープン
#44 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
18/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
go, lua
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Go
スター
3.5k
フォーク
217
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Shopify/go-lua のほかの issue

Shopify/go-lua の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。