/** * File * * Represents a File object. * Creates a new file object based on the specified path. * * Usage: * * File new: '/example/path/to/file.txt'. */ ctr_object* ctr_file_new(ctr_object* myself, ctr_argument* argumentList) { ctr_object* s = ctr_object_make(myself, argumentList); ctr_object* pathObject; s->info.type = CTR_OBJECT_TYPE_OTEX; /* indicates resource for GC */ s->link = myself; s->value.rvalue = NULL; pathObject = ctr_build_string( argumentList->object->value.svalue->value, argumentList->object->value.svalue->vlen ); ctr_internal_object_add_property( s, ctr_build_string_from_cstring( "path" ), pathObject, 0 ); return s; }
/** * File * * Represents a File object. * Creates a new file object based on the specified path. * * Usage: * * File new: '/example/path/to/file.txt'. */ ctr_object* ctr_file_new(ctr_object* myself, ctr_argument* argumentList) { ctr_object* s = ctr_object_make(myself, argumentList); ctr_object* pathObject; s->info.type = CTR_OBJECT_TYPE_OTMISC; s->link = myself; s->value.rvalue = malloc(sizeof(ctr_resource)); s->value.rvalue->type = 1; pathObject = ctr_internal_create_object(CTR_OBJECT_TYPE_OTSTRING); pathObject->info.type = CTR_OBJECT_TYPE_OTSTRING; pathObject->value.svalue = (ctr_string*) malloc(sizeof(ctr_string)); pathObject->value.svalue->value = (char*) malloc(sizeof(char) * argumentList->object->value.svalue->vlen); memcpy(pathObject->value.svalue->value, argumentList->object->value.svalue->value, argumentList->object->value.svalue->vlen); pathObject->value.svalue->vlen = argumentList->object->value.svalue->vlen; ctr_internal_object_add_property(s, ctr_build_string("path",4), pathObject, 0); return s; }