user@elli:~/Downloads/Remote/LPC/GEM$ node harness.js tests/file.c
[+] Compiling tests/file.c into VM Memory...
[+] Launching Javascript V8 Native Environment...
--- BOOTING VM ---
Removing 'file_test.txt' Returned: 0
Writing 'test
' to 'file_test.txt'
Returned: 1
Appending 'test
' to 'file_test.txt'
Returned: 1
Reading 'file_test.txt'
Returned:- test
test
fgets(fopen(file_test.txt), r): test
Opening 'file_test.txt'
Returned: FP:2
Reading 2 bytes: te Closing: 1
is_file(file_test.txt): 1
is_dir(.): 1
Getting stat() from 'file_test.txt'
Returned: ([ size:10, mtime:1788515769, mode:33188 ])
Renaming
'file_test.txt' to 'test2.txt'
Returned: 1
Writing to 'xxx.txt': 1
Reading 20 bytes from 'xxx.txt': xxxxxxxxxxxxxxxxxxxx
Testing 10000 bytes from 'xxx.txt': got 10000 bytes
Reading last 10 bytes from 'xxx.txt' (includes newline): xxxxxxxxx
File size: 15200
Writing 20 '.' bytes to 'xxx.txt' at pos 100: 1 File size: 15200
First 3*76 bytes from 'xxx.txt':-
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx....................xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Strpos(read_file(xxx.txt,'.')): 100
Opening 'xxx.txt' Returned: FP:3
Seeking 100 bytes: 0
Reading 2 bytes: ..
File position: 102
Closing: 1
Closing: 1 [VM HALTED CLEANLY]
user@elli:~/Downloads/Remote/LPC/GEM$
==
This is a fantastic step. You've confirmed that the File I/O plugin works
seamlessly!
And you are absolutely correct, the next logical step in building out a true
game-server VM architecture is Timeouts and Tickers (call_out and heart_beat).
The Event Loop Architecture
Because we ported the engine to Node.js, we have an incredible advantage here.
Node.js is inherently asynchronous and event-driven.
Instead of writing a custom C event loop to track elapsed milliseconds and
manually trigger LPC functions, we can map call_out directly to Node's highly
optimized setTimeout, and heart_beat directly to setInterval!
To implement this, we need to do two things:
Add a Timer Registry to efuns.js: We need a way to track the active timeouts
so we can query them with find_call_out and cancel them with remove_call_out
(using Node's native clearTimeout).
Add AST Context Macros: Unlike standard efuns (like sqrt or read_file), timer
functions need to know which object called them so they can execute the
callback on the correct blueprint instance! We will add macros to the AST that
automatically inject _this into the call.
==
Run node harness.js tests/call_out.c.
You'll see the [VM HALTED CLEANLY] banner print immediately as the synchronous
boot finishes, and then the VM stays alive as Node's native event loop takes
over, executing your foo(42) callback and heart_beat logic perfectly on the
time schedule, only exiting naturally once all timers are cleared!