|
diff --git a/main.c b/main.c
|
| ... |
| 81 |
return 0; |
81 |
return 0; |
| 82 |
} |
82 |
} |
| 83 |
|
83 |
|
|
|
84 |
static int l_get_dt(lua_State *L) { |
|
|
85 |
lua_pushnumber(L, GetFrameTime()); |
|
|
86 |
return 1; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
static int l_get_fps(lua_State *L) { |
|
|
90 |
lua_pushnumber(L, GetFPS()); |
|
|
91 |
return 1; |
|
|
92 |
} |
|
|
93 |
|
| 84 |
static int l_close_window(lua_State *L) { |
94 |
static int l_close_window(lua_State *L) { |
| 85 |
CloseWindow(); |
95 |
CloseWindow(); |
| 86 |
TraceLog(LOG_DEBUG, "l_close_window"); |
96 |
TraceLog(LOG_DEBUG, "l_close_window"); |
| ... |
| 154 |
return 0; |
164 |
return 0; |
| 155 |
} |
165 |
} |
| 156 |
|
166 |
|
| 157 |
static int l_draw_pixel(lua_State *L) {} |
167 |
static int l_draw_pixel(lua_State *L) { |
| 158 |
static int l_draw_line(lua_State *L) {} |
168 |
int x = luaL_checknumber(L, 1); |
| 159 |
static int l_draw_circle(lua_State *L) {} |
169 |
int y = luaL_checknumber(L, 2); |
| 160 |
static int l_draw_ellipse(lua_State *L) {} |
170 |
luaL_checktype(L, 3, LUA_TTABLE); |
| 161 |
static int l_draw_triangle(lua_State *L) {} |
171 |
Color color = { |
|
|
172 |
.r = (unsigned char)lua_getfield_int(L, 3, "r"), |
|
|
173 |
.g = (unsigned char)lua_getfield_int(L, 3, "g"), |
|
|
174 |
.b = (unsigned char)lua_getfield_int(L, 3, "b"), |
|
|
175 |
.a = (unsigned char)lua_getfield_int_opt(L, 3, "a", 255) |
|
|
176 |
}; |
|
|
177 |
DrawPixel(x, y, color); |
|
|
178 |
} |
|
|
179 |
|
|
|
180 |
static int l_draw_line(lua_State *L) { |
|
|
181 |
int x1 = luaL_checknumber(L, 1); |
|
|
182 |
int y1 = luaL_checknumber(L, 2); |
|
|
183 |
int x2 = luaL_checknumber(L, 3); |
|
|
184 |
int y2 = luaL_checknumber(L, 4); |
|
|
185 |
luaL_checktype(L, 5, LUA_TTABLE); |
|
|
186 |
Color color = { |
|
|
187 |
.r = (unsigned char)lua_getfield_int(L, 5, "r"), |
|
|
188 |
.g = (unsigned char)lua_getfield_int(L, 5, "g"), |
|
|
189 |
.b = (unsigned char)lua_getfield_int(L, 5, "b"), |
|
|
190 |
.a = (unsigned char)lua_getfield_int_opt(L, 5, "a", 255) |
|
|
191 |
}; |
|
|
192 |
DrawLine(x1, y1, x2, y2, color); |
|
|
193 |
return 0; |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
static int l_draw_circle(lua_State *L) { |
|
|
197 |
int center_x = luaL_checknumber(L, 1); |
|
|
198 |
int center_y = luaL_checknumber(L, 2); |
|
|
199 |
int radius = luaL_checknumber(L, 3); |
|
|
200 |
luaL_checktype(L, 4, LUA_TTABLE); |
|
|
201 |
Color color = { |
|
|
202 |
.r = (unsigned char)lua_getfield_int(L, 4, "r"), |
|
|
203 |
.g = (unsigned char)lua_getfield_int(L, 4, "g"), |
|
|
204 |
.b = (unsigned char)lua_getfield_int(L, 4, "b"), |
|
|
205 |
.a = (unsigned char)lua_getfield_int_opt(L, 4, "a", 255) |
|
|
206 |
}; |
|
|
207 |
DrawCircle(center_x, center_y, radius, color); |
|
|
208 |
return 0; |
|
|
209 |
} |
|
|
210 |
|
|
|
211 |
static int l_draw_ellipse(lua_State *L) { |
|
|
212 |
int center_x = luaL_checknumber(L, 1); |
|
|
213 |
int center_y = luaL_checknumber(L, 2); |
|
|
214 |
int radius_h = luaL_checknumber(L, 3); |
|
|
215 |
int radius_v = luaL_checknumber(L, 4); |
|
|
216 |
luaL_checktype(L, 5, LUA_TTABLE); |
|
|
217 |
Color color = { |
|
|
218 |
.r = (unsigned char)lua_getfield_int(L, 5, "r"), |
|
|
219 |
.g = (unsigned char)lua_getfield_int(L, 5, "g"), |
|
|
220 |
.b = (unsigned char)lua_getfield_int(L, 5, "b"), |
|
|
221 |
.a = (unsigned char)lua_getfield_int_opt(L, 5, "a", 255) |
|
|
222 |
}; |
|
|
223 |
DrawEllipse(center_x, center_y, radius_h, radius_v, color); |
|
|
224 |
return 0; |
|
|
225 |
} |
|
|
226 |
|
|
|
227 |
static int l_draw_triangle(lua_State *L) { |
|
|
228 |
int x1 = luaL_checknumber(L, 1); |
|
|
229 |
int y1 = luaL_checknumber(L, 2); |
|
|
230 |
int x2 = luaL_checknumber(L, 3); |
|
|
231 |
int y2 = luaL_checknumber(L, 4); |
|
|
232 |
int x3 = luaL_checknumber(L, 5); |
|
|
233 |
int y3 = luaL_checknumber(L, 6); |
|
|
234 |
luaL_checktype(L, 7, LUA_TTABLE); |
|
|
235 |
Color color = { |
|
|
236 |
.r = (unsigned char)lua_getfield_int(L, 7, "r"), |
|
|
237 |
.g = (unsigned char)lua_getfield_int(L, 7, "g"), |
|
|
238 |
.b = (unsigned char)lua_getfield_int(L, 7, "b"), |
|
|
239 |
.a = (unsigned char)lua_getfield_int_opt(L, 7, "a", 255) |
|
|
240 |
}; |
|
|
241 |
|
|
|
242 |
// NOTE: Raylib orders vertices in counter-clockwise order. We order them |
|
|
243 |
// in clockwise order instead to make this a bit easier to use. |
|
|
244 |
Vector2 p1 = { x1, y1 }; |
|
|
245 |
Vector2 p2 = { x3, y3 }; |
|
|
246 |
Vector2 p3 = { x2, y2 }; |
|
|
247 |
|
|
|
248 |
DrawTriangle(p1, p2, p3, color); |
|
|
249 |
return 0; |
|
|
250 |
} |
| 162 |
|
251 |
|
| 163 |
static void help(const char *argv0) { |
252 |
static void help(const char *argv0) { |
| 164 |
printf("Usage: %s [options]\n" |
253 |
printf("Usage: %s [options]\n" |
| ... |
| 226 |
lua_register(L, "begin_drawing", l_begin_drawing); |
315 |
lua_register(L, "begin_drawing", l_begin_drawing); |
| 227 |
lua_register(L, "end_drawing", l_end_drawing); |
316 |
lua_register(L, "end_drawing", l_end_drawing); |
| 228 |
lua_register(L, "set_fps", l_set_fps); |
317 |
lua_register(L, "set_fps", l_set_fps); |
|
|
318 |
lua_register(L, "get_fps", l_get_fps); |
|
|
319 |
lua_register(L, "get_dt", l_get_dt); |
|
|
320 |
lua_register(L, "clear_window", l_clear_window); |
| 229 |
lua_register(L, "draw_info", l_draw_info); |
321 |
lua_register(L, "draw_info", l_draw_info); |
| 230 |
lua_register(L, "clear_window", l_clear_window); |
|
|
| 231 |
lua_register(L, "draw_rect", l_draw_rect); |
322 |
lua_register(L, "draw_rect", l_draw_rect); |
| 232 |
lua_register(L, "draw_text", l_draw_text); |
323 |
lua_register(L, "draw_text", l_draw_text); |
|
|
324 |
lua_register(L, "draw_pixel", l_draw_pixel); |
|
|
325 |
lua_register(L, "draw_line", l_draw_line); |
|
|
326 |
lua_register(L, "draw_circle", l_draw_circle); |
|
|
327 |
lua_register(L, "draw_ellipse", l_draw_ellipse); |
|
|
328 |
lua_register(L, "draw_triangle", l_draw_triangle); |
| 233 |
|
329 |
|
| 234 |
// Loading embeded modules into Lua state. |
330 |
// Loading embeded modules into Lua state. |
| 235 |
if (!load_embedded_module(L, json, json_len, "json")) return 1; |
331 |
if (!load_embedded_module(L, json, json_len, "json")) return 1; |
| ... |