示例#1
0
// Create a new KeyValue collection.
// id is the name of the KeyValue colleciton.
// dbindex is the Redis database index (typically 0).
func newKeyValue(L *lua.LState, creator pinterface.ICreator, id string) (*lua.LUserData, error) {
	// Create a new key/value
	kv, err := creator.NewKeyValue(id)
	if err != nil {
		return nil, err
	}
	// Create a new userdata struct
	ud := L.NewUserData()
	ud.Value = kv
	L.SetMetatable(ud, L.GetTypeMetatable(lKeyValueClass))
	return ud, nil
}
示例#2
0
// Create a new code library.
// id is the name of the hash map.
func newCodeLibrary(L *lua.LState, creator pinterface.ICreator, id string) (*lua.LUserData, error) {
	// Create a new Lua Library (hash map)
	lualib, err := creator.NewKeyValue(id)
	if err != nil {
		return nil, err
	}
	// Create a new userdata struct
	ud := L.NewUserData()
	ud.Value = lualib
	L.SetMetatable(ud, L.GetTypeMetatable(lLibraryClass))
	return ud, nil
}