Skip to content

Commit

Permalink
more type check
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Apr 1, 2015
1 parent 41b447d commit 6b87f15
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lualib-src/sproto/lsproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ encode(const struct sproto_arg *args) {
return 0;
}
if (!lua_istable(L, -1)) {
return luaL_error(L, "%s is not a table", args->tagname);
return luaL_error(L, ".*%s(%d) should be a table (Is a %s)",
args->tagname, args->index, lua_typename(L, lua_type(L, -1)));
}
if (self->array_index) {
lua_replace(L, self->array_index);
Expand Down Expand Up @@ -177,6 +178,10 @@ encode(const struct sproto_arg *args) {
}
case SPROTO_TBOOLEAN: {
int v = lua_toboolean(L, -1);
if (!lua_isboolean(L,-1)) {
return luaL_error(L, ".%s[%d] is not a boolean (Is a %s)",
args->tagname, args->index, lua_typename(L, lua_type(L, -1)));
}
*(int *)args->value = v;
lua_pop(L,1);
return 4;
Expand All @@ -200,9 +205,13 @@ encode(const struct sproto_arg *args) {
struct encode_ud sub;
int r;
int top = lua_gettop(L);
if (!lua_istable(L, top)) {
return luaL_error(L, ".%s[%d] is not a table (Is a %s)",
args->tagname, args->index, lua_typename(L, lua_type(L, -1)));
}
sub.L = L;
sub.st = args->subtype;
sub.tbl_index = lua_gettop(L);
sub.tbl_index = top;
sub.array_tag = NULL;
sub.array_index = 0;
sub.deep = self->deep + 1;
Expand Down

0 comments on commit 6b87f15

Please sign in to comment.