-
Notifications
You must be signed in to change notification settings - Fork 178
Open
Description
So, I'm trying to just embed squirrel language in cpp app to see how easy it is to embed or how great it is for games etc.
And to test it I tried to make a script that creates variable a (an integer). And cpp app is suposed to load that ./myscript.nut file and pull value of variable "a" form vm into stack and print it out.
(linking errors have been resolved, now there are logic errors)
here is code
#include "./squirrel_includes.h"
#include <stdio.h>
HSQUIRRELVM vm = sq_open(1024); // Create a Squirrel VM
int main() {
// Load and execute the script
SQRESULT res = sqstd_dofile(vm, "./myscript.nut", SQFalse, SQTrue);
if (SQ_SUCCEEDED(res)) {
// Get the value of variable 'a' from the script
sq_pushinteger(vm, _SC("a"), -1);
if (SQ_SUCCEEDED(sq_get(vm, -1))) {
if (sq_gettype(vm, -1) == OT_INTEGER) {
SQInteger a;
sq_getinteger(vm, -1, &a);
printf("Value of variable 'a' in the script: %d\n", a);
} else {
printf("Variable 'a' is not an integer in the script\n");
}
} else {
const SQChar *errorString;
sq_getlasterror(vm);
sq_getstring(vm, -1, &errorString);
printf("Script execution error: %s\n", errorString);
}
} else {
const SQChar *errorString;
sq_getlasterror(vm);
sq_getstring(vm, -1, &errorString);
printf("Script execution error: %s\n", errorString);
}
sq_close(vm);
return 0;
}and when building and running app (./myscript.nut is in same directory)
Script execution error: environment table expectedand where should I ask about what's wrong? (ik chatbots are a thing but i mean like forum where ppl know what they say)?
Whould be cool if it was added to readme
Metadata
Metadata
Assignees
Labels
No labels