本文整理汇总了Golang中github.com/xyproto/pinterface.IUserState.Creator方法的典型用法代码示例。如果您正苦于以下问题:Golang IUserState.Creator方法的具体用法?Golang IUserState.Creator怎么用?Golang IUserState.Creator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xyproto/pinterface.IUserState
的用法示例。
在下文中一共展示了IUserState.Creator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: exportCodeLibrary
// Make functions related to building a library of Lua code available
func exportCodeLibrary(L *lua.LState, userstate pinterface.IUserState) {
creator := userstate.Creator()
// Register the Library class and the methods that belongs with it.
mt := L.NewTypeMetatable(lLibraryClass)
mt.RawSetH(lua.LString("__index"), mt)
L.SetFuncs(mt, libMethods)
// The constructor for new Libraries takes only an optional id
L.SetGlobal("CodeLib", L.NewFunction(func(L *lua.LState) int {
// Check if the optional argument is given
id := defaultID
if L.GetTop() == 1 {
id = L.ToString(1)
}
// Create a new Library in Lua
userdata, err := newCodeLibrary(L, creator, id)
if err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
L.Push(lua.LNumber(1))
return 3 // Number of returned values
}
// Return the hash map object
L.Push(userdata)
return 1 // number of results
}))
}
示例2: NewUsersHole
func NewUsersHole(state pinterface.IUserState) *UsersHole {
uh := new(UsersHole)
creator := state.Creator()
uh.state = state
uh.holes, _ = creator.NewHashMap("holes")
uh.seq, _ = creator.NewKeyValue("seq")
uh.servers = make(map[string]*HoleApp)
return uh
}
示例3: exportList
// Make functions related to HTTP requests and responses available to Lua scripts
func exportList(L *lua.LState, userstate pinterface.IUserState) {
creator := userstate.Creator()
// Register the list class and the methods that belongs with it.
mt := L.NewTypeMetatable(lListClass)
mt.RawSetH(lua.LString("__index"), mt)
L.SetFuncs(mt, listMethods)
// The constructor for new lists takes a name and an optional redis db index
L.SetGlobal("List", L.NewFunction(func(L *lua.LState) int {
name := L.ToString(1)
// Check if the optional argument is given
if L.GetTop() == 2 {
localDBIndex := L.ToInt(2)
// Set the DB index, if possible
switch rh := creator.(type) {
case pinterface.IRedisCreator:
rh.SelectDatabase(localDBIndex)
}
}
// Create a new list in Lua
userdata, err := newList(L, creator, name)
if err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
L.Push(lua.LNumber(1))
return 3 // Number of returned values
}
// Return the list object
L.Push(userdata)
return 1 // Number of returned values
}))
}