Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
retro8
Commits
5a533a37
Commit
5a533a37
authored
Dec 23, 2019
by
Jack
Browse files
fix to break/goto in inline if, improved tostr, improved sub
parent
c0bb18d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lua/lparser.c
View file @
5a533a37
...
...
@@ -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 */
...
...
src/vm/lua_bridge.cpp
View file @
5a533a37
...
...
@@ -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"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment