add addresscommand

This commit is contained in:
Cloud Wu
2018-04-14 20:30:47 +08:00
committed by 云风
parent eb8a2b5e65
commit a9852273cb
2 changed files with 35 additions and 10 deletions

View File

@@ -120,6 +120,38 @@ lcommand(lua_State *L) {
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
lintcommand(lua_State *L) {
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
@@ -356,6 +388,7 @@ luaopen_skynet_core(lua_State *L) {
{ "redirect", lredirect },
{ "command" , lcommand },
{ "intcommand", lintcommand },
{ "addresscommand", laddresscommand },
{ "error", lerror },
{ "tostring", ltostring },
{ "harbor", lharbor },

View File

@@ -295,20 +295,12 @@ function skynet.wait(co)
session_id_coroutine[session] = nil
end
local self_handle
function skynet.self()
if self_handle then
return self_handle
end
self_handle = string_to_handle(c.command("REG"))
return self_handle
return c.addresscommand "REG"
end
function skynet.localname(name)
local addr = c.command("QUERY", name)
if addr then
return string_to_handle(addr)
end
return c.addresscommand("QUERY", name)
end
skynet.now = c.now