Copy Output
Type 'help' for a list of commands.
--- LPC WEBASSEMBLY VM BOOTED ---
Available commands:
help - Show this message
time - Display system time
md5 <string> - Hash a string
eval <lpc> - Evaluate LPC expression dynamically
clear - Clear the screen (handled by frontend)
eval read_file("tests/math.c")
Result: void create ()
{
float f;
int i;
f = 5.5;
printf ("f: %f
", f);
printf ("f/2: %f
", f / 2.0);
printf ("sqrt(f): %f
", sqrt (f));
printf ("log(f): %f
", log (f));
printf ("pow(f,2): %f
", pow (f,2));
printf ("
");
i = -42;
printf ("i: %d
", i);
printf ("abs(i): %d
", abs (i));
}
eval get_dir ("tests/")
Result: ({ string.c, math.c, file.c, clone_object.c, catch.c, define.c,
rambuffer.c, repl.c, mesh_test.c })
eval read_file ("tests/repl.c")
Result: // tests/repl.c
void create() {
printf("Type 'help' for a list of commands.
");
}
void process_repl_command_line(string input) {
// 1. Declare ALL variables at the top of the block
string cmd, arg;
string filename, src;
object ob;
mixed res;
// 2. Execute logic
if (sscanf(input, "%s %s", cmd, arg) != 2) {
cmd = input;
}
if (cmd == "help") {
printf("Available commands:
");
printf(" help - Show this message
");
printf(" time - Display system time
");
printf(" md5 <string> - Hash a string
");
printf(" eval <lpc> - Evaluate LPC expression dynamically
");
printf(" clear - Clear the screen (handled by frontend)
");
}
else if (cmd == "time") {
printf("System uptime: %d seconds
", uptime());
printf("Current time: %s
", ctime(time()));
}
else if (cmd == "md5" && arg) {
printf("MD5('%s') = %s
", arg, md5(arg));
}
else if (cmd == "eval" && arg) {
// Assign the previously declared variables
filename = "tmp_eval_" + random(9999999) + ".c";
src = "mixed do_eval() { return (" + arg + "); }
";
if (write_file(filename, src)) {
ob = clone_object(filename);
if (ob) {
res = ob->do_eval();
printf("Result: %s
", res);
destruct(ob);
} else {
printf("Error: Failed to compile expression.
");
}
rm(filename); // Clean up the VFS
} else {
printf("Error: Failed to write temp file to VFS.
");
}
}
else if (cmd == "") {
// Do nothing on empty enter
}
else {
printf("Unrecognized command: %s
", cmd);
}
}
>