-
Notifications
You must be signed in to change notification settings - Fork 15
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
interface conversion error when trying to PullTable
#27
Comments
After looking at the tests, I noticed that The updated code reflects this change and grabs the table. package main
import (
"fmt"
"log"
"os"
"github.com/Shopify/go-lua"
"github.com/Shopify/goluago/util"
"gopkg.in/yaml.v2"
)
func main() {
l := lua.NewState()
util.Open(l)
source := `
local my_map = {
key1="value1",
key2="value2",
}
local some_list = array({my_map, "item2"})
return({list_with_a_map=some_list})
`
if err := lua.DoString(l, source); err != nil {
panic(err)
}
index := 1
if !l.IsTable(index) {
log.Println("the last return value of the script must be a table")
os.Exit(1)
}
table, err := util.PullTable(l, index)
if err != nil {
log.Panicln("getting table: %s", err)
}
payload, err := yaml.Marshal(table)
if err != nil {
log.Panicln("marshaling yaml: %s", err)
}
fmt.Println(string(payload))
} Why is the artifact |
There's no good way to distinguishing via golang that a With the following function _.isArray(value)
return type(value) == "table" and (value[1] or next(value) == nil)
end This is taken from some of my old lua library. If we can write the equivalent as a golang set of instructions. The use of I'm going to give it a try. |
Using /* return type(value) == "table" and (value[1] or next(value) == nil) */
lua_getfield(L,LUA_ENVIRONINDEX,"type");
lua_getfield(L,LUA_ENVIRONINDEX,"value");
lua_call(L,1,1);
lua_pushliteral(L,"table");
const int lc1 = lua_equal(L,-2,-1);
lua_pop(L,2);
lua_pushboolean(L,lc1);
if (lua_toboolean(L,-1)) {
lua_pop(L,1);
lua_getfield(L,LUA_ENVIRONINDEX,"value");
lua_pushnumber(L,1);
lua_gettable(L,-2);
lua_remove(L,-2);
if (!(lua_toboolean(L,-1))) {
lua_pop(L,1);
lua_getfield(L,LUA_ENVIRONINDEX,"next");
lua_getfield(L,LUA_ENVIRONINDEX,"value");
lua_call(L,1,1);
lua_pushnil(L);
const int lc2 = lua_equal(L,-2,-1);
lua_pop(L,2);
lua_pushboolean(L,lc2);
}
} I'll just see if this can be converted to the equivalent golang code. Update: I think I found the equivalant commands. Don't think I'm going to get this done tonight, though. |
To start off, I know I am doing something wrong. My usage of
PullTable
is based off the work done with encoding JSON support.The value
PullTable
is trying to get would be the lastreturn
in the execution of the script.When I try, I get the following error:
The source to reproduce this problem:
Any insight to what I am doing wrong?
The text was updated successfully, but these errors were encountered: