Plugin fixes
This commit is contained in:
@@ -4,10 +4,10 @@ let plugin = plugin_create();
|
||||
// Register custom viewport shader
|
||||
context_set_viewport_shader(function(shader) {
|
||||
node_shader_add_uniform(shader, "vec3 light_dir", "_light_dir");
|
||||
node_shader_write(shader, `
|
||||
float dotnl = max(dot(n, light_dir), 0.0);
|
||||
output_color = basecol * step(0.5, dotnl) + basecol;
|
||||
`);
|
||||
node_shader_write(shader, " \
|
||||
float dotnl = max(dot(n, light_dir), 0.0); \
|
||||
output_color = basecol * step(0.5, dotnl) + basecol; \
|
||||
");
|
||||
});
|
||||
|
||||
plugin_notify_on_delete(plugin, function() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;\
|
||||
|
||||
Reference in New Issue
Block a user