mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
add addresscommand
This commit is contained in:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user