So, I have a program that will draw a window with some text and a background using raylib, and I'm trying to bind a C function to Lua, so that a user can change the title within a 'config.lua' script. The program compiles, but when I try to run, I get this error: Illegal exception 4.
#include <stdio.h>
#include <raylib.h>
#include <lua/lauxlib.h>
#include <lua/lua.h>
#include <lua/luaconf.h>
#include <lua/lualib.h>
#include <string.h>
int windowHeight = 460;
int windowWidth = 800;
char windowTitle[] = "my game";
int setTitle(char title[]) {
//this is unsafe, use strcpy_s instead
strcpy(windowTitle, title);
//if (strcpy_s(windowTitle, sizeof(windowTitle), windowTitle) != 0) {
// return 1;
//}
return 0;
}
static int lua_setTitle(lua_State *L) {
const char *new_title = luaL_checkstring(L, 1);
setTitle(new_title);
return 0;
}
int main() {
lua_State *L = luaL_newstate();
// push funcs to lua globally
lua_pushcfunction(L, lua_setTitle);
lua_setglobal(L, "settitle");
// load Lua file, be sure to load the file AFTER pushing the C functions to lua
// check if file is actually loaded
if (luaL_dofile(L, "src/config.lua") != 0) {
printf("could not find, or load config file! \n");
printf("error info: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return 1;
}
InitWindow(windowWidth, windowHeight, windowTitle);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
lua_close(L);
CloseWindow();
return 0;
}
Here is my makefile (I'm on MacOS big sur btw)
game:
clang -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL lib/libraylib.a lib/liblua.a src/main.c -o main
And here is my config.lua script:
settitle('water')
What does Illegal Exception 4 even mean? and how can I fix this? Any help is greatly appreciated.