converter

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-lua-converter

A GopherLua utility package for converting between Go values and Lua values.

Installation

go get github.com/kerimovok/go-lua-converter

Usage

Go to Lua Conversion
import (
    lua "github.com/yuin/gopher-lua"
    converter "github.com/kerimovok/go-lua-converter"
)

L := lua.NewState()
defer L.Close()

// Convert Go value to Lua
goValue := map[string]interface{}{
    "name": "John",
    "age": 30,
    "tags": []interface{}{"developer", "golang"},
}
luaTable := converter.ToLua(L, goValue)

// Or use specific converters
luaMap := converter.MapToTable(L, map[string]interface{}{"key": "value"})
luaArray := converter.SliceToTable(L, []interface{}{1, 2, 3})
Lua to Go Conversion
// Get a Lua value from the stack or table
luaValue := L.Get(-1) // or from table

// Convert to Go value
goValue := converter.FromLua(L, luaValue)

// Convert Lua table to Go map or slice
luaTable := L.GetGlobal("mytable").(*lua.LTable)
goValue := converter.TableToGo(L, luaTable)

Functions

ToLua(L *lua.LState, v interface{}) lua.LValue

Converts a Go value to a Lua value.

  • Supported types: string, int, int32, int64, float32, float64, bool, map[string]interface{}, []interface{}, nil
  • Unknown types: Converted to string representation
MapToTable(L *lua.LState, m map[string]interface{}) *lua.LTable

Converts a Go map to a Lua table.

SliceToTable(L *lua.LState, arr []interface{}) *lua.LTable

Converts a Go slice to a Lua table (1-indexed).

FromLua(L *lua.LState, lv lua.LValue) interface{}

Converts a Lua value to a Go value.

  • Supported types: nil, bool, string, number, table
  • Unknown types: Converted to string
TableToGo(L *lua.LState, tbl *lua.LTable) interface{}

Converts a Lua table to a Go value (map or slice).

  • Array detection: If table has consecutive integer keys starting from 1, returns []interface{}
  • Otherwise: Returns map[string]interface{}

Notes

  • Lua arrays are 1-indexed, Go slices are 0-indexed - conversion handles this automatically
  • Tables with mixed keys (both integer and string) are treated as maps
  • Numbers are converted to float64 when converting from Lua to Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromLua

func FromLua(L *lua.LState, lv lua.LValue) interface{}

FromLua converts a Lua value to a Go value. Supports: nil, bool, string, number, table (array or map).

func MapToTable

func MapToTable(L *lua.LState, m map[string]interface{}) *lua.LTable

MapToTable converts a Go map[string]interface{} to a Lua table.

func SliceToTable

func SliceToTable(L *lua.LState, arr []interface{}) *lua.LTable

SliceToTable converts a Go []interface{} to a Lua table. Lua arrays are 1-indexed, so the slice is converted accordingly.

func TableToGo

func TableToGo(L *lua.LState, tbl *lua.LTable) interface{}

TableToGo converts a Lua table to a Go value (map or slice). It detects if the table is an array (consecutive integer keys starting from 1) or a map (mixed or string keys).

func ToLua

func ToLua(L *lua.LState, v interface{}) lua.LValue

ToLua converts a Go value to a Lua value. Supports: string, numbers (int, int32, int64, float32, float64), bool, map[string]interface{}, []interface{}, and nil. Unknown types are converted to string representation.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址