diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-08-06 11:47:03 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-08-06 11:47:03 +0200 |
| commit | a007b4dd156ae1eae302cd43e22186caf854069b (patch) | |
| tree | 2e8d95a2d93776ce555232bbc20b6a8dd644a6b3 /main.c | |
| parent | 116124155ce9a36b50c0b606154547fffe549e49 (diff) | |
| download | bidi-a007b4dd156ae1eae302cd43e22186caf854069b.tar.gz | |
Added JSON example via Lua script
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -6,6 +6,7 @@ #include "lauxlib.h" #include "stdlib/color.h" +#include "stdlib/json.h" #define IN_FILE "test/main.lua" #define DEBUG_LEVEL LOG_DEBUG @@ -86,6 +87,7 @@ int main(void) { lua_State *L = luaL_newstate(); luaL_openlibs(L); + // Registring Raylib mappings. lua_register(L, "open_window", l_open_window); lua_register(L, "close_window", l_close_window); lua_register(L, "window_running", l_window_running); @@ -95,6 +97,7 @@ int main(void) { lua_register(L, "draw_fps", l_draw_fps); lua_register(L, "clear_window", l_clear_window); + // Embedding color module. if (luaL_loadbuffer(L, color, color_len, "color") || lua_pcall(L, 0, 1, 0)) { fprintf(stderr, "Error loading color.lua: %s\n", lua_tostring(L, -1)); lua_close(L); @@ -102,8 +105,15 @@ int main(void) { } lua_setglobal(L, "color"); - // TODO: This should probably use loadbuffer instead. - // https://www.lua.org/manual/5.4/manual.html#luaL_loadbuffer + // Embedding JSON module. + if (luaL_loadbuffer(L, json, json_len, "json") || lua_pcall(L, 0, 1, 0)) { + fprintf(stderr, "Error loading json.lua: %s\n", lua_tostring(L, -1)); + lua_close(L); + return 1; + } + lua_setglobal(L, "json"); + + // Interpreting and running input file Lua script. if (luaL_loadfile(L, IN_FILE) || lua_pcall(L, 0, 0, 0)) { fprintf(stderr, "Error: %s\n", lua_tostring(L, -1)); return 1; |
