void duk_push_sphere_font(duk_context* ctx, font_t* font) { duk_push_sphere_obj(ctx, "Font", ref_font(font)); duk_push_sphere_color(ctx, color_new(255, 255, 255, 255)); duk_put_prop_string(ctx, -2, "\xFF" "color_mask"); }
static duk_ret_t js_new_Logger(duk_context* ctx) { const char* filename = duk_get_string(ctx, 0); char* path = get_asset_path(filename, "logs", true); logger_t* logger = open_log_file(path); free(path); if (logger == NULL) duk_error_ni(ctx, -1, DUK_ERR_ERROR, "OpenLog(): Failed to open file for logging '%s'", filename); duk_push_sphere_obj(ctx, "Logger", logger); return 1; }
static duk_ret_t js_new_RawFile(duk_context* ctx) { int n_args = duk_get_top(ctx); const char* filename = duk_require_string(ctx, 0); bool writable = n_args >= 2 ? duk_require_boolean(ctx, 1) : false; FILE* file; char* path; path = get_asset_path(filename, "other", writable); file = fopen(path, writable ? "w+b" : "rb"); free(path); if (file == NULL) duk_error_ni(ctx, -1, DUK_ERR_ERROR, "OpenRawFile(): Failed to open file '%s' for %s", filename, writable ? "writing" : "reading"); duk_push_sphere_obj(ctx, "RawFile", file); return 1; }