diff --git a/dist/platform/elc b/dist/platform/elc index 722711c..14cd6ee 100755 Binary files a/dist/platform/elc and b/dist/platform/elc differ diff --git a/dist/platform/elc.prev3 b/dist/platform/elc.prev3 new file mode 100755 index 0000000..722711c Binary files /dev/null and b/dist/platform/elc.prev3 differ diff --git a/el-compiler/runtime/el_runtime.c b/el-compiler/runtime/el_runtime.c index e5b0365..ab788dc 100644 --- a/el-compiler/runtime/el_runtime.c +++ b/el-compiler/runtime/el_runtime.c @@ -27,6 +27,7 @@ #include #include #include +#include /* dlsym for http_set_handler fallback */ #include #include #include @@ -616,6 +617,24 @@ void http_set_handler(el_val_t name) { pthread_mutex_lock(&_http_handler_mu); free(_http_active_handler); _http_active_handler = el_strdup(n ? n : ""); + /* If the name is not yet in the registry, try dlsym lookup against + * the running binary's symbol table. Every El `fn name(...)` compiles + * to a global C symbol with that exact name, so El programs can self- + * register their own handlers just by calling http_set_handler("name"). */ + if (n && *n) { + int found = 0; + for (size_t i = 0; i < _http_handler_count; i++) { + if (strcmp(_http_handlers[i].name, n) == 0) { found = 1; break; } + } + if (!found) { + void* sym = dlsym(RTLD_DEFAULT, n); + if (sym && _http_handler_count < sizeof(_http_handlers) / sizeof(_http_handlers[0])) { + _http_handlers[_http_handler_count].name = el_strdup(n); + _http_handlers[_http_handler_count].fn = (http_handler_fn)sym; + _http_handler_count++; + } + } + } pthread_mutex_unlock(&_http_handler_mu); }