void get_source_file_location(Block* block, Value* out) { // Search upwards until we find a block that has source-file defined. while (block != NULL && block_get_source_filename(block) == NULL) block = get_parent_block(block); if (block == NULL) return set_string(out, ""); Value* sourceFilename = block_get_source_filename(block); if (sourceFilename == NULL) return set_string(out, ""); get_directory_for_filename(sourceFilename, out); }
void source_file_location() { test_write_fake_file("block.ca", 1, "a = 1"); Block* block = load_module_file(global_world(), temp_string("source_file_location"), "block.ca"); test_equals(block_get_source_filename(block), "block.ca"); }
void Block__source_filename(VM* vm) { Block* block = as_block(vm->input(0)); while (block != NULL) { Value* filename = block_get_source_filename(block); if (filename != NULL) { copy(filename, vm->output()); return; } block = get_parent_block(block); } set_string(vm->output(), ""); }