Executing Lua closure from Go

Abierto
#44 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
18/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
go, lua
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Go
Estrellas
3.5k
Forks
217
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Shopify/go-lua

Todos los issues de Shopify/go-lua

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.