Commit d48dfdc7 authored by Jack's avatar Jack
Browse files

added check for nil in del in api.lua, added glyphs for buttons made by single...

added check for nil in del in api.lua, added glyphs for buttons made by single ascii values both in lexer and in print function, relaxed some requirements on functions which now accept types different from the expected and produce default values
parent f93bd808
......@@ -42,13 +42,15 @@ end
-- check semantics
function del(t, v)
local found = false
for i = 1, #t do
if t[i] == v then
found = true
end
if found then
t[i] = t[i+1]
if t ~= nil then
local found = false
for i = 1, #t do
if t[i] == v then
found = true
end
if found then
t[i] = t[i+1]
end
end
end
end
......
......@@ -586,16 +586,42 @@ static int llex (LexState *ls, SemInfo *seminfo) {
} while (anyValid);
}
/*case 0x8B:
case 0x8B:
{
next(ls);
seminfo->i = 0;
return TK_INT;
}
case 0x91:
{
next(ls);
seminfo->i = 1;
return TK_INT;
}*/
}
case 0x94:
{
next(ls);
seminfo->i = 2;
return TK_INT;
}
case 0x83:
{
next(ls);
seminfo->i = 3;
return TK_INT;
}
case 0x8e:
{
next(ls);
seminfo->i = 4;
return TK_INT;
}
case 0x97:
{
next(ls);
seminfo->i = 5;
return TK_INT;
}
case EOZ: {
return TK_EOS;
......
......@@ -570,10 +570,13 @@ namespace math
int abs(lua_State* L)
{
assert(lua_isnumber(L, 1));
real_t v = lua_tonumber(L, 1);
lua_pushnumber(L, std::abs(v));
if (lua_isnumber(L, 1))
{
real_t v = lua_tonumber(L, 1);
lua_pushnumber(L, std::abs(v));
}
else
lua_pushnumber(L, 0);
return 1;
}
......@@ -599,6 +602,8 @@ namespace math
}
}
#define EXPECT_TYPE(tn, idx) do { if (!lua_is ## tn(L, idx)) std::cout << "expected " # tn << " but got " << lua_typename(L, idx) << std::endl; assert(false);} while (false)
namespace bitwise
{
using data_t = uint64_t;
......@@ -606,13 +611,16 @@ namespace bitwise
template<typename F>
int bitwise(lua_State* L)
{
assert(lua_isnumber(L, 1));
assert(lua_isnumber(L, 2));
if (lua_isnumber(L, 1) && lua_isnumber(L, 2))
{
data_t a = lua_tonumber(L, 1);
data_t b = lua_tonumber(L, 2);
data_t a = lua_tonumber(L, 1);
data_t b = lua_tonumber(L, 2);
lua_pushnumber(L, F()(a, b));
}
else
lua_pushnumber(L, 0);
lua_pushnumber(L, F()(a,b));
return 1;
}
......
......@@ -299,13 +299,16 @@ void Machine::print(const std::string& string, coord_t x, coord_t y, color_t col
size_t index;
};
static const std::array<SpecialGlyph, 6> SpecialGlyphs = { {
static const std::array<SpecialGlyph, 12> SpecialGlyphs = { {
{ { 0xe2, 0xac, 0x87, 0xef, 0xb8, 0x8f }, 3 }, // down arrow
{ { 0xe2, 0xac, 0x86, 0xef, 0xb8, 0x8f }, 20}, // up arrow
{ { 0xe2, 0xac, 0x85, 0xef, 0xb8, 0x8f }, 11}, // left arrow
{ { 0xe2, 0x9e, 0xa1, 0xef, 0xb8, 0x8f }, 17}, // right arrow
{ { 0xf0, 0x9f, 0x85, 0xbe, 0xef, 0xb8, 0x8f }, 14 }, // o button
{ { 0xe2, 0x9d, 0x8e }, 23 }, // x button
// 0x8b left, 0x91 right, 0x94 up, 0x83 down, 0x83 o, 0x97 x
{ { 0x8b }, 11 }, { { 0x91, }, 17 }, { { 0x94 }, 20 }, { { 0x83 }, 3 }, { { 0x8e }, 14 }, { { 0x97 }, 23 }
} };
static const std::array<uint8_t, 2> Prefixes = { 0xe2, 0xf0 };
......@@ -314,16 +317,13 @@ void Machine::print(const std::string& string, coord_t x, coord_t y, color_t col
{
auto c = string[i];
const bool isSpecial = std::find(Prefixes.begin(), Prefixes.end(), c) != Prefixes.end();
auto specialGlyph = std::find_if(SpecialGlyphs.begin(), SpecialGlyphs.end(), [&string, &i](const SpecialGlyph& glyph) {
return string.size() > i + glyph.encoding.size() && memcmp(&string[i], &glyph.encoding[0], glyph.encoding.size()) == 0; //TODO: memcpy is not best design ever
return string.size() >= i + glyph.encoding.size() && memcmp(&string[i], &glyph.encoding[0], glyph.encoding.size()) == 0; //TODO: memcmp is not best design ever
});
const gfx::sequential_sprite_t* sprite = nullptr;
coord_t width = gfx::GLYPH_WIDTH;
if (specialGlyph != SpecialGlyphs.end())
{
sprite = _font.specialGlyph(specialGlyph->index);
......
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