当前位置: 首页>>代码示例>>Golang>>正文


Golang IUserState.Creator方法代码示例

本文整理汇总了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
	}))

}
开发者ID:sneakyweasel,项目名称:algernon,代码行数:32,代码来源:codelib.go

示例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
}
开发者ID:ultimate010,项目名称:holehub,代码行数:9,代码来源:holehubd.go

示例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
	}))

}
开发者ID:sneakyweasel,项目名称:algernon,代码行数:39,代码来源:list.go


注:本文中的github.com/xyproto/pinterface.IUserState.Creator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。