mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add addresscommand
This commit is contained in:
@@ -120,6 +120,38 @@ lcommand(lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
laddresscommand(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;
|
||||||
|
if (lua_gettop(L) == 2) {
|
||||||
|
parm = luaL_checkstring(L,2);
|
||||||
|
}
|
||||||
|
result = skynet_command(context, cmd, parm);
|
||||||
|
if (result && result[0] == ':') {
|
||||||
|
int i;
|
||||||
|
uint32_t addr = 0;
|
||||||
|
for (i=1;result[i];i++) {
|
||||||
|
int c = result[i];
|
||||||
|
if (c>='0' && c<='9') {
|
||||||
|
c = c - '0';
|
||||||
|
} else if (c>='a' && c<='f') {
|
||||||
|
c = c - 'a' + 10;
|
||||||
|
} else if (c>='A' && c<='F') {
|
||||||
|
c = c - 'A' + 10;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
addr = addr * 16 + c;
|
||||||
|
}
|
||||||
|
lua_pushinteger(L, addr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lintcommand(lua_State *L) {
|
lintcommand(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
@@ -356,6 +388,7 @@ luaopen_skynet_core(lua_State *L) {
|
|||||||
{ "redirect", lredirect },
|
{ "redirect", lredirect },
|
||||||
{ "command" , lcommand },
|
{ "command" , lcommand },
|
||||||
{ "intcommand", lintcommand },
|
{ "intcommand", lintcommand },
|
||||||
|
{ "addresscommand", laddresscommand },
|
||||||
{ "error", lerror },
|
{ "error", lerror },
|
||||||
{ "tostring", ltostring },
|
{ "tostring", ltostring },
|
||||||
{ "harbor", lharbor },
|
{ "harbor", lharbor },
|
||||||
|
|||||||
@@ -295,20 +295,12 @@ function skynet.wait(co)
|
|||||||
session_id_coroutine[session] = nil
|
session_id_coroutine[session] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local self_handle
|
|
||||||
function skynet.self()
|
function skynet.self()
|
||||||
if self_handle then
|
return c.addresscommand "REG"
|
||||||
return self_handle
|
|
||||||
end
|
|
||||||
self_handle = string_to_handle(c.command("REG"))
|
|
||||||
return self_handle
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.localname(name)
|
function skynet.localname(name)
|
||||||
local addr = c.command("QUERY", name)
|
return c.addresscommand("QUERY", name)
|
||||||
if addr then
|
|
||||||
return string_to_handle(addr)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
skynet.now = c.now
|
skynet.now = c.now
|
||||||
|
|||||||
Reference in New Issue
Block a user