add core.intcommand , See Issue #321

This commit is contained in:
Cloud Wu
2015-08-10 22:06:36 +08:00
parent 2935ba3521
commit 6fa436e8ff
2 changed files with 28 additions and 7 deletions

View File

@@ -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 },