functions

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.

Code generated by gobindlua; DO NOT EDIT.

Example
package main

import (
	"fmt"
	"log"

	"github.com/ChrisTrenkamp/gobindlua"
	lua "github.com/yuin/gopher-lua"
)

const script = `
local functions = require "functions"
local FnContainer = require "FnContainer"

function lua_left_pad(str, pad)
	local ret = ""

	for i=1,pad,1 do
		ret = "lua" .. ret
	end

	return ret .. str
end

functions.PrintMe(functions.Split("foo_bar", "_"), functions.Split("eggs&ham", "&"))

print("NotIncluded was excluded from the bindings: " .. tostring(functions.NotIncluded == nil))

--[[ You can seamlessly pass Lua and Go functions as parameters. ]]
functions.DoFunc(lua_left_pad)
functions.DoFunc(functions.GoLeftPad)

--[[ You can also assign methods to struct fields. ]]
container = FnContainer.NewFnContainer(lua_left_pad)
`

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

	// For pure functions, we use the LuaPreloadModule function instead of gobindlua.Register.
	LuaPreloadModule(L)

	gobindlua.Register(L, &FnContainer{})

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

	container := L.GetGlobal("container").(*lua.LUserData).Value.(*FnContainer)
	str := " hi lua from go!"
	fmt.Println(container.Fn(&str, 2))

}
Output:

[foo bar] [eggs ham]
NotIncluded was excluded from the bindings: true
Result of fn("foo", 3) call: lualualuafoo
Result of fn("foo", 3) call: gogogofoo
lualua hi lua from go!

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoFunc added in v0.0.16

func DoFunc(fn func(*string, int) string)

func GoLeftPad added in v0.0.16

func GoLeftPad(str string, pad int) string

func LuaPreloadModule added in v0.0.19

func LuaPreloadModule(L *lua.LState)

func NotIncluded

func NotIncluded()

func PrintMe

func PrintMe(args ...any)

func Split

func Split(s string, spl string) []string

Types

type FnContainer added in v0.0.17

type FnContainer struct {
	Fn func(*string, int) string
}

func NewFnContainer added in v0.0.17

func NewFnContainer(fn func(*string, int) string) FnContainer

func (*FnContainer) LuaMetatableType added in v0.0.17

func (r *FnContainer) LuaMetatableType() string

func (*FnContainer) LuaModuleLoader added in v0.0.17

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

func (*FnContainer) LuaModuleName added in v0.0.17

func (goType *FnContainer) LuaModuleName() string

func (*FnContainer) LuaRegisterGlobalMetatable added in v0.0.17

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

Jump to

Keyboard shortcuts

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