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
|
local max_client = 64
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
print("Server start")
|
skynet.error("Server start")
|
||||||
skynet.uniqueservice("protoloader")
|
skynet.uniqueservice("protoloader")
|
||||||
local console = skynet.newservice("console")
|
local console = skynet.newservice("console")
|
||||||
skynet.newservice("debug_console",8000)
|
skynet.newservice("debug_console",8000)
|
||||||
@@ -15,7 +15,6 @@ skynet.start(function()
|
|||||||
maxclient = max_client,
|
maxclient = max_client,
|
||||||
nodelay = true,
|
nodelay = true,
|
||||||
})
|
})
|
||||||
print("Watchdog listen on ", 8888)
|
skynet.error("Watchdog listen on", 8888)
|
||||||
|
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -551,7 +551,7 @@ seri(lua_State *L, struct block *b, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_luaseri_unpack(lua_State *L) {
|
luaseri_unpack(lua_State *L) {
|
||||||
if (lua_isnoneornil(L,1)) {
|
if (lua_isnoneornil(L,1)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -595,7 +595,7 @@ _luaseri_unpack(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_luaseri_pack(lua_State *L) {
|
luaseri_pack(lua_State *L) {
|
||||||
struct block temp;
|
struct block temp;
|
||||||
temp.next = NULL;
|
temp.next = NULL;
|
||||||
struct write_block wb;
|
struct write_block wb;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
int _luaseri_pack(lua_State *L);
|
int luaseri_pack(lua_State *L);
|
||||||
int _luaseri_unpack(lua_State *L);
|
int luaseri_unpack(lua_State *L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ forward_cb(struct skynet_context * context, void * ud, int type, int session, ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_callback(lua_State *L) {
|
lcallback(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
int forward = lua_toboolean(L, 2);
|
int forward = lua_toboolean(L, 2);
|
||||||
luaL_checktype(L,1,LUA_TFUNCTION);
|
luaL_checktype(L,1,LUA_TFUNCTION);
|
||||||
@@ -101,7 +101,7 @@ _callback(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_command(lua_State *L) {
|
lcommand(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
const char * cmd = luaL_checkstring(L,1);
|
const char * cmd = luaL_checkstring(L,1);
|
||||||
const char * result;
|
const char * result;
|
||||||
@@ -119,7 +119,7 @@ _command(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_intcommand(lua_State *L) {
|
lintcommand(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
const char * cmd = luaL_checkstring(L,1);
|
const char * cmd = luaL_checkstring(L,1);
|
||||||
const char * result;
|
const char * result;
|
||||||
@@ -141,7 +141,7 @@ _intcommand(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_genid(lua_State *L) {
|
lgenid(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
int session = skynet_send(context, 0, 0, PTYPE_TAG_ALLOCSESSION , 0 , NULL, 0);
|
int session = skynet_send(context, 0, 0, PTYPE_TAG_ALLOCSESSION , 0 , NULL, 0);
|
||||||
lua_pushinteger(L, session);
|
lua_pushinteger(L, session);
|
||||||
@@ -167,7 +167,7 @@ get_dest_string(lua_State *L, int index) {
|
|||||||
integer len
|
integer len
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
_send(lua_State *L) {
|
lsend(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
uint32_t dest = (uint32_t)lua_tointeger(L, 1);
|
uint32_t dest = (uint32_t)lua_tointeger(L, 1);
|
||||||
const char * dest_string = NULL;
|
const char * dest_string = NULL;
|
||||||
@@ -224,7 +224,7 @@ _send(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_redirect(lua_State *L) {
|
lredirect(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
uint32_t dest = (uint32_t)lua_tointeger(L,1);
|
uint32_t dest = (uint32_t)lua_tointeger(L,1);
|
||||||
const char * dest_string = NULL;
|
const char * dest_string = NULL;
|
||||||
@@ -267,14 +267,32 @@ _redirect(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_error(lua_State *L) {
|
lerror(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_tostring(lua_State *L) {
|
ltostring(lua_State *L) {
|
||||||
if (lua_isnoneornil(L,1)) {
|
if (lua_isnoneornil(L,1)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -285,7 +303,7 @@ _tostring(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_harbor(lua_State *L) {
|
lharbor(lua_State *L) {
|
||||||
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1));
|
||||||
uint32_t handle = (uint32_t)luaL_checkinteger(L,1);
|
uint32_t handle = (uint32_t)luaL_checkinteger(L,1);
|
||||||
int harbor = 0;
|
int harbor = 0;
|
||||||
@@ -298,7 +316,7 @@ _harbor(lua_State *L) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lpackstring(lua_State *L) {
|
lpackstring(lua_State *L) {
|
||||||
_luaseri_pack(L);
|
luaseri_pack(L);
|
||||||
char * str = (char *)lua_touserdata(L, -2);
|
char * str = (char *)lua_touserdata(L, -2);
|
||||||
int sz = lua_tointeger(L, -1);
|
int sz = lua_tointeger(L, -1);
|
||||||
lua_pushlstring(L, str, sz);
|
lua_pushlstring(L, str, sz);
|
||||||
@@ -338,19 +356,19 @@ luaopen_skynet_core(lua_State *L) {
|
|||||||
luaL_checkversion(L);
|
luaL_checkversion(L);
|
||||||
|
|
||||||
luaL_Reg l[] = {
|
luaL_Reg l[] = {
|
||||||
{ "send" , _send },
|
{ "send" , lsend },
|
||||||
{ "genid", _genid },
|
{ "genid", lgenid },
|
||||||
{ "redirect", _redirect },
|
{ "redirect", lredirect },
|
||||||
{ "command" , _command },
|
{ "command" , lcommand },
|
||||||
{ "intcommand", _intcommand },
|
{ "intcommand", lintcommand },
|
||||||
{ "error", _error },
|
{ "error", lerror },
|
||||||
{ "tostring", _tostring },
|
{ "tostring", ltostring },
|
||||||
{ "harbor", _harbor },
|
{ "harbor", lharbor },
|
||||||
{ "pack", _luaseri_pack },
|
{ "pack", luaseri_pack },
|
||||||
{ "unpack", _luaseri_unpack },
|
{ "unpack", luaseri_unpack },
|
||||||
{ "packstring", lpackstring },
|
{ "packstring", lpackstring },
|
||||||
{ "trash" , ltrash },
|
{ "trash" , ltrash },
|
||||||
{ "callback", _callback },
|
{ "callback", lcallback },
|
||||||
{ "now", lnow },
|
{ "now", lnow },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -548,13 +548,7 @@ function skynet.harbor(addr)
|
|||||||
return c.harbor(addr)
|
return c.harbor(addr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.error(...)
|
skynet.error = c.error
|
||||||
local t = {...}
|
|
||||||
for i=1,#t do
|
|
||||||
t[i] = tostring(t[i])
|
|
||||||
end
|
|
||||||
return c.error(table.concat(t, " "))
|
|
||||||
end
|
|
||||||
|
|
||||||
----- register protocol
|
----- register protocol
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user