Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #52 from jjensen/support-unsigned-static-const
Browse files Browse the repository at this point in the history
Support 8-, 16-, and 32-bit numeric types when parsing static const valu...
  • Loading branch information
jmckaskill committed May 4, 2013
2 parents cf56462 + 0b0f2ee commit bafef34
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2074,12 +2074,15 @@ static int parse_root(lua_State* L, struct parser* P)
parse_typedef(L, P);

} else if (IS_LITERAL(tok, "static")) {
struct ctype at;

int64_t val;
require_token(L, P, &tok);
if (!IS_CONST(tok)) {
luaL_error(L, "expected 'static const int' on line %d", P->line);
}
check_token(L, P, TOK_TOKEN, "int", "expected 'static const int' on line %d", P->line);

parse_type(L, P, &at);

require_token(L, P, &tok);
if (tok.type != TOK_TOKEN) {
Expand All @@ -2094,7 +2097,21 @@ static int parse_root(lua_State* L, struct parser* P)

push_upval(L, &constants_key);
lua_pushlstring(L, tok.str, tok.size);
lua_pushnumber(L, (int) val);

switch (at.type) {
case INT8_TYPE:
case INT16_TYPE:
case INT32_TYPE:
if (at.is_unsigned)
lua_pushnumber(L, (unsigned int) val);
else
lua_pushnumber(L, (int) val);
break;

default:
luaL_error(L, "expected a valid 8-, 16-, or 32-bit signed or unsigned integer type after 'static const' on line %d", P->line);
}

lua_rawset(L, -3);
lua_pop(L, 1); /*constants*/

Expand Down

0 comments on commit bafef34

Please sign in to comment.