Documentation
¶
Overview ¶
Code generated by gobindlua; DO NOT EDIT.
Code generated by gobindlua; DO NOT EDIT.
Code generated by gobindlua; DO NOT EDIT.
Example ¶
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/ChrisTrenkamp/gobindlua"
lua "github.com/yuin/gopher-lua"
)
const script = `
local vector = require "vector"
local array_struct = require "array_struct"
local matrix = require "matrix"
local gbl_array = require "gbl_array"
--[[ Notice you can use lua tables as parameters for slices. ]]
local a = vector.new_from({3,2,1})
for i=1,#a.elements,1 do
print("Go slice element index " .. tostring(i) .. ": " .. a.elements[i])
end
a.elements[1] = 1
a.elements[3] = 3
--[[ You can also convert the slice back to a table. ]]
local a_table = gbl_array.to_table(a.elements)
print("a_table type: " .. type(a_table))
for i=1,#a_table,1 do
print("Element index " .. tostring(i) .. ": " .. a_table[i])
end
--[[ gobindlua can also handle variadic arguments. ]]
local b = vector.new_variadic(4,5,6)
print("Inner product: " .. tostring(a:inner_product(b)))
m.elements = a:outer_product(b).elements
print("Outer product:")
print(m:string())
--[[ Arrays are a separate type, which can be generated with gobindlua ]]
local an_array = array_struct.new({1, 2, 3})
print("Array elements before:")
print(an_array:string())
an_array:set_elements({4, 5, 6})
print("Array elements after:")
print(an_array:string())
an_array:set_elements_from_subpackage({3, 2, 1})
print("Array elements set_elements_from_subpackage:")
print(an_array:string())
an_array.elements = {7, 8, 9}
print("Array elements directly set:")
print(an_array:string())
local direct_array_access = an_array.elements
direct_array_access[1] = 10
print("Direct array modification:")
print(an_array:string())
local identity_matrix = matrix.new_from(
{
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
}
)
print("Identity matrix:")
print(identity_matrix:string())
`
func main() {
L := lua.NewState()
defer L.Close()
gobindlua.Register(L, &Vector{}, &ArrayStruct{}, &Matrix{})
matrix := Matrix{}
L.SetGlobal("m", gobindlua.NewUserData(&matrix, L))
if err := L.DoString(script); err != nil {
log.Fatal(err)
}
jsonBytes, err := json.Marshal(matrix.Elements)
if err != nil {
log.Fatal(err)
}
fmt.Println("Outer product result in Go:", string(jsonBytes))
}
Output: Go slice element index 1: 3 Go slice element index 2: 2 Go slice element index 3: 1 a_table type: table Element index 1: 1 Element index 2: 2 Element index 3: 3 Inner product: 32 Outer product: 4.00 5.00 6.00 8.00 10.00 12.00 12.00 15.00 18.00 Array elements before: {1.000000, 2.000000, 3.000000} Array elements after: {4.000000, 5.000000, 6.000000} Array elements set_elements_from_subpackage: {3.000000, 2.000000, 1.000000} Array elements directly set: {7.000000, 8.000000, 9.000000} Direct array modification: {10.000000, 8.000000, 9.000000} Identity matrix: 1.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 1.00 Outer product result in Go: [[4,5,6],[8,10,12],[12,15,18]]
Index ¶
- Constants
- type ArrayStruct
- func (r *ArrayStruct) LuaMetatableType() string
- func (goType *ArrayStruct) LuaModuleLoader(L *lua.LState) int
- func (goType *ArrayStruct) LuaModuleName() string
- func (goType *ArrayStruct) LuaRegisterGlobalMetatable(L *lua.LState)
- func (s *ArrayStruct) SetElements(j [3]float32)
- func (s *ArrayStruct) SetElementsFromSubpackage(j *slicessubpackage.AnArray)
- func (s ArrayStruct) String() string
- type Matrix
- type Vector
- func (v Vector) InnerProduct(o Vector) (float64, error)
- func (r *Vector) LuaMetatableType() string
- func (goType *Vector) LuaModuleLoader(L *lua.LState) int
- func (goType *Vector) LuaModuleName() string
- func (goType *Vector) LuaRegisterGlobalMetatable(L *lua.LState)
- func (v Vector) OuterProduct(o Vector) (Matrix, error)
Examples ¶
Constants ¶
View Source
const ArrSize = 3
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayStruct ¶ added in v0.0.6
func NewArrayStruct ¶ added in v0.0.6
func NewArrayStruct(elems [3]float32) ArrayStruct
func (*ArrayStruct) LuaMetatableType ¶ added in v0.0.6
func (r *ArrayStruct) LuaMetatableType() string
func (*ArrayStruct) LuaModuleLoader ¶ added in v0.0.9
func (goType *ArrayStruct) LuaModuleLoader(L *lua.LState) int
func (*ArrayStruct) LuaModuleName ¶ added in v0.0.9
func (goType *ArrayStruct) LuaModuleName() string
func (*ArrayStruct) LuaRegisterGlobalMetatable ¶ added in v0.0.9
func (goType *ArrayStruct) LuaRegisterGlobalMetatable(L *lua.LState)
func (*ArrayStruct) SetElements ¶ added in v0.0.6
func (s *ArrayStruct) SetElements(j [3]float32)
func (*ArrayStruct) SetElementsFromSubpackage ¶ added in v0.0.7
func (s *ArrayStruct) SetElementsFromSubpackage(j *slicessubpackage.AnArray)
func (ArrayStruct) String ¶ added in v0.0.6
func (s ArrayStruct) String() string
type Matrix ¶
type Matrix struct {
Elements [][]float64
}
func NewMatrixFrom ¶
func (*Matrix) LuaMetatableType ¶
func (*Matrix) LuaModuleLoader ¶ added in v0.0.9
func (*Matrix) LuaModuleName ¶ added in v0.0.9
func (*Matrix) LuaRegisterGlobalMetatable ¶ added in v0.0.9
type Vector ¶
type Vector struct {
Elements []float64
}
func NewVectorFrom ¶
func NewVectorVariadic ¶
func (*Vector) LuaMetatableType ¶
func (*Vector) LuaModuleLoader ¶ added in v0.0.9
func (*Vector) LuaModuleName ¶ added in v0.0.9
func (*Vector) LuaRegisterGlobalMetatable ¶ added in v0.0.9
Click to show internal directories.
Click to hide internal directories.