Skip to content

gooops/glua

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glua

This is a simple Golang bindings to Lua.

A sample likes this:

package main

import (
        "fmt"
        "glua"
)

type Int struct {
        I int
}

func NewInt() *Int {
        return &Int{10}
}

func (i Int) PrintInt(str string) {
        fmt.Println(str, i.I)
}

func main() {
        L := glua.NewState()
        
        L.Openlibs()

        var tlib = glua.Libfuncs{
                "gotest", // lib name
                map[string]interface{}{
                        "NewInt":    NewInt,          // lua function name, go function
                        "PrintInt":  (*Int).PrintInt, // lua function name, go function
                        "goprintln": fmt.Println,
                },
        }
        if ok, err := L.Register(&tlib); !ok {
                fmt.Println(err.Error())
                return
        }
        
        L.Dostring(`gotest.PrintInt(gotest.NewInt(), "Int is")`) 

        L.Dofile("test.lua")
        
        L.Call("gotest.goprintln", "Call lua function.", 123456)
}

test.lua file likes this:

--test.lua
gotest.goprintln(true, 123, "lua", gotest.NewInt())

###Code license GNU Lesser GPL

About

This is a simple Golang bindings to Lua.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 71.6%
  • C 25.1%
  • Lua 3.3%