mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
optimize skynet.error
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <lua.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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<n) {
|
||||
luaL_addchar(&b, ' ');
|
||||
}
|
||||
}
|
||||
luaL_pushresult(&b);
|
||||
skynet_error(context, "%s", lua_tostring(L, -1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_tostring(lua_State *L) {
|
||||
ltostring(lua_State *L) {
|
||||
if (lua_isnoneornil(L,1)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -285,7 +303,7 @@ _tostring(lua_State *L) {
|
||||
}
|
||||
|
||||
static int
|
||||
_harbor(lua_State *L) {
|
||||
lharbor(lua_State *L) {
|
||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||
uint32_t handle = (uint32_t)luaL_checkinteger(L,1);
|
||||
int harbor = 0;
|
||||
@@ -298,7 +316,7 @@ _harbor(lua_State *L) {
|
||||
|
||||
static int
|
||||
lpackstring(lua_State *L) {
|
||||
_luaseri_pack(L);
|
||||
luaseri_pack(L);
|
||||
char * str = (char *)lua_touserdata(L, -2);
|
||||
int sz = lua_tointeger(L, -1);
|
||||
lua_pushlstring(L, str, sz);
|
||||
@@ -338,19 +356,19 @@ luaopen_skynet_core(lua_State *L) {
|
||||
luaL_checkversion(L);
|
||||
|
||||
luaL_Reg l[] = {
|
||||
{ "send" , _send },
|
||||
{ "genid", _genid },
|
||||
{ "redirect", _redirect },
|
||||
{ "command" , _command },
|
||||
{ "intcommand", _intcommand },
|
||||
{ "error", _error },
|
||||
{ "tostring", _tostring },
|
||||
{ "harbor", _harbor },
|
||||
{ "pack", _luaseri_pack },
|
||||
{ "unpack", _luaseri_unpack },
|
||||
{ "send" , lsend },
|
||||
{ "genid", lgenid },
|
||||
{ "redirect", lredirect },
|
||||
{ "command" , lcommand },
|
||||
{ "intcommand", lintcommand },
|
||||
{ "error", lerror },
|
||||
{ "tostring", ltostring },
|
||||
{ "harbor", lharbor },
|
||||
{ "pack", luaseri_pack },
|
||||
{ "unpack", luaseri_unpack },
|
||||
{ "packstring", lpackstring },
|
||||
{ "trash" , ltrash },
|
||||
{ "callback", _callback },
|
||||
{ "callback", lcallback },
|
||||
{ "now", lnow },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
@@ -548,13 +548,7 @@ function skynet.harbor(addr)
|
||||
return c.harbor(addr)
|
||||
end
|
||||
|
||||
function skynet.error(...)
|
||||
local t = {...}
|
||||
for i=1,#t do
|
||||
t[i] = tostring(t[i])
|
||||
end
|
||||
return c.error(table.concat(t, " "))
|
||||
end
|
||||
skynet.error = c.error
|
||||
|
||||
----- register protocol
|
||||
do
|
||||
|
||||
Reference in New Issue
Block a user