Skip to content

Commit

Permalink
sproto.default can return array type
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Sep 1, 2017
1 parent 10613b7 commit 13f1623
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lsproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,36 @@ encode_default(const struct sproto_arg *args) {
lua_pushstring(L, args->tagname);
if (args->index > 0) {
lua_newtable(L);
if (args->subtype) {
lua_pushstring(L, sproto_name(args->subtype));
} else {
const char * typename = NULL;
switch(args->type) {
case SPROTO_TINTEGER:
typename = (args->extra) ? "decimal" : "integer";
break;
case SPROTO_TBOOLEAN:
typename = "boolean";
break;
case SPROTO_TSTRING:
typename = (args->extra) ? "binary" : "string";
break;
default:
typename = "unknown";
break;
}
lua_pushstring(L, typename);
}
lua_setfield(L, -2, "__array");
lua_rawset(L, -3);
return SPROTO_CB_NOARRAY;
} else {
switch(args->type) {
case SPROTO_TINTEGER:
lua_pushinteger(L, 0);
if (args->extra)
lua_pushnumber(L, 0.0);
else
lua_pushinteger(L, 0);
break;
case SPROTO_TBOOLEAN:
lua_pushboolean(L, 0);
Expand Down

0 comments on commit 13f1623

Please sign in to comment.