Jump to content
  • Advertisement
Sign in to follow this  
fagiano

[ANN] Squirrel 1.0 release candidate 1(RC1) is out

This topic is 5170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all I've just released a new version of Squirrel(release candidate 1). changes log: -fixed division by zero(between integers) -the 'in' operator and obj.rawget() do not query the default delegate anymore -added function sq_getprintfunc() -added new standard library 'auxlib'(implements default error handlers) Squirrel is a light weight programming language(6K~ lines) featuring higher-order functions,delegation,tail recursion,generators,cooperative threads(aka coroutines),exception handling, reference counting and garbage collection on demand. C-like syntax. ciao Alberto

Share this post


Link to post
Share on other sites
Advertisement
I got a problem. I would like my script to execute print("hello") squirrel built in function but don't know how to do it since the vm is bombing on me most likely because I missed something. I'm having very difficult time to get my head around squirrel. This is my C code:


#include "stdafx.h"
#include <squirrel.h>
#include <sqstdio.h>
#include <cassert>
#include <cstdio>

SQInteger file_lexfeedASCII(SQUserPointer file)
{
char c;

if(fread(&c, sizeof(c), 1, (FILE*)file) > 0)
return c;
return 0;
}

int compile_file(HSQUIRRELVM v, const char *filename)
{
FILE *file = fopen(filename, "rb");

if(file)
{
sq_compile(v, file_lexfeedASCII, file, filename, 1);
fclose(file);
return 1;
}
return 0;
}

int main(int argc, char* argv[])
{
HSQUIRRELVM v;
v = sq_open(1024); // creates a VM with initial stack size 1024

// do some stuff with squirrel here
if(!compile_file(v, "script.txt"))
assert(0);

if(SQ_FAILED(sq_call(v, 1, 0)))
assert(0);//<-- bombs right here

sq_close(v);

return 0;
}




Oh, I also found a bug in docs. In the section where it talks about embedding squirrel the FILE *f should be renamed to FILE *file like I have above. Also, I took out ret variable from the file_lexfeedASCII(), it doesn't need to be there. Probably was a straight copy from the squirrel lib source code.

Can also someone explain to me how this whole squirrel system works? The docs are really terse. I would also like to see C code examples so I wouldn't have much problem testing stuff like the case above. Thanks.

Share this post


Link to post
Share on other sites
Things I would like to see in future:

- squirrel renamed to squirrelScript or similar for googling
- html crosslinked docs for easier/faster navigation
- dll libs (single, multi, dubug, release) like genesis3d did
- runtime GC flag
- much more info in the docs to lead newcomers like me
- more C example code
- promote some sqstdlib functions to main codebase
- provide zip package for windows users (get ZipCentral)

I should not be required to recompile squirrel when I go from debug to release build of my app. Good work so far :)

PS. Is sourceforge really pissed at MS or something? It bombs my IE6 all the time, spent like hour trying to download the files yesterday. Almost gave up! Can't you host them on free tripod account instead? You get 20megs and several gigs of bandwidth. Just wondering.

Share this post


Link to post
Share on other sites
Yay! html docs can be scratched out. I found chm docs on your website and like them so far. That's exactly what I was asking for.

Ofcourse, google yield no results, only nuts :) I did a search on gamedev and a post came out while ago discussing some asm technique that would hide the stack. I would love to see this whole scripting thing simplified if possible. Throw in a good IDE with debugger and C++ bindings and we're in heaven :)

Share this post


Link to post
Share on other sites
Quote:
Original post by JD
Things I would like to see in future:

- squirrel renamed to squirrelScript or similar for googling

No way, that would just destroy it! heh


Anyway, keep up the good work fagiano, Ive been following Squirrels development for a few months now and must say I really (REALLY) like it. Its exactly what ive been looking for in a scripting language (so far), though the embedding could be streamlined a small bit (I guess the Squirrelator does that though).

Just thought Id post to say "Way to go, fagiano. Keep it up."

Share this post


Link to post
Share on other sites
I'm simply trying to call print("hello") from my script file. Here's my code so far and I added a portion to it but still not quite understand it all. I'm looking at lua docs but they're a bit different in this respect. Hopefully someone can butt in and give me some heads up. Oh forgot, the code now works, no errors. However "hello" string doesn't show up in the console. Strange. God I hate this stack thing - just frustrated, ignore me :)


#include "stdafx.h"
#include <squirrel.h>
#include <sqstdio.h>
#include <cassert>
#include <cstdio>

SQInteger file_lexfeedASCII(SQUserPointer file)
{
char c;

if(fread(&c, sizeof(c), 1, (FILE*)file) > 0)
return c;
return 0;
}

int compile_file(HSQUIRRELVM v, const char *filename)
{
FILE *file = fopen(filename, "rb");

if(file)
{
sq_compile(v, file_lexfeedASCII, file, filename, 1);
fclose(file);
return 1;
}
return 0;
}

int main(int argc, char* argv[])
{
HSQUIRRELVM v;
v = sq_open(1024); // creates a VM with initial stack size 1024

// do some stuff with squirrel here
if(!compile_file(v, "script.txt"))
assert(0);

sq_pushroottable(v);
sq_pushstring(v, "print", -1);
sq_get(v, -2); //get the function from the root table
sq_pushroottable(v); //’this’ (function environment object)
sq_pushstring(v, "hello", -1);
if(SQ_FAILED(sq_call(v, 2, 0)))
assert(0);
sq_pop(v,2); //pops the roottable and the function

sq_close(v);

return 0;
}


Share this post


Link to post
Share on other sites
by default squirrel does have a print function in the vm, you got to give him one at initialization time, so you can ridirect your output where ever you want(in the game console for instance).
this is another thing that should be more clear in the doc.

search for sq_setprintfunc() in the doc :)

ciao
Alberto

Share this post


Link to post
Share on other sites
Ok, I have added this to my C code:

int main(int argc, char* argv[])
{
HSQUIRRELVM v;
v = sq_open(1024); // creates a VM with initial stack size 1024

sq_setprintfunc(v, printfunc);// added
//blah......
}

then defined my printfunc like so:

void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
{

}

not sure what I should write inside it though. It looks like a variable argument function in which case *s will give me number of arguments. Is each argument a character? Because if I simply do this: printf("%s", s); I get %s as output instead of hello string. Should I instead be doing something with the v? Confused as always:) Thanks for replying to my post, much appreciated.

Share this post


Link to post
Share on other sites
take a look at sq.c


#include <stdarg.h>

void printfunc(HSQUIRRELVM v,const SQChar *s,...)
{
va_list vl;
va_start(vl, s);
scvprintf( s, vl);
va_end(vl);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!