Sign in to follow this  

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

This topic is 4860 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
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
Well I got a problem again this time with not understanding the logic of calling a squirrel print() function from C. It turns out that I have to push the argument to print() while that should be handled by the vm. Why do I need to know what some user put into print() as an argument? He could have written print("hello world") and I have to push that from C side. Doesn't sound right does it? I don't understand the following section:


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 world", -1);
if(SQ_FAILED(sq_call(v, 2, 0)))
assert(0);
sq_pop(v,2); //pops the roottable and the function




the sq_pushstring(v, "hello world", -1); this should be done by vm not? In the script I have print("hello") and the output is "hello world" the string I pushed onto the stack. Argg :)

Share this post


Link to post
Share on other sites
I guess this is what you want to do. m'I right?



#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);
if(SQ_FAILED(sq_call(v, 2, 0))) //executes the script you just compiled
assert(0);
sq_pop(v,2); //pops the roottable and the function

sq_close(v);

return 0;
}


Alberto

Share this post


Link to post
Share on other sites
That's how I thought things should work but I get an error when I run it. I basically want to call function print("hello world") from the script and have it output "hello world" to standard output ie. DOS console. I thought I would have to invoke that function from C code but it seems that the script should do that by itself. If I write any function in script and I want to call it from C I understand that I need to push the function name and also its arguments on the stact and then invoke the sq_call(). Then that function is called in script and the script then pushes the results onto the stack that I then can get at from C. Likewise if I call a native function from within my script, my C function will have to pull the arguments from the stack, do the calculations and then push the results onto the stack so that the script can deal with it. Is this how it suppose to work?

The problem now I'm having is figuring out how to execute the script without writing any C stack code which I think how it suppose this to work. Say I write in script:

local a = 1;
local b = 2;
local c = a + b;
print(c);

and I want the script to execute what C code do I have to write for that to happen? I think sq_call() is reserved for the case when I want to invoke a user defined script function? Again, I'm confused, but thanks for hanging in with me :)

Share this post


Link to post
Share on other sites
Quote:

- squirrel renamed to squirrelScript or similar for googling


Actually that would not help, as Google (and many other search engines) does not support wildcards, eg. '*script' or 'squirrel*'. So using that kind of joined word-name, it would be propably harder to find the site.

Now, if someone searched for a scripting language, Squirrel would not be the first, actually it seems that PHP and Python are the first ones. So popularity rules. When searching for squirrels, the first results are about squirrels. (Well, mostly, there seems to be even a porn site in the top 10 results!)

Squirrel script or squirrel scripting will lead the lost programmer to light.

PS. Sorry, i just had to make this reply, the proposal to change the name simply forced me to do this.

Share this post


Link to post
Share on other sites
Maybe when more folks write about it then we get better google search results. Right now you get other scripting langs or things about squirrels and nuts. But I still think that squirrelScript is a better name than squirrel. Perhaps SQScript or something like that too.

Share this post


Link to post
Share on other sites
Docs could be made easier to read if the info about a topic say arrays wasn't spread out in different places. It makes sense to have one topic on arrays and put everything into that including builtin functions. Those functions could still be put into api reference section. I would also like to see this example put into the docs:


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

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

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

sqstd_register_iolib(v);

sq_setprintfunc(v, printfunc);

sq_pushroottable(v);
if(SQ_FAILED(sqstd_dofile(v, "script.txt", 0, 0)))
assert(0);

sq_close(v);

return 0;
}

write in script.txt file:

print("hello");



Ok, I'm going to play with some squirrel code and hopefully I'll decipher the stack issue and what to call and when maybe even looking into lua programming book.

Share this post


Link to post
Share on other sites
Sweet :) I'm going to transfer to forums on your website (not those on sourceforge since there is little input there) and stop writing here. I hope as I learn squirrel I will be able to provide more feedback to you. Other than that issue with setting up the environment so that it compiles my script I have not had much problems with actual learning of the squirrel lang. so far. Keep up the excellent work and thanks for all that hard work :)

Share this post


Link to post
Share on other sites

This topic is 4860 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this