Skip to content

Convert LUA types to go #34

@maja42

Description

@maja42

gopher-luar is able to automatically convert lua-types into go - an example for that is given in the documentation.

However, this mechanism is not exposed in the API. While there is a luar.New(), the counterpart is missing.
This becomes necessary when calling lua-functions from go, and trying to get the function's return value:

// Convert from go-to-LUA
var args []interface{} = ...
lArgs := make([]lua.LValue, len(args))
for i, a := range args {
    lArgs[i] = luar.New(L, a)
}

var numberOfReturnArgs = 4
vm.state.CallByParam(lua.P{
    Fn:      L.GetGlobal("functionName"),
    NRet:    numberOfReturnArgs,
}, lArgs...)

// Collect return values:
retValues := make([]interface{}, returnArgs)
for i := returnArgs; i > 0; i-- {
    ret := vm.state.Get(-1)
    vm.state.Pop(1)

    retValues[i-1] = ret // <--- how to convert to go-type?
}

How can I convert these return-values to go-types?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions