mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
new --version option and qualities method in obiscript
Former-commit-id: 7b0ce2901785d5c7494dec3a7a95d1fc5dc4a52b
This commit is contained in:
@ -37,15 +37,17 @@ func pushInterfaceToLua(L *lua.LState, val interface{}) {
|
||||
case []string:
|
||||
pushSliceStringToLua(L, v)
|
||||
case []int:
|
||||
pushSliceIntToLua(L, v)
|
||||
pushSliceNumericToLua(L, v)
|
||||
case []byte:
|
||||
pushSliceNumericToLua(L, v)
|
||||
case []float64:
|
||||
pushSliceFloat64ToLua(L, v)
|
||||
pushSliceNumericToLua(L, v)
|
||||
case []bool:
|
||||
pushSliceBoolToLua(L, v)
|
||||
case nil:
|
||||
L.Push(lua.LNil)
|
||||
default:
|
||||
log.Fatalf("Cannot deal with value %v", val)
|
||||
log.Fatalf("Cannot deal with value (%T) : %v", val, val)
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,6 +165,21 @@ func pushSliceIntToLua(L *lua.LState, slice []int) {
|
||||
L.Push(luaTable)
|
||||
}
|
||||
|
||||
func pushSliceNumericToLua[T float64 | int | byte](L *lua.LState, slice []T) {
|
||||
// Create a new Lua table
|
||||
luaTable := L.NewTable()
|
||||
|
||||
// Iterate over the Go slice and set the elements in the Lua table
|
||||
for _, value := range slice {
|
||||
// Append the value to the Lua table
|
||||
// Lua is 1-indexed, so we use the length of the table + 1 as the next index
|
||||
luaTable.Append(lua.LNumber(value))
|
||||
}
|
||||
|
||||
// Push the Lua table onto the stack
|
||||
L.Push(luaTable)
|
||||
}
|
||||
|
||||
// pushSliceStringToLua creates a new Lua table and sets the elements in the table from the given Go slice. It then pushes the Lua table onto the stack.
|
||||
//
|
||||
// L *lua.LState - The Lua state
|
||||
|
Reference in New Issue
Block a user