Beispiel #1
0
func GetField(L *luajit.State, f string) (float64, bool) {
	var result float64

	L.Pushstring(f)
	L.Gettable(-2)
	if L.Isnumber(-1) != true {
		print("invalid field in table")
		return 0, false
	}

	result = L.Tonumber(-1)
	L.Pop(1)

	return result, true

}
Beispiel #2
0
func SetField(L *luajit.State, f string, v float64) {
	L.Pushstring(f)
	L.Pushnumber(v)
	L.Settable(-3)
}
Beispiel #3
0
func DumpLuaStack(L *luajit.State) {
	var top int

	top = L.Gettop()
	for i := 1; i <= top; i++ {
		t := L.Type(i)
		switch t {
		case luajit.Tstring:
			fmt.Println("String : \t", L.Tostring(i))
		case luajit.Tboolean:
			fmt.Println("Bool : \t\t", L.Toboolean(i))
		case luajit.Tnumber:
			fmt.Println("Number : \t", L.Tonumber(i))
		default:
			fmt.Println("Type : \t\t", L.Typename(i))
		}
	}
	print("\n")
}
Beispiel #4
0
func summator(L *luajit.State) int {
	a := L.Tonumber(1)
	b := L.Tonumber(2)
	L.Pushnumber(a + b)
	return 1
}