Commit 3949ecb0 authored by Jack's avatar Jack
Browse files

added support for binary literals to Lua

parent e7d4cee5
......@@ -54,7 +54,7 @@ private:
#define MOUSE_ENABLED true
#define WINDOW_SCALE 1
#define DEBUGGER true
#define TEST_MODE false
#define TEST_MODE true
#else
#define MOUSE_ENABLED false
#endif
\ No newline at end of file
......@@ -243,7 +243,6 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) {
}
}
/*
** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return
** its number of '='s; otherwise, return a negative number (-1 iff there
......
......@@ -310,6 +310,13 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
empty = 0;
}
}
else if (s[0] == '0' && (s[1] == 'b' || s[1] == 'B')) { /* binary */
s += 2;
for (; *s == '0' || *s == '1'; s++) {
a = a * 2 + (*s == '0' ? 0 : 1);
empty = 0;
}
}
else { /* decimal */
for (; lisdigit(cast_uchar(*s)); s++) {
int d = *s - '0';
......
......@@ -72,6 +72,36 @@ TEST_CASE("lua language modifications")
}
SECTION("binary literals")
{
std::string literal;
int expected = 0;
SECTION("0b1")
{
literal = "0b1";
expected = 0b1;
}
SECTION("0b100")
{
literal = "0b100";
expected = 0b100;
}
SECTION("0b000")
{
literal = "0b000";
expected = 0b000;
}
const std::string code = "x = " + literal + "; return x";
REQUIRE(luaL_loadstring(L, code.c_str()) == 0);
REQUIRE(lua_pcall(L, 0, 1, 0) == 0);
REQUIRE(lua_tonumber(L, -1) == expected);
}
lua_close(L);
}
......
......@@ -100,7 +100,7 @@ void GameView::render()
machine.code().loadAPI();
retro8::io::LoaderP8 loader;
std::string path = !_path.empty() ? _path : "test.p8";
std::string path = !_path.empty() ? _path : "pico_physics.p8";
loader.load(path, machine);
manager->setFrameRate(machine.code().require60fps() ? 60 : 30);
......
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