mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add management of []interface{} to the LUA API.
This commit is contained in:
@ -46,6 +46,8 @@ func pushInterfaceToLua(L *lua.LState, val interface{}) {
|
|||||||
pushSliceNumericToLua(L, v)
|
pushSliceNumericToLua(L, v)
|
||||||
case []bool:
|
case []bool:
|
||||||
pushSliceBoolToLua(L, v)
|
pushSliceBoolToLua(L, v)
|
||||||
|
case []interface{}:
|
||||||
|
pushSliceInterfaceToLua(L, v)
|
||||||
case nil:
|
case nil:
|
||||||
L.Push(lua.LNil)
|
L.Push(lua.LNil)
|
||||||
case *sync.Mutex:
|
case *sync.Mutex:
|
||||||
@ -78,6 +80,29 @@ func pushMapStringInterfaceToLua(L *lua.LState, m map[string]interface{}) {
|
|||||||
L.Push(luaTable)
|
L.Push(luaTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pushSliceInterfaceToLua(L *lua.LState, s []interface{}) {
|
||||||
|
// Create a new Lua table
|
||||||
|
luaTable := L.NewTable()
|
||||||
|
// Iterate over the Go map and set the key-value pairs in the Lua table
|
||||||
|
for _, value := range s {
|
||||||
|
switch v := value.(type) {
|
||||||
|
case int:
|
||||||
|
luaTable.Append(lua.LNumber(v))
|
||||||
|
case float64:
|
||||||
|
luaTable.Append(lua.LNumber(v))
|
||||||
|
case bool:
|
||||||
|
luaTable.Append(lua.LBool(v))
|
||||||
|
case string:
|
||||||
|
luaTable.Append(lua.LString(v))
|
||||||
|
default:
|
||||||
|
log.Fatalf("Doesn't deal with slice containing value %v of type %T", v, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push the Lua table onto the stack
|
||||||
|
L.Push(luaTable)
|
||||||
|
}
|
||||||
|
|
||||||
// pushMapStringIntToLua creates a new Lua table and iterates over the Go map to set key-value pairs in the Lua table. It then pushes the Lua table onto the stack.
|
// pushMapStringIntToLua creates a new Lua table and iterates over the Go map to set key-value pairs in the Lua table. It then pushes the Lua table onto the stack.
|
||||||
//
|
//
|
||||||
// L *lua.LState - the Lua state
|
// L *lua.LState - the Lua state
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
// TODO: The version number is extracted from git. This induces that the version
|
// TODO: The version number is extracted from git. This induces that the version
|
||||||
// corresponds to the last commit, and not the one when the file will be
|
// corresponds to the last commit, and not the one when the file will be
|
||||||
// commited
|
// commited
|
||||||
var _Commit = "40fb4e9"
|
var _Commit = "ad2461a"
|
||||||
var _Version = "Release 4.3.0"
|
var _Version = "Release 4.3.0"
|
||||||
|
|
||||||
// Version returns the version of the obitools package.
|
// Version returns the version of the obitools package.
|
||||||
|
Reference in New Issue
Block a user