mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 19:43:09 +00:00
add lua loader
This commit is contained in:
43
service/datacenterd.lua
Normal file
43
service/datacenterd.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
local command = {}
|
||||
local database = {}
|
||||
|
||||
local function query(db, key, ...)
|
||||
if key == nil then
|
||||
return db
|
||||
else
|
||||
return query(db[key], ...)
|
||||
end
|
||||
end
|
||||
|
||||
function command.QUERY(key, ...)
|
||||
local d = database[key]
|
||||
if d then
|
||||
return query(d, ...)
|
||||
end
|
||||
end
|
||||
|
||||
local function update(db, key, value, ...)
|
||||
if select("#",...) == 0 then
|
||||
local ret = db[key]
|
||||
db[key] = value
|
||||
return ret
|
||||
else
|
||||
if db[key] == nil then
|
||||
db[key] = {}
|
||||
end
|
||||
return update(db[key], value, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function command.UPDATE(...)
|
||||
return update(database, ...)
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", function (_, source, cmd, ...)
|
||||
local f = assert(command[cmd])
|
||||
skynet.ret(skynet.pack(f(source, ...)))
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user