lua: TDD of enabling base lib

This commit is contained in:
rusefillc 2022-02-22 16:22:09 -05:00
parent d9772657a7
commit ec97bf2cb5
2 changed files with 20 additions and 2 deletions

View File

@ -140,8 +140,7 @@ static int lua_setTickRate(lua_State* l) {
static void loadLibraries(LuaHandle& ls) {
constexpr luaL_Reg libs[] = {
// TODO: do we even need the base lib?
//{ LUA_GNAME, luaopen_base },
{ LUA_GNAME, luaopen_base },
{ LUA_MATHLIBNAME, luaopen_math },
};

View File

@ -25,6 +25,25 @@ TEST(LuaBasic, MathLib) {
EXPECT_FLOAT_EQ(result, 1.0f);
}
TEST(LuaBasic, iPairs) {
auto script = R"(
function testFunc()
counter = 0
data = {0x5F, 0x59, 0xFF, 0x00, 0x34, 0x0D, 0x80, 0x99}
for i, v in ipairs(data) do
counter = counter + 1
end
return counter
end
)";
float result = testLuaReturnsNumber(script);
EXPECT_FLOAT_EQ(result, 8);
}
TEST(LuaBasic, MathLibFloor) {
auto script = R"(
function testFunc()