feat: convert Stat from Wren class with list fields to foreign class with native C accessors

Replace the Wren-implemented Stat class that stored stat fields in a list with a foreign class backed by the raw uv_fs_stat struct, enabling direct C-level access to stat data for future methods like isDirectory() using S_ISDIR().
This commit is contained in:
Bob Nystrom
2016-02-21 19:34:10 +00:00
parent 42ba73b03b
commit 7f744565fc
5 changed files with 140 additions and 79 deletions
+9 -8
View File
@@ -612,18 +612,19 @@ static void bindForeignClass(WrenVM* vm, ObjClass* classObj, ObjModule* module)
Method method;
method.type = METHOD_FOREIGN;
method.fn.foreign = methods.allocate;
ASSERT(method.fn.foreign != NULL,
"A foreign class must provide an allocate function.");
int symbol = wrenSymbolTableEnsure(vm, &vm->methodNames, "<allocate>", 10);
wrenBindMethod(vm, classObj, symbol, method);
// Add the symbol even if there is no finalizer so we can ensure that the
// symbol itself is always in the symbol table.
int symbol = wrenSymbolTableEnsure(vm, &vm->methodNames, "<allocate>", 10);
if (methods.allocate != NULL)
{
method.fn.foreign = methods.allocate;
wrenBindMethod(vm, classObj, symbol, method);
}
// Add the symbol even if there is no finalizer so we can ensure that the
// symbol itself is always in the symbol table.
symbol = wrenSymbolTableEnsure(vm, &vm->methodNames, "<finalize>", 10);
if (methods.finalize != NULL)
{
method.fn.foreign = (WrenForeignMethodFn)methods.finalize;