mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
sproto.default returns array type
This commit is contained in:
@@ -621,31 +621,49 @@ lloadproto(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
push_default(const struct sproto_arg *args, int array) {
|
||||||
|
lua_State *L = args->ud;
|
||||||
|
switch(args->type) {
|
||||||
|
case SPROTO_TINTEGER:
|
||||||
|
if (args->extra)
|
||||||
|
lua_pushnumber(L, 0.0);
|
||||||
|
else
|
||||||
|
lua_pushinteger(L, 0);
|
||||||
|
break;
|
||||||
|
case SPROTO_TBOOLEAN:
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
break;
|
||||||
|
case SPROTO_TSTRING:
|
||||||
|
lua_pushliteral(L, "");
|
||||||
|
break;
|
||||||
|
case SPROTO_TSTRUCT:
|
||||||
|
if (array) {
|
||||||
|
lua_pushstring(L, sproto_name(args->subtype));
|
||||||
|
} else {
|
||||||
|
lua_createtable(L, 0, 1);
|
||||||
|
lua_pushstring(L, sproto_name(args->subtype));
|
||||||
|
lua_setfield(L, -2, "__type");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
luaL_error(L, "Invalid type %d", args->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
encode_default(const struct sproto_arg *args) {
|
encode_default(const struct sproto_arg *args) {
|
||||||
lua_State *L = args->ud;
|
lua_State *L = args->ud;
|
||||||
lua_pushstring(L, args->tagname);
|
lua_pushstring(L, args->tagname);
|
||||||
if (args->index > 0) {
|
if (args->index > 0) {
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
push_default(args, 1);
|
||||||
|
lua_setfield(L, -2, "__array");
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
return SPROTO_CB_NOARRAY;
|
return SPROTO_CB_NOARRAY;
|
||||||
} else {
|
} else {
|
||||||
switch(args->type) {
|
push_default(args, 0);
|
||||||
case SPROTO_TINTEGER:
|
|
||||||
lua_pushinteger(L, 0);
|
|
||||||
break;
|
|
||||||
case SPROTO_TBOOLEAN:
|
|
||||||
lua_pushboolean(L, 0);
|
|
||||||
break;
|
|
||||||
case SPROTO_TSTRING:
|
|
||||||
lua_pushliteral(L, "");
|
|
||||||
break;
|
|
||||||
case SPROTO_TSTRUCT:
|
|
||||||
lua_createtable(L, 0, 1);
|
|
||||||
lua_pushstring(L, sproto_name(args->subtype));
|
|
||||||
lua_setfield(L, -2, "__type");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
return SPROTO_CB_NIL;
|
return SPROTO_CB_NIL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user