YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Cannot write multiple closures to file
Kelvin
#1 Posted : Sunday, May 7, 2017 3:17:05 AM(UTC)
Rank: Advanced Member

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

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
So, when I use sqstd_writeclosuretofile(), it only writes the last closure loaded, and if I use it immediately after each source file I load, it overwrites instead of adding the bytecode to the end of the output file. Does anyone have a workaround for this?
absence
#2 Posted : Wednesday, May 10, 2017 9:13:47 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 109
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
ehm... what about doing it YOURSELF? ;-P

sqstd_writeclosuretofile is these few lines of code:

Code:

SQInteger file_write(SQUserPointer file,SQUserPointer p,SQInteger size)
{
    return sqstd_fwrite(p,1,size,(SQFILE)file);  //which basically is fwrite on a FILE* as of stdio.h
}
SQRESULT sqstd_writeclosuretofile(HSQUIRRELVM v,const SQChar *filename)
{
    SQFILE file = sqstd_fopen(filename,_SC("wb+"));   // sidenote: wb+ -> overwrite. See C fopen()
    if(!file) return sq_throwerror(v,_SC("cannot open the file"));
    if(SQ_SUCCEEDED(sq_writeclosure(v,file_write,file))) {
        sqstd_fclose(file);
        return SQ_OK;
    }
    sqstd_fclose(file);
    return SQ_ERROR; //forward the error
}


As you can see it's almost dead simple.
sq_writeclosure just needs a callback function to pass binary chunks to work on (Note that the passed "file" is a SQUserPointer, so it's not necessarily a file write you have to do!)
Have a look at it's API docs

1 user thanked absence for this useful post.
Kelvin on 5/18/2017(UTC)
VoidSpirit
#3 Posted : Thursday, May 11, 2017 8:01:19 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 7

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
sqstd_writeclosuretofile writes a closure on the top of stack. You must put other closure to stack by any according operation and use this function.
Also use sq_writeclosure to write a closure with optional writing function.
1 user thanked VoidSpirit for this useful post.
Kelvin on 5/18/2017(UTC)
Kelvin
#4 Posted : Friday, May 19, 2017 10:04:53 PM(UTC)
Rank: Advanced Member

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

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
OK, so it's putting all the closures into one file now, but it only executes the first one. I have two files, one the actual program I wrote, and the other being just a print statement that should show up when the program exits, but the print is never executed. I can't tell if it's inserting an EOF character or something, because when I open it in Notepad++, I get a ton of crazy symbols, but I can also see the string "end.nut" towards the end, as well as "This should show up in the final output." from my call to print().

There's no errors in the Squirrel code itself, either, so I put one in on purpose. It gives an error message, even mentioning the original source file by name and what line the execution stopped at.
Users browsing this topic
Guest
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.132 seconds.