Page 1 of 2

love.filesystem.mkdir not working

Posted: Wed Feb 11, 2009 8:44 pm
by bartbes
Mostly @rude
When I try to save a binary file all goes well, strings are as long as they should be, but when I call love.filesystem.write it just stops at the first NULL character ("\0"). Something I can do to prevent this?

EDIT:
SWIG manual wrote: The char * datatype is handled as a NULL-terminated ASCII string. SWIG maps this into a 8-bit character string in the target scripting language. SWIG converts character strings in the target language to NULL terminated strings before passing them into C/C++. The default handling of these strings does not allow them to have embedded NULL bytes. Therefore, the char * datatype is not generally suitable for passing binary data. However, it is possible to change this behavior by defining a SWIG typemap. See the chapter on Typemaps for details about this.
EDIT2: I changed the topic title because I didn't feel it was necessary to start a new thread, first post at: http://love2d.org/forum/viewtopic.php?f ... 4436#p4436 (bottom of the page :P)

Re: Binary files with love.filesystem

Posted: Wed Feb 11, 2009 10:12 pm
by Skofo
Do you have any backslashes (\) in your strings? That usually does some weird things if you mean for it to show up as a backslash, because particular backslash and character combinations make special characters (i.e. \n makes a new line). If you want to input a backslash, type '\\' instead of just '\'.

Also, here's a list of other special backslash characters if you need them:
\a bell
\b back space
\f form feed
\n newline
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\" double quote
\' single quote
\[ left square bracket
\] right square bracket

Re: Binary files with love.filesystem

Posted: Wed Feb 11, 2009 11:26 pm
by Merkoth
Or just use Lua's file.io methods :)

Re: Binary files with love.filesystem

Posted: Thu Feb 12, 2009 6:58 am
by bartbes
Skofo wrote:Do you have any backslashes (\) in your strings?
No, I come from C/C++ so I know that, but I didn't enter the string, it is read from another source (the mighty internet)
Merkoth wrote:Or just use Lua's file.io methods :)
That really isn't an option, I'll only use it if I really, really have to.

Re: Binary files with love.filesystem

Posted: Fri Feb 13, 2009 2:04 pm
by bartbes
Bump?

Re: Binary files with love.filesystem

Posted: Fri Feb 13, 2009 2:43 pm
by rude
Sorry, I'm not that agressive on the forums these days. (But your bump worked). There's probably nothing you can do about that at this point. I didn't know SWIG did that.

FYI, I checked up on this:
lua.org wrote: lua_tolstring returns a fully aligned pointer to a string inside the Lua state. This string always has a zero ('\0') after its last character (as in C), but can contain other zeros in its body. Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring will be valid after the corresponding value is removed from the stack.
SWIG has been removed, so I guess this problem is already fixed (in SVN, that is). I'll add it to the "test me"-list. As for a temporary fix: stop needing binary data. :rofl:

Re: Binary files with love.filesystem

Posted: Fri Feb 13, 2009 6:50 pm
by bartbes
Well.. this renders updater unusable... I'll wait though

Re: Binary files with love.filesystem

Posted: Fri Feb 13, 2009 10:06 pm
by Skofo
bartbes wrote:Well.. this renders updater unusable... I'll wait though
Oh man, I'm sorry braw. :(

I'll wait for it too.

Re: Binary files with love.filesystem

Posted: Sat Feb 14, 2009 9:50 am
by bartbes
I guess I'll use io until it is fixed.

Re: love.filesystem.mkdir not working

Posted: Sat Feb 14, 2009 1:24 pm
by bartbes
Again @rude
love.filesystem.mkdir doesn't work, and because I can't find an mkdir in standard Lua (I could swear I've used something like that), it'd be nice if I knew the correct syntax.