diff --git a/main.c b/main.c index 82319d27756cb440ecb322c2768f393cac6129f5..b6602a0fdd5ac24ed55043811de047293ab2e6d5 100644 --- a/main.c +++ b/main.c @@ -5,8 +5,9 @@ #include "lua.h" #include "lualib.h" #include "lauxlib.h" +#include "stdlib/json.h" #include "stdlib/color.h" -#include "stdlib/json.h" +#include "stdlib/tilemap.h" #define IN_FILE "test/main.lua" #define DEBUG_LEVEL LOG_DEBUG @@ -97,6 +98,14 @@ lua_register(L, "set_fps", l_set_fps); lua_register(L, "draw_fps", l_draw_fps); lua_register(L, "clear_window", l_clear_window); + // 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"); + // 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)); @@ -105,13 +114,13 @@ return 1; } lua_setglobal(L, "color"); - // 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)); + // Embedding tilemap module. + if (luaL_loadbuffer(L, tilemap, tilemap_len, "tilemap") || lua_pcall(L, 0, 1, 0)) { + fprintf(stderr, "Error loading tilemap.lua: %s\n", lua_tostring(L, -1)); lua_close(L); return 1; } - lua_setglobal(L, "json"); + lua_setglobal(L, "tilemap"); // Interpreting and running input file Lua script. if (luaL_loadfile(L, IN_FILE) || lua_pcall(L, 0, 0, 0)) { diff --git a/stdlib/tilemap.h b/stdlib/tilemap.h index 5795bd7f0c0ac42f164126a3a071bd651ae9221e..3a60c2d78e871ee40727ea22f3430184d5a8f32f 100644 --- a/stdlib/tilemap.h +++ b/stdlib/tilemap.h @@ -2,18 +2,10 @@ #ifndef tilemap_H #define tilemap_H unsigned char tilemap[] = { - 0x2d, 0x2d, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, - 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, - 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x70, 0x6f, - 0x74, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x61, 0x6e, - 0x64, 0x61, 0x72, 0x64, 0x20, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, - 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, - 0x73, 0x20, 0x74, 0x68, 0x65, 0x0a, 0x2d, 0x2d, 0x20, 0x66, 0x72, 0x61, - 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, - 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x66, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x69, - 0x65, 0x73, 0x2e, 0x0a + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x69, 0x6c, 0x65, 0x6d, 0x61, + 0x70, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x74, 0x69, 0x6c, 0x65, 0x6d, 0x61, 0x70, 0x0a }; -unsigned int tilemap_len = 124; +unsigned int tilemap_len = 35; #endif // tilemap_H diff --git a/stdlib/tilemap.lua b/stdlib/tilemap.lua index e2dad67afc4f74c2350524353943699c347278e7..da30c1eec2669787fe7f01ff18ca5ee97a45b413 100644 --- a/stdlib/tilemap.lua +++ b/stdlib/tilemap.lua @@ -1,2 +1,3 @@ --- This is a placeholder file for potential standard library that extends the --- framework with additional functionalities. +local tilemap = {} + +return tilemap