func main() {
	var L *lua51.State

	L = lua51.NewState()
	L.OpenLibs()

	L.GetField(lua51.LUA_GLOBALSINDEX, "print")
	L.PushString("Hello World!")
	L.Call(1, 0)

	L.PushGoFunction(test)
	L.PushGoFunction(test)
	L.PushGoFunction(test)
	L.PushGoFunction(test)

	L.PushGoFunction(test2)
	L.PushInteger(42)
	L.Call(1, 0)

	L.Call(0, 0)
	L.Call(0, 0)
	L.Call(0, 0)

	L.Close()
}
func main() {

	var L *lua.State

	L = lua.NewState()
	defer L.Close()
	L.OpenLibs()

	// just to show we can catch the panic
	defer func() {
		fmt.Println("done")
		if x := recover(); x != nil {
			fmt.Printf("run time panic: %v", x)
		}
	}()

	// we can still catch the panic without this,
	// but it allows us to do some custom recovery
	currentPanicf := L.AtPanic(nil)
	currentPanicf = L.AtPanic(currentPanicf)
	newPanic := func(L1 *lua.State) int {
		fmt.Println("I AM PANICKING!!!")
		return currentPanicf(L1)
	}
	L.AtPanic(newPanic)

	//force a panic
	L.PushNil()
	L.Call(0, 0)
}
Beispiel #3
0
// make and initialize a new Lua state
func Init() *lua.State {
	var L = lua.NewState()
	L.OpenLibs()
	initializeProxies(L)
	RawRegister(L, "luar", Map{
		"map2table":   map2table,
		"slice2table": slice2table,
	})
	return L
}
func main() {
	var L *lua.State
	L = lua.NewState()
	L.OpenLibs()

	rawptr := L.NewUserdata(uintptr(unsafe.Sizeof(Userdata{})))
	var ptr *Userdata
	ptr = (*Userdata)(rawptr)
	ptr.a = 2
	ptr.b = 3

	fmt.Println(ptr)

	rawptr2 := L.ToUserdata(-1)
	ptr2 := (*Userdata)(rawptr2)

	fmt.Println(ptr2)
}