functions

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 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 fn_container = require "fn_container"

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

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

	return ret .. str
end

functions.print_me(functions.split("foo_bar", "_"), functions.split("eggs&ham", "&"))

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

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

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

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

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

	gobindlua.Register(L, &FnContainer{})

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

	container := L.GetGlobal("container").(*lua.LUserData).Value.(*FnContainer)
	fmt.Println(container.Fn(" hi lua from go!", 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 FunctionsModuleLoader added in v0.0.9

func FunctionsModuleLoader(L *lua.LState) int

func GoLeftPad added in v0.0.16

func GoLeftPad(str string, pad int) string

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