Lua on Pokitto

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.

2 Likes

I’m getting ready for that, don’t worry. I also have to wait for something I can’t be specific about, but trust me it’s on my mind!


I’ll make a new topic if I have more to say about LIL and related stuff.

Let’s get back to LUA here.

For text editor discuss here:

3 Likes