Commit 5a533a37 authored by Jack's avatar Jack
Browse files

fix to break/goto in inline if, improved tostr, improved sub

parent c0bb18d0
......@@ -1442,12 +1442,23 @@ static void inline_if(LexState* ls, expdesc* v)
FuncState* fs = ls->fs;
int jf;
if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK)
luaX_syntaxerror(ls, luaO_pushfstring(ls->L, "unsupported goto or break in inline if"));
luaK_goiftrue(ls->fs, v); /* skip over block if condition is false */
enterblock(fs, &bl, 0);
jf = v->f;
if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
luaK_goiffalse(ls->fs, v); /* will jump to label if condition is true */
enterblock(fs, &bl, 0); /* must enter block before 'goto' */
gotostat(ls, v->t); /* handle goto/break */
while (testnext(ls, ';')) {} /* skip colons */
if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
leaveblock(fs);
return 0; /* and that is it */
}
else /* must skip over 'then' part if condition is false */
jf = luaK_jump(fs);
}
else { /* regular case (not goto/break) */
luaK_goiftrue(ls->fs, v); /* skip over block if condition is false */
enterblock(fs, &bl, 0);
jf = v->f;
}
ls->ignorenewline = 0;
statlist(ls); /* parse true block */
......
......@@ -677,8 +677,17 @@ namespace string
if (e < 0)
e = v.length() - e + 1;
assert(s <= e);
lua_pushstring(L, v.substr(s - 1, e - s + 1).c_str());
// TODO: intended behavior? picotetris calls it with swapped indices
if (e < s)
lua_pushstring(L, "");
else
{
if (s == 0)
s = 1;
lua_pushstring(L, v.substr(s - 1, e - s + 1).c_str());
}
return 1;
}
......@@ -686,10 +695,19 @@ namespace string
int tostr(lua_State* L)
{
//TODO implement
static char buffer[20];
switch (lua_type(L, 1))
{
case LUA_TBOOLEAN: lua_pushstring(L, lua_toboolean(L, 1) ? "true" : "false"); break;
case LUA_TNUMBER:
{
snprintf(buffer, 20, "% 4.4f", lua_tonumber(L, 1));
lua_pushstring(L, buffer);
break;
}
case LUA_TSTRING: lua_pushstring(L, lua_tostring(L, 1)); break;
default: lua_pushstring(L, "foo");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment