albertodemichelis / squirrel

Official repository for the programming language Squirrel
http://www.squirrel-lang.org
MIT License
910 stars 155 forks source link

Any kind of forums? #289

Open TymekBrunka opened 1 month ago

TymekBrunka commented 1 month ago

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 expected

and 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

TymekBrunka commented 1 month ago

i think i migh choose diferent language, but good forum for questions and answers whould be good to have

zeromus commented 1 month ago

The docs for sqstd_dofile say the function expects a table on top of the stack that will be used as ‘this’ for the execution of the script.

It then goes on to give an example of meeting this requirement.

If you require support from an active community, then this language is not the greatest choice for you.