Welcome Guest Search | Active Topics | Log In | Register

#1 Posted : Friday, May 13, 2011 5:11:20 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/13/2011(UTC)
Posts: 7
Location: Canada

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
Hi squirrel community!

I have a question about sq_compilebuffer. Right now I have some code looking like this in my program,

void ScriptEngine::run_script(char* cmd)
    SQInteger oldtop = sq_gettop(v);
    sq_settop(v, oldtop);

void printfunc(HSQUIRRELVM v,const SQChar *s,...)
    std::string text;
    static SQChar temp[2048];
    va_list vl;
    va_start(vl, s);
    scvsprintf( temp,s, vl);
    text = temp;

this works fine for commands such as print (1);

however, when I try "local p = print;" and then call p (1); it says THE INDEX 'P' DOES NOT EXIST.

or if I use sqstd_dofile, it will compile and run the script fine, but same thing happens when I try to call a function it says the index does not exist.

I must be missing something, can someone offer some advice?


#2 Posted : Tuesday, July 4, 2017 9:32:26 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
I think it's because sq_compilebuffer pushes the code as a function, so when you define p in one call, and then try to print it in another, it's like this:


function a(){
  local p = print;

function b(){

Because p is defined in a() and not in b(), you get an error. If you want to use the same things between calls, you'll have to call something that's in a scope or define new things in the global scope. At least, that's what it looks like to me.
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.070 seconds.