mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add core.intcommand , See Issue #321
This commit is contained in:
@@ -118,6 +118,28 @@ _command(lua_State *L) {
|
|||||||
return 0;
|
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
|
static int
|
||||||
_genid(lua_State *L) {
|
_genid(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
@@ -310,6 +332,7 @@ luaopen_skynet_core(lua_State *L) {
|
|||||||
{ "genid", _genid },
|
{ "genid", _genid },
|
||||||
{ "redirect", _redirect },
|
{ "redirect", _redirect },
|
||||||
{ "command" , _command },
|
{ "command" , _command },
|
||||||
|
{ "intcommand", _intcommand },
|
||||||
{ "error", _error },
|
{ "error", _error },
|
||||||
{ "tostring", _tostring },
|
{ "tostring", _tostring },
|
||||||
{ "harbor", _harbor },
|
{ "harbor", _harbor },
|
||||||
|
|||||||
@@ -248,18 +248,16 @@ function suspend(co, result, command, param, size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.timeout(ti, func)
|
function skynet.timeout(ti, func)
|
||||||
local session = c.command("TIMEOUT",tostring(ti))
|
local session = c.intcommand("TIMEOUT",ti)
|
||||||
assert(session)
|
assert(session)
|
||||||
session = tonumber(session)
|
|
||||||
local co = co_create(func)
|
local co = co_create(func)
|
||||||
assert(session_id_coroutine[session] == nil)
|
assert(session_id_coroutine[session] == nil)
|
||||||
session_id_coroutine[session] = co
|
session_id_coroutine[session] = co
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.sleep(ti)
|
function skynet.sleep(ti)
|
||||||
local session = c.command("TIMEOUT",tostring(ti))
|
local session = c.intcommand("TIMEOUT",ti)
|
||||||
assert(session)
|
assert(session)
|
||||||
session = tonumber(session)
|
|
||||||
local succ, ret = coroutine_yield("SLEEP", session)
|
local succ, ret = coroutine_yield("SLEEP", session)
|
||||||
sleep_session[coroutine.running()] = nil
|
sleep_session[coroutine.running()] = nil
|
||||||
if succ then
|
if succ then
|
||||||
@@ -301,11 +299,11 @@ function skynet.localname(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.now()
|
function skynet.now()
|
||||||
return tonumber(c.command("NOW"))
|
return c.intcommand("NOW")
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.starttime()
|
function skynet.starttime()
|
||||||
return tonumber(c.command("STARTTIME"))
|
return c.intcommand("STARTTIME")
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.time()
|
function skynet.time()
|
||||||
@@ -643,7 +641,7 @@ function skynet.endless()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.mqlen()
|
function skynet.mqlen()
|
||||||
return tonumber(c.command "MQLEN")
|
return c.intcommand "MQLEN"
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.task(ret)
|
function skynet.task(ret)
|
||||||
|
|||||||
Reference in New Issue
Block a user