primitives

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

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 PrimitiveStruct = require "PrimitiveStruct"

--[[ You can call the constructor functions and methods and access the fields from Lua. ]]
data = PrimitiveStruct.NewPrimitiveStruct()
data.MyBool = true
data.MyInt = 42
data.MyInt64 = 0xDEADBEEF
data.MyFloat = 3.14
data.MyString = "all your lua are belong to us"

print("MyBool: " .. tostring(data.MyBool))
print("MyInt: " .. tostring(data.MyInt))
print("MyInt64: " .. tostring(data.MyInt64))
print("MyFloat: " .. tostring(data.MyFloat))
print("MyString: " .. tostring(data.MyString))
print("WillBeExcluded has been excluded: " .. tostring(data.WillBeExcluded == nil))

data:SetSpecializedInt(9001)
print("MySpecializedInt: " .. tostring(data.MySpecializedInt))

print("DivideMyInt: " .. tostring(data:DivideMyInt(2)))
local _, err = pcall(function () data:DivideMyInt(0) end)
print("DivideMyInt error: " .. err)

print("ExcludedMethod has been excluded: " .. tostring(data.ExcludedMethod == nil))
`

func main() {
	L := lua.NewState()
	defer L.Close()

	var registrarPointer *PrimitiveStruct
	gobindlua.Register(L, registrarPointer)
	// For ease of use, you can pass in &PrimitiveStruct{} to the Register function as well.
	// The Register function does not require the pointer to contain a value.  It's simply
	// for registering the metadata tables.

	if err := L.DoString(script); err != nil {
		log.Fatal(err)
	}

	data := L.GetGlobal("data").(*lua.LUserData).Value.(*PrimitiveStruct)
	jsonBytes, err := json.MarshalIndent(data, "", "\t")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(jsonBytes))

}
Output:

MyBool: true
MyInt: 42
MyInt64: 3735928559
MyFloat: 3.14
MyString: all your lua are belong to us
WillBeExcluded has been excluded: true
MySpecializedInt: 9001
DivideMyInt: 21
DivideMyInt error: <string>:23: divide by zero error
ExcludedMethod has been excluded: true
{
	"MyBool": true,
	"MyInt": 42,
	"MyInt64": 3735928559,
	"MyFloat": 3.14,
	"SomeString": "all your lua are belong to us",
	"WillBeExcluded": "",
	"MySpecializedInt": 9001
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PrimitiveStruct

type PrimitiveStruct struct {
	// All exported fields will have bindings created for GopherLua
	MyBool  bool
	MyInt   int32
	MyInt64 int64
	// Notice how `lua_PrimitiveStruct.go` will properly cast the float64 to this named type
	MyFloat primitivesubpackage.SomeFloat64
	// You can use tags to explicitly declare the Lua name of the field.
	SomeString string `gobindlua:"MyString"`
	// You can also exclude fields
	WillBeExcluded   string `gobindlua:"-"`
	MySpecializedInt SpecializedInt
}

func NewPrimitiveStruct

func NewPrimitiveStruct() PrimitiveStruct

Use the gobindlua:constructor directive to declare a function as a constructor in the Lua bindings.

func (PrimitiveStruct) DivideMyInt

func (p PrimitiveStruct) DivideMyInt(divisor float64) (float64, error)

Use the gobindlua:function directive to bind a method in Lua.

func (PrimitiveStruct) ExcludedMethod added in v0.0.4

func (p PrimitiveStruct) ExcludedMethod()

There's no gobindlua directive, so this method has been excluded.

func (*PrimitiveStruct) LuaMetatableType

func (r *PrimitiveStruct) LuaMetatableType() string

func (*PrimitiveStruct) LuaModuleLoader added in v0.0.9

func (goType *PrimitiveStruct) LuaModuleLoader(L *lua.LState) int

func (*PrimitiveStruct) LuaModuleName added in v0.0.9

func (goType *PrimitiveStruct) LuaModuleName() string

func (*PrimitiveStruct) LuaRegisterGlobalMetatable added in v0.0.9

func (goType *PrimitiveStruct) LuaRegisterGlobalMetatable(L *lua.LState)

func (*PrimitiveStruct) SetSpecializedInt added in v0.0.5

func (p *PrimitiveStruct) SetSpecializedInt(i SpecializedInt)

type SpecializedInt added in v0.0.5

type SpecializedInt uint32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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