Author Topic: dofile from squirrel  (Read 5528 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
dofile from squirrel
« on: June 13, 2013, 01:00:57 am »
Hello, it is late her, so i might have missed it, but is the "dofile" command from squirrel enabled in c::b?
if i type it in the script console i get
Code
AN ERROR HAS OCCURED [the index 'dofile' does not exist]

i thought c::b uses squirrel 2.2
http://www.squirrel-lang.org/doc/sqstdlib2.html
and there dofile exists. Is the stdlib not loaded in c::b?
if not: why not?
why yes:
I discovered that the variable expansion (and the script execution) is enabled in Tools+ Plug-in. This is great, but in the little textctrl of the tool command it is difficult to write a nice script, it would be great to call a script from there with "dofile()"

good night everybody in CET

Offline Azerty

  • Single posting newcomer
  • *
  • Posts: 1
Re: dofile from squirrel
« Reply #1 on: Yesterday at 10:14:56 pm »
Before using dofile() function in a squirrel script, it's necessary to add the Input/Output library to the squirrel roottable in the C program with sq_pushroottable() and sqstd_register_iolib().
For example, something like that :

main.c :
Code
#include <stdio.h>
#include <squirrel.h>
#include <sqstdio.h>
#include <sqstdaux.h>

HSQUIRRELVM squirrel_open(void)
{
HSQUIRRELVM v = sq_open(0x400);
sq_pushroottable(v);
sqstd_register_iolib(v);

return v;
}
void squirrel_close(HSQUIRRELVM v)
{
sq_pop(v, 1);
sq_close(v);
}
int main(void)
{
HSQUIRRELVM v = squirrel_open();

if(SQ_FAILED(sqstd_dofile(v, (SQChar *)("squirrelScriptName.ext"), SQFalse, SQTrue)))
{
printf("Error\n");
}
squirrel_close(v);
}

squirrelScriptName.ext :
Code
dofile("fileToCall.ext")
« Last Edit: Yesterday at 10:19:03 pm by Azerty »