Esempio n. 1
0
// PushGoClosure pushes a lua.LuaGoFunction to the stack wrapped in a Closure.
// this permits the go function to reflect lua type 'function' when checking with type()
// this implements behaviour akin to lua_pushcfunction() in lua C API.
func (L *State) PushGoClosure(f LuaGoFunction) {
	L.PushGoFunction(f)      // leaves Go function userdata on stack
	C.clua_pushcallback(L.s) // wraps the userdata object with a closure making it into a function
}
Esempio n. 2
0
File: lua.go Progetto: szll/golua
// Sets a metamethod to execute a go function
//
// The code:
//
// 	L.LGetMetaTable(tableName)
// 	L.SetMetaMethod(methodName, function)
//
// is the logical equivalent of:
//
// 	L.LGetMetaTable(tableName)
// 	L.PushGoFunction(function)
// 	L.SetField(-2, methodName)
//
// except this wouldn't work because pushing a go function results in user data not a cfunction
func (L *State) SetMetaMethod(methodName string, f LuaGoFunction) {
	L.PushGoFunction(f)      // leaves Go function userdata on stack
	C.clua_pushcallback(L.s) // wraps the userdata object with a closure making it into a function
	L.SetField(-2, methodName)
}
Esempio n. 3
0
func (L *State) PushGoCallback(f GoFunction) {
	L.PushGoFunction(f) // leaves Go function userdata on stack
	C.clua_pushcallback(L.s)
}