Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any kind of forums? #289

Open
TymekBrunka opened this issue Jul 18, 2024 · 2 comments
Open

Any kind of forums? #289

TymekBrunka opened this issue Jul 18, 2024 · 2 comments

Comments

@TymekBrunka
Copy link

TymekBrunka commented Jul 18, 2024

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
Copy link
Author

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

@zeromus
Copy link
Contributor

zeromus commented Jul 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants