Make Stat a foreign class.

Instead of copying the uv_fs_stat struct to a list of Wren numbers, we
store it directly in the Stat object. This is important because we'll
need to implement later methods like isDirectory() in C so we can use
S_ISDIR(). For that, we need to have access to the original stat data.
This commit is contained in:
Bob Nystrom
2016-02-21 11:34:10 -08:00
parent b331915259
commit c6148f8941
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;