本文整理匯總了Golang中github.com/aarzilli/golua/lua.State.NewMetaTable方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.NewMetaTable方法的具體用法?Golang State.NewMetaTable怎麽用?Golang State.NewMetaTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aarzilli/golua/lua.State
的用法示例。
在下文中一共展示了State.NewMetaTable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initializeProxies
func initializeProxies(L *lua.State) {
flagValue := func() {
L.SetMetaMethod("__tostring", proxy__tostring)
L.SetMetaMethod("__gc", proxy__gc)
L.SetMetaMethod("__eq", proxy__eq)
L.PushBoolean(true)
L.SetField(-2, "luago.value")
L.Pop(1)
}
L.NewMetaTable(cSLICE_META)
L.SetMetaMethod("__index", slice__index)
L.SetMetaMethod("__newindex", slice__newindex)
L.SetMetaMethod("__len", slicemap__len)
L.SetMetaMethod("__ipairs", slice__ipairs)
flagValue()
L.NewMetaTable(cMAP_META)
L.SetMetaMethod("__index", map__index)
L.SetMetaMethod("__newindex", map__newindex)
L.SetMetaMethod("__len", slicemap__len)
L.SetMetaMethod("__pairs", map__pairs)
flagValue()
L.NewMetaTable(cSTRUCT_META)
L.SetMetaMethod("__index", struct__index)
L.SetMetaMethod("__newindex", struct__newindex)
flagValue()
L.NewMetaTable(cINTERFACE_META)
L.SetMetaMethod("__index", interface__index)
flagValue()
L.NewMetaTable(cCHANNEL_META)
//~ RegisterFunctions(L,"*",FMap {
//~ "Send":channel_send,
//~ "Recv":channel_recv,
//~ })
L.NewTable()
L.PushGoFunction(channel_send)
L.SetField(-2, "Send")
L.PushGoFunction(channel_recv)
L.SetField(-2, "Recv")
L.SetField(-2, "__index")
flagValue()
}
示例2: installWorld
func installWorld(state *lua.State) {
log.Println("Installing world")
printStackTypes(state)
state.NewMetaTable(ThingMetaTableName) // ( -- mtbl )
state.SetMetaMethod("__index", MessThingIndex) // ( mtbl -- mtbl )
state.Pop(1) // ( mtbl -- )
worldTable := map[string]interface{}{
/*
"Root":
"Create": func...
*/
}
pushValue(state, worldTable)
// Install Thing types as singleton sentinel values. As userdata, these will only compare if the values are exactly equal.
state.NewUserdata(uintptr(0))
state.SetField(-2, "Player")
state.NewUserdata(uintptr(0))
state.SetField(-2, "Place")
state.NewUserdata(uintptr(0))
state.SetField(-2, "Program")
state.NewUserdata(uintptr(0))
state.SetField(-2, "Action")
state.NewUserdata(uintptr(0))
state.SetField(-2, "Thing")
state.SetGlobal("world")
state.GetGlobal("table") // ( -- tblTable )
state.PushGoFunction(TableFormat)
state.SetField(-2, "format")
state.Pop(1) // ( tblTable -- )
log.Println("Finished installing world")
printStackTypes(state)
}