mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 11:33:09 +00:00
add core.intcommand , See Issue #321
This commit is contained in:
@@ -118,6 +118,28 @@ _command(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_intcommand(lua_State *L) {
|
||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||
const char * cmd = luaL_checkstring(L,1);
|
||||
const char * result;
|
||||
const char * parm = NULL;
|
||||
char tmp[64]; // for integer parm
|
||||
if (lua_gettop(L) == 2) {
|
||||
int32_t n = (int32_t)luaL_checkinteger(L,2);
|
||||
sprintf(tmp, "%d", n);
|
||||
parm = tmp;
|
||||
}
|
||||
|
||||
result = skynet_command(context, cmd, parm);
|
||||
if (result) {
|
||||
lua_Integer r = strtoll(result, NULL, 0);
|
||||
lua_pushinteger(L, r);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_genid(lua_State *L) {
|
||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||
@@ -310,6 +332,7 @@ luaopen_skynet_core(lua_State *L) {
|
||||
{ "genid", _genid },
|
||||
{ "redirect", _redirect },
|
||||
{ "command" , _command },
|
||||
{ "intcommand", _intcommand },
|
||||
{ "error", _error },
|
||||
{ "tostring", _tostring },
|
||||
{ "harbor", _harbor },
|
||||
|
||||
@@ -248,18 +248,16 @@ function suspend(co, result, command, param, size)
|
||||
end
|
||||
|
||||
function skynet.timeout(ti, func)
|
||||
local session = c.command("TIMEOUT",tostring(ti))
|
||||
local session = c.intcommand("TIMEOUT",ti)
|
||||
assert(session)
|
||||
session = tonumber(session)
|
||||
local co = co_create(func)
|
||||
assert(session_id_coroutine[session] == nil)
|
||||
session_id_coroutine[session] = co
|
||||
end
|
||||
|
||||
function skynet.sleep(ti)
|
||||
local session = c.command("TIMEOUT",tostring(ti))
|
||||
local session = c.intcommand("TIMEOUT",ti)
|
||||
assert(session)
|
||||
session = tonumber(session)
|
||||
local succ, ret = coroutine_yield("SLEEP", session)
|
||||
sleep_session[coroutine.running()] = nil
|
||||
if succ then
|
||||
@@ -301,11 +299,11 @@ function skynet.localname(name)
|
||||
end
|
||||
|
||||
function skynet.now()
|
||||
return tonumber(c.command("NOW"))
|
||||
return c.intcommand("NOW")
|
||||
end
|
||||
|
||||
function skynet.starttime()
|
||||
return tonumber(c.command("STARTTIME"))
|
||||
return c.intcommand("STARTTIME")
|
||||
end
|
||||
|
||||
function skynet.time()
|
||||
@@ -643,7 +641,7 @@ function skynet.endless()
|
||||
end
|
||||
|
||||
function skynet.mqlen()
|
||||
return tonumber(c.command "MQLEN")
|
||||
return c.intcommand "MQLEN"
|
||||
end
|
||||
|
||||
function skynet.task(ret)
|
||||
|
||||
Reference in New Issue
Block a user