From a6299a0748215ed26dfa61682eab747564b6595b Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Fri, 6 May 2016 20:10:11 +0800 Subject: [PATCH] optimize skynet.error --- examples/main.lua | 5 ++-- lualib-src/lua-seri.c | 4 +-- lualib-src/lua-seri.h | 4 +-- lualib-src/lua-skynet.c | 62 ++++++++++++++++++++++++++--------------- lualib/skynet.lua | 8 +----- 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/examples/main.lua b/examples/main.lua index 9da707d4..cac49737 100644 --- a/examples/main.lua +++ b/examples/main.lua @@ -4,7 +4,7 @@ local sprotoloader = require "sprotoloader" local max_client = 64 skynet.start(function() - print("Server start") + skynet.error("Server start") skynet.uniqueservice("protoloader") local console = skynet.newservice("console") skynet.newservice("debug_console",8000) @@ -15,7 +15,6 @@ skynet.start(function() maxclient = max_client, nodelay = true, }) - print("Watchdog listen on ", 8888) - + skynet.error("Watchdog listen on", 8888) skynet.exit() end) diff --git a/lualib-src/lua-seri.c b/lualib-src/lua-seri.c index d80452b6..28056f74 100644 --- a/lualib-src/lua-seri.c +++ b/lualib-src/lua-seri.c @@ -551,7 +551,7 @@ seri(lua_State *L, struct block *b, int len) { } int -_luaseri_unpack(lua_State *L) { +luaseri_unpack(lua_State *L) { if (lua_isnoneornil(L,1)) { return 0; } @@ -595,7 +595,7 @@ _luaseri_unpack(lua_State *L) { } int -_luaseri_pack(lua_State *L) { +luaseri_pack(lua_State *L) { struct block temp; temp.next = NULL; struct write_block wb; diff --git a/lualib-src/lua-seri.h b/lualib-src/lua-seri.h index 23eb4cf9..6102239e 100644 --- a/lualib-src/lua-seri.h +++ b/lualib-src/lua-seri.h @@ -3,7 +3,7 @@ #include -int _luaseri_pack(lua_State *L); -int _luaseri_unpack(lua_State *L); +int luaseri_pack(lua_State *L); +int luaseri_unpack(lua_State *L); #endif diff --git a/lualib-src/lua-skynet.c b/lualib-src/lua-skynet.c index 063320a4..2422f413 100644 --- a/lualib-src/lua-skynet.c +++ b/lualib-src/lua-skynet.c @@ -81,7 +81,7 @@ forward_cb(struct skynet_context * context, void * ud, int type, int session, ui } static int -_callback(lua_State *L) { +lcallback(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); int forward = lua_toboolean(L, 2); luaL_checktype(L,1,LUA_TFUNCTION); @@ -101,7 +101,7 @@ _callback(lua_State *L) { } static int -_command(lua_State *L) { +lcommand(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); const char * cmd = luaL_checkstring(L,1); const char * result; @@ -119,7 +119,7 @@ _command(lua_State *L) { } static int -_intcommand(lua_State *L) { +lintcommand(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); const char * cmd = luaL_checkstring(L,1); const char * result; @@ -141,7 +141,7 @@ _intcommand(lua_State *L) { } static int -_genid(lua_State *L) { +lgenid(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); int session = skynet_send(context, 0, 0, PTYPE_TAG_ALLOCSESSION , 0 , NULL, 0); lua_pushinteger(L, session); @@ -167,7 +167,7 @@ get_dest_string(lua_State *L, int index) { integer len */ static int -_send(lua_State *L) { +lsend(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); uint32_t dest = (uint32_t)lua_tointeger(L, 1); const char * dest_string = NULL; @@ -224,7 +224,7 @@ _send(lua_State *L) { } static int -_redirect(lua_State *L) { +lredirect(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); uint32_t dest = (uint32_t)lua_tointeger(L,1); const char * dest_string = NULL; @@ -267,14 +267,32 @@ _redirect(lua_State *L) { } static int -_error(lua_State *L) { +lerror(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); - skynet_error(context, "%s", luaL_checkstring(L,1)); + int n = lua_gettop(L); + if (n <= 1) { + lua_settop(L, 1); + const char * s = luaL_tolstring(L, 1, NULL); + skynet_error(context, "%s", s); + return 0; + } + luaL_Buffer b; + luaL_buffinit(L, &b); + int i; + for (i=1; i<=n; i++) { + luaL_tolstring(L, i, NULL); + luaL_addvalue(&b); + if (i