ffi: canonical static access ffi::load (module namespace)

- '::' accesses a static/class member (here the module namespace ffi),
  '.'/':' sends to an instance.  ffi is a module, so ffi::load is the
  canonical form; the native now accepts the receiver passed by '::'.
- example, tests and README use ffi::load; '.load' still works (compat).
- 69/69 tests
This commit is contained in:
Minus committed 2026-11-16 03:44:59 +00:00
1 parent 05f31aed68
commit 4dae4ee1cd
4 files changed
+28 -10

No files matched your search

+17 -3
View File
@@ -353,16 +353,30 @@ CAT_VALUE_Value *cat_types_ffi_bind(CAT_VALUE_Value *lib, const char *name,
return &f->base;
}
/* `ffi.load(path)` module function. */
/* `ffi::load(path)` module function (static access).
*
* `::` sends the module as the receiver, so with `ffi::load("x")` the
* path is args[1]; a plain `load("x")` passes it as args[0]. Accept
* both by taking the first TEXT argument. */
static int ffi_load_native(CAT_VM_State *vm, CAT_VALUE_Value **args, int nargs,
CAT_VALUE_Value **out)
{
CAT_VALUE_Value *path = NULL;
int i;
(void)vm;
if (nargs < 1) {
for (i = 0; i < nargs; i++) {
if (args[i] != NULL && args[i]->vtable != NULL &&
args[i]->vtable->kind == CAT_VALUE_KIND_TEXT) {
path = args[i];
break;
}
}
if (path == NULL) {
*out = cat_types_nil_get();
return 0;
}
*out = cat_types_ffi_load(cat_types_text_bytes(args[0]));
*out = cat_types_ffi_load(cat_types_text_bytes(path));
return 0;
}