Plugin fixes

This commit is contained in:
luboslenco
2024-09-26 21:55:27 +02:00
parent 5ea40a8c16
commit 6213f9ca9c
4 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ function plugin_create(): plugin_t {
function plugin_start(plugin: string) {
let blob: buffer_t = data_get_blob("plugins/" + plugin);
_plugin_name = plugin;
js_eval(sys_buffer_to_string(blob));
js_eval("(1, eval)(`" + sys_buffer_to_string(blob) + "`)");
data_delete_blob("plugins/" + plugin);
}
+7
View File
@@ -365,6 +365,8 @@ globalThis.buffer_to_string = buffer_to_string;\
// ██████╔╝██║██║ ╚████║██████╔╝██║██║ ╚████║╚██████╔╝███████║
// ╚═════╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝
any_array_t *plugin_gc;
// These could be auto-generated by alang
VOID_FN_STR(console_log)
VOID_FN_STR(console_info)
@@ -467,6 +469,7 @@ FN(project_save) {
FN(ui_handle_create) {
int64_t result = (int64_t)ui_handle_create();
any_array_push(plugin_gc, (void *)result);
return JS_NewInt64(ctx, result);
}
@@ -763,10 +766,14 @@ FN(plugin_api_make_raw_mesh) {
return JS_NewInt64(ctx, (int64_t)mesh);
}
void gc_root(void *ptr);
void plugin_api_init() {
JSValue global_obj = JS_GetGlobalObject(js_ctx);
js_eval(lib);
plugin_gc = any_array_create(0);
gc_root(plugin_gc);
BIND(console_log, 1);
BIND(console_info, 1);
+2 -1
View File
@@ -56,8 +56,9 @@ void js_call_arg(void *p, int argc, void *argv);
#define VOID_FN_CB(name)\
void name(void *p);\
FN(name) {\
JSValue *p = malloc(sizeof(JSValue));\
JSValue dup = JS_DupValue(ctx, argv[0]);\
if (JS_IsNull(dup)) { name(NULL); return JS_UNDEFINED; } \
JSValue *p = malloc(sizeof(JSValue));\
memcpy(p, &dup, sizeof(JSValue));\
name(p);\
return JS_UNDEFINED;\