WiiDuktape/source/grrlib_duk.c
2024-06-19 23:37:41 -07:00

40 lines
1 KiB
C

#include "grrlib_duk.h"
#include <grrlib.h>
static unsigned int get_color(duk_context *ctx, duk_idx_t index) {
size_t rgba_size;
unsigned char * rgba = duk_get_buffer(ctx, index, &rgba_size);
return rgba[0] << 24 | rgba[1] << 16 | rgba[2] << 8 | rgba[3];
}
static duk_ret_t grrlib_fill_screen(duk_context *ctx) {
unsigned int color = get_color(ctx, 0);
GRRLIB_FillScreen(color);
return 0;
}
static duk_ret_t grrlib_rectangle(duk_context *ctx) {
float x = duk_to_number(ctx, 0);
float y = duk_to_number(ctx, 1);
float width = duk_to_number(ctx, 2);
float height = duk_to_number(ctx, 3);
unsigned int color = get_color(ctx, 4);
bool filled = duk_to_boolean(ctx, 5);
GRRLIB_Rectangle(x, y, width, height, color, filled);
return 0;
}
void define_grrlib_object(duk_context *ctx) {
duk_idx_t grrlib_obj = duk_push_object(ctx);
duk_push_c_function(ctx, grrlib_fill_screen, 1);
duk_put_prop_string(ctx, grrlib_obj, "fill_screen");
duk_push_c_function(ctx, grrlib_rectangle, 6);
duk_put_prop_string(ctx, grrlib_obj, "rectangle");
}