mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
Redesign harbor/master/dummy service
This commit is contained in:
@@ -581,8 +581,16 @@ _luaseri_unpack(lua_State *L) {
|
||||
if (lua_isnoneornil(L,1)) {
|
||||
return 0;
|
||||
}
|
||||
void * buffer = lua_touserdata(L,1);
|
||||
int len = luaL_checkinteger(L,2);
|
||||
void * buffer;
|
||||
int len;
|
||||
if (lua_type(L,1) == LUA_TSTRING) {
|
||||
size_t sz;
|
||||
buffer = (void *)lua_tolstring(L,1,&sz);
|
||||
len = (int)sz;
|
||||
} else {
|
||||
buffer = lua_touserdata(L,1);
|
||||
len = luaL_checkinteger(L,2);
|
||||
}
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -289,6 +289,16 @@ _harbor(lua_State *L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int
|
||||
lpackstring(lua_State *L) {
|
||||
_luaseri_pack(L);
|
||||
char * str = (char *)lua_touserdata(L, -2);
|
||||
int sz = lua_tointeger(L, -1);
|
||||
lua_pushlstring(L, str, sz);
|
||||
skynet_free(str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
luaopen_skynet_c(lua_State *L) {
|
||||
luaL_checkversion(L);
|
||||
@@ -303,6 +313,7 @@ luaopen_skynet_c(lua_State *L) {
|
||||
{ "harbor", _harbor },
|
||||
{ "pack", _luaseri_pack },
|
||||
{ "unpack", _luaseri_unpack },
|
||||
{ "packstring", lpackstring },
|
||||
{ "callback", _callback },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user