Since this thread is supposed to be about Lua, here’s the Lua equivalent:
#include <Pokitto.h>
#define LUA_32BITS
#include <lua.hpp>
void writeChar(lua_State * state)
{
using Pokitto::Display;
auto string = luaL_checkstring(state, 1);
Display::setCursor(1, 1);
Display::print(string);
}
int main ()
{
using Pokitto::Core;
using Pokitto::Display;
Core::begin();
lua_State * state = luaL_newstate();
lua_pushcfunction(state, writeChar);
lua_setglobal(state, "writeChar");
while (Core::isRunning())
{
if (Core::update())
{
auto status = luaL_loadstring(state, "writeChar('Hey');");
if (status != 0)
{
Display::println("Error loading!");
Display::println(lua_tostring(state, -1));
continue;
}
auto result = lua_pcall(state, 0, 0, 0);
if (result != 0)
{
Display::println("Error running!");
Display::println(lua_tostring(state, -1));
continue;
}
}
}
lua_close(state);
return 0;
}
You could omit the error handling of course, but I’d rather leave it in.
(I think auto status = luaL_loadstring(state, "writeChar 'Hey'");
would work as well.)
Weren’t you supposed to be making a raycaster-based game a few weeks back? :P
Probably for the best.
Same with LIL, that should be in a separate topic as well, otherwise it’s going to get buried and nobody will see it.