AtlatestRepositorysigil-sqlite
1/*
2 * main.c - Sigil SQLite Test Harness
3 *
4 * Creates a VM, initializes the sqlite module, and runs a test script.
5 */
6
7#include <sigil/sigil.h>
8#include <stdio.h>
9#include <stdlib.h>
11/* SQLite module init function */
12extern void sigil__init_sigil_sqlite_module(SigilVM *vm);
14int main(int argc, char *argv[])
16 const char *script_path = "test/test-sqlite.sgl";
18 if (argc >= 2) {
19 script_path = argv[1];
20 }
22 /* Create VM */
23 SigilVM *vm = sigil_vm_create();
24 if (!vm) {
25 fprintf(stderr, "Failed to create VM\n");
26 return 1;
27 }
29 /* Add load paths for stdlib and sqlite modules */
30 sigil_vm_add_load_path(vm, "../../stdlib");
31 sigil_vm_add_load_path(vm, "../../build/boot/lib");
32 /* SQLite modules (check compiled first, then source for development) */
33 sigil_vm_add_load_path(vm, "build/dev/lib");
34 sigil_vm_add_load_path(vm, "src/sigil");
36 /* Initialize sqlite native module */
37 sigil__init_sigil_sqlite_module(vm);
39 /* Load and run the script */
40 printf("Loading %s...\n", script_path);
41 int result = sigil_eval_file(vm, script_path);
43 if (result != 0) {
44 const char *err = sigil_error_message(vm);
45 if (err) {
46 fprintf(stderr, "Error: %s\n", err);
47 } else {
48 fprintf(stderr, "Script execution failed (no error message)\n");
49 }
50 }
52 /* Cleanup */
53 sigil_vm_destroy(vm);
55 return result;