handmade/test/test_lua.cpp
Bubblegumdrop 2403f060eb Add SHADER_PROGRAM_REFRESH, and a bunch of debug crap because of events.
So when PACKET_SDL_EVENT was SDL_USEREVENT, things worked fine in the
main loop it would see SDL_USEREVENT and send it off to my_SDL_UserEvent.

But when I started adding more events, the SDL_UserEvent paradigm given
in the SDL Wiki stopped working.

The example here is broken: https://wiki.libsdl.org/SDL_AddTimer
The example here is working and "correct": https://wiki.libsdl.org/SDL_UserEvent

All SDL_RegisterEvents is increase a static counter. SDL doesn't
actually use these events anyway. It's purely symbolic, as far as I can tell.

So anyway. Now events work after a bunch of debugging.

SHADER_PROGRAM_REFRESH is the second user event I've done.

The ShaderProgram runs an SDL_TimerID that looks at mVertexPath,
mGeometryPath if present, and mFragmentPath. mVertexPath and
mFragmentPath are required by Compile3ShaderBuffers.
In the future I'd like to change the way this class behaves.
2022-01-09 23:37:48 -05:00

58 lines
805 B
C++

#include "lib_lua_common.h"
#include "trim.h"
#include <iostream>
#include <fstream>
#include <string>
static const char* prompt_str = "> ";
static void my_ShowPrompt (void)
{
printf ("\n%s", prompt_str);
fflush (stdout);
}
int main (int argc, char** argv)
{
std::string buf;
bool done = false;
lua_State* L;
L = luaL_newstate ();
luaL_openlibs (L);
while (!done)
{
my_ShowPrompt ();
try
{
getline (std::cin, buf);
}
catch (std::ifstream::failure& e)
{
done = true;
break;
}
if (std::cin.eof ())
{
done = true;
break;
}
buf = trim (buf);
if (buf.empty ())
{
std::cin.clear();
std::cin.ignore();
continue;
}
printf (" => ");
fflush (stdout);
common_lua_run (L, "line", buf.c_str (), buf.length ());
}
lua_close (L);
return 0;
}