int main(int argc, char** argv) { caWorld* world = circa_initialize(); circa_load_module_from_file(world, "ClassA", "ClassA.ca"); // circa_dump_b(circa_kernel(world)); caStack* stack = circa_alloc_stack(world); circa_push_function_by_name(stack, "create_ClassA"); circa_run(stack); if (circa_has_error(stack)) circa_print_error_to_stdout(stack); caValue* classA = circa_alloc_value(); circa_move(circa_output(stack, 0), classA); circa_pop(stack); // Dump to stdout circa_push_function_by_name(stack, "ClassA.dump"); circa_copy(classA, circa_input(stack, 0)); circa_run(stack); if (circa_has_error(stack)) circa_print_error_to_stdout(stack); circa_pop(stack); for (int i=0; i < 5; i++) { // Increment circa_push_function_by_name(stack, "ClassA.increment"); circa_copy(classA, circa_input(stack, 0)); circa_run(stack); if (circa_has_error(stack)) circa_print_error_to_stdout(stack); // Using index #1 not 0: circa_move(circa_output(stack, 1), classA); circa_pop(stack); // And dump circa_push_function_by_name(stack, "ClassA.dump"); circa_copy(classA, circa_input(stack, 0)); circa_run(stack); if (circa_has_error(stack)) circa_print_error_to_stdout(stack); circa_pop(stack); } circa_dealloc_value(classA); circa_dealloc_stack(stack); circa_shutdown(world); }
int main(int argc, char** argv) { const int iteratations = 100; caWorld* world = circa_initialize(); caStack* stack = circa_alloc_stack(world); // Write initial version write_script_to_file(0); caBranch* module = circa_load_module_from_file(world, "file_to_reload", "file_to_reload.ca"); int currentKey = 0; for (int i=0; i < iteratations; i++) { // Update file on every other iteration if ((i % 2) == 1) { printf("writing to file: %d\n", i); currentKey = i; write_script_to_file(i); sleep(2); } circa_refresh_module(module); circa_push_function_by_name(stack, "f"); circa_run(stack); if (circa_has_error(stack)) { circa_print_error_to_stdout(stack); break; } int readValue = circa_int(circa_output(stack, 0)); if (currentKey != readValue) { printf("Failed, currentKey (%d) != readValue (%d)\n", currentKey, readValue); break; } circa_pop(stack); } circa_shutdown(world); }