diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 56 |
1 files changed, 45 insertions, 11 deletions
| @@ -109,11 +109,6 @@ static int l_clear_window(lua_State *L) { | |||
| 109 | return 0; | 109 | return 0; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | static int l_draw_fps_meter(lua_State *L) { | ||
| 113 | DrawFPS(GetScreenWidth() - 100, 20); | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | static int l_draw_info(lua_State *L) { | 112 | static int l_draw_info(lua_State *L) { |
| 118 | float delta = GetFrameTime(); | 113 | float delta = GetFrameTime(); |
| 119 | int fps = GetFPS(); | 114 | int fps = GetFPS(); |
| @@ -127,14 +122,52 @@ static int l_draw_info(lua_State *L) { | |||
| 127 | return 0; | 122 | return 0; |
| 128 | } | 123 | } |
| 129 | 124 | ||
| 125 | static int l_draw_rect(lua_State *L) { | ||
| 126 | int x = luaL_checknumber(L, 1); | ||
| 127 | int y = luaL_checknumber(L, 2); | ||
| 128 | int width = luaL_checknumber(L, 3); | ||
| 129 | int height = luaL_checknumber(L, 4); | ||
| 130 | luaL_checktype(L, 5, LUA_TTABLE); | ||
| 131 | Color color = { | ||
| 132 | .r = (unsigned char)lua_getfield_int(L, 5, "r"), | ||
| 133 | .g = (unsigned char)lua_getfield_int(L, 5, "g"), | ||
| 134 | .b = (unsigned char)lua_getfield_int(L, 5, "b"), | ||
| 135 | .a = (unsigned char)lua_getfield_int_opt(L, 5, "a", 255) | ||
| 136 | }; | ||
| 137 | DrawRectangle(x, y, width, height, color); | ||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | |||
| 141 | static int l_draw_text(lua_State *L) { | ||
| 142 | const char *text = luaL_checkstring(L, 1); | ||
| 143 | int x = luaL_checknumber(L, 2); | ||
| 144 | int y = luaL_checknumber(L, 3); | ||
| 145 | int size = luaL_checknumber(L, 4); | ||
| 146 | luaL_checktype(L, 5, LUA_TTABLE); | ||
| 147 | Color color = { | ||
| 148 | .r = (unsigned char)lua_getfield_int(L, 5, "r"), | ||
| 149 | .g = (unsigned char)lua_getfield_int(L, 5, "g"), | ||
| 150 | .b = (unsigned char)lua_getfield_int(L, 5, "b"), | ||
| 151 | .a = (unsigned char)lua_getfield_int_opt(L, 5, "a", 255) | ||
| 152 | }; | ||
| 153 | DrawTextEx(ctx.font, text, (Vector2){ x, y }, size, 0, color); | ||
| 154 | return 0; | ||
| 155 | } | ||
| 156 | |||
| 157 | static int l_draw_pixel(lua_State *L) {} | ||
| 158 | static int l_draw_line(lua_State *L) {} | ||
| 159 | static int l_draw_circle(lua_State *L) {} | ||
| 160 | static int l_draw_ellipse(lua_State *L) {} | ||
| 161 | static int l_draw_triangle(lua_State *L) {} | ||
| 162 | |||
| 130 | static void help(const char *argv0) { | 163 | static void help(const char *argv0) { |
| 131 | printf("Usage: %s [options]\n" | 164 | printf("Usage: %s [options]\n" |
| 132 | "\nAvailable options:\n" | 165 | "\nAvailable options:\n" |
| 133 | " -r,--run=file.lua run input file\n" | 166 | " -r,--run=file.lua run input file\n" |
| 134 | " -b,--bundle bundles this folder\n" | 167 | " -b,--bundle bundles this folder\n" |
| 135 | " -d,--debug prints debug information\n" | 168 | " -d,--debug prints debug information\n" |
| 136 | " -h,--help this help\n" | 169 | " -h,--help this help\n" |
| 137 | " -v,--version show version\n", | 170 | " -v,--version show version\n", |
| 138 | argv0); | 171 | argv0); |
| 139 | } | 172 | } |
| 140 | 173 | ||
| @@ -193,9 +226,10 @@ int main(int argc, char *argv[]) { | |||
| 193 | lua_register(L, "begin_drawing", l_begin_drawing); | 226 | lua_register(L, "begin_drawing", l_begin_drawing); |
| 194 | lua_register(L, "end_drawing", l_end_drawing); | 227 | lua_register(L, "end_drawing", l_end_drawing); |
| 195 | lua_register(L, "set_fps", l_set_fps); | 228 | lua_register(L, "set_fps", l_set_fps); |
| 196 | lua_register(L, "draw_fps_meter", l_draw_fps_meter); | ||
| 197 | lua_register(L, "draw_info", l_draw_info); | 229 | lua_register(L, "draw_info", l_draw_info); |
| 198 | lua_register(L, "clear_window", l_clear_window); | 230 | lua_register(L, "clear_window", l_clear_window); |
| 231 | lua_register(L, "draw_rect", l_draw_rect); | ||
| 232 | lua_register(L, "draw_text", l_draw_text); | ||
| 199 | 233 | ||
| 200 | // Loading embeded modules into Lua state. | 234 | // Loading embeded modules into Lua state. |
| 201 | if (!load_embedded_module(L, json, json_len, "json")) return 1; | 235 | if (!load_embedded_module(L, json, json_len, "json")) return 1; |
