mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 12:00:39 +00:00
8c7017a99d
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5" - Update version.txt from 4.29 → .30 (automated by Makefile)
1.6 KiB
1.6 KiB
Semantic Description of obilua Package
This Go package provides utilities for converting Lua tables—used in a Gopher-Lua environment—to native Go data structures.
-
Table2Interface:
Converts a Lua*lua.LTableinto either:- A Go slice (
[]interface{}) if the table is array-like (keys are numeric, starting at 1), preserving order and type coercion (nil,bool,float64,string). - A Go map (
map[string]interface{}) if the table contains string keys (i.e., a hash/dictionary).
- A Go slice (
-
Table2ByteSlice:
Specifically converts an array-like Lua table into a[]byte, assuming all values are numeric and ≤ 255.- Fails with a fatal log if non-numeric or out-of-range values are encountered.
- Also fails fatally for hash-like (non-array) tables.
-
Key Design Notes:
- Type coercion is explicit and safe: only
LTNil,LTBool,LTNumber,LTStringare supported. - Array detection relies on key type: if all keys are
LNumber, the table is treated as an array. - Uses
logrusfor fatal error reporting. - No dependency on external serialization (e.g., JSON); conversions are direct and lightweight.
- Type coercion is explicit and safe: only
-
Use Cases:
- Bridging Lua scripting layers with Go backends (e.g., embedded config parsing, plugin systems).
- Efficiently extracting structured data from Lua state into idiomatic Go types.
⚠️ Limitations:
- No support for nested tables or custom types.
- Array indexing assumes 1-based Lua semantics (converted to 0-indexed Go slices).
- No error handling: misuse triggers
log.Fatalf.