add lua loader

This commit is contained in:
Cloud Wu
2014-04-29 19:59:04 +08:00
parent a4a21bd793
commit d16159c166
9 changed files with 105 additions and 161 deletions

43
service/datacenterd.lua Normal file
View 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)