loadstring

@Bortels Sorry for reviving an old thread but above you mentioned that the DataDumper revised code:

 More fun - it works unmodified - just load that gist into a blank tab, and...

So, as a clueless neophyte, I’ve just tried pasting said unmodified code into a blank tab and found (before I even tried invoking the function in main) that the code choked on this line:

if totallen ]] > 80 then

with a – ‘then’ expected near ‘]’ – error.

Any ideas? Does the DataDumper function still work for you?

TIA Mr. Bortels!

Hmm - it worked for me when I posted it…

Looking at the gist, the only line I see that comes close to what you posted above is line 256

            if totallen > 80 then

Only thing I can think is maybe something got funky with the cut and paste? Try it again - the code that’s there worked for me.

I’ll try again… ah thanks!.. it now runs… mea culpa, you were right there must have been something funky with my cut and paste… :slight_smile:

However… now when I call DataDumper (using your {“hello”, “world”} table for testing) Codea protests its confusion concerning getfenv(), a function which, at least according to Mr. Zoyd’s recent posts, is under embargo in the sandbox file.

@Bortels did you not encounter this problem?

@Simeon is getfenv() dangerous?

Must I live dangerously to serialize/save tables and functions with up-values?

Edit: Thinking about this a bit I can imagine the ability to serialize tables and functions might be a giant step beyond loadstring on Apple’s slippery slope.

It worked when I posted it; a quick google (all that I have time for right now, I’m on the way to work) suggests this was removed in Lua 5.2? (and I think the Lua Codea uses was upgraded between then and now, although I’m not sure.) I’m also not sure how relevant that call is in the iOS/Codea context anyway - I suspect it could be stubbed out or otherwise dealt with. Keep in mind - I did not write the code in question, I just found/ported it, and as I noted the port was trivial, code being basically unchanged - there’s still very deep voodoo in it I won’t claim to fully understand.

I believe - again, based on a quick scan - that this chunk of code only deals with “userdata” - in our case, things like image() and mesh(). If your data structure is a pure lua-element-only table, I suspect this chunk of code could simply be commented out.

I’m pretty sure that Codea hasn’t upgraded to Lua 5.2 yet. But thanks for your reply Mr. B. I’ll keep at it!

Confirmation: Codea is only on 5.1 :frowning:

Our libraries (vec2, image, mesh, and so on) are not compatible with 5.2. We haven’t got around to re-working them.

@Blanchot getfenv is not dangerous. None of the sandboxed functions are really dangerous — we’ll probably expose some more in the next release.

Well - if it’s not Lua 5.2, my only other thought is that they must have sandboxed that function at some point, because I promise - the code worked for me when I posted it. Scout’s Honor. Or, maybe I just never tried using it on something that triggered that call?

No idea.

we'll probably expose some more in the next release.

@Simeon that would be swell! (hopefully getfenv in 1.3.1?)

@Bortels the call to getfenv() was triggered using your own {“hello”, “world”} example! But hey… no problem. Thank you for all your help. :slight_smile:

Edit:

I believe - again, based on a quick scan - that this chunk of code only deals with "userdata" - in our case, things like image() and mesh(). If your data structure is a pure lua-element-only table, I suspect this chunk of code could simply be commented out.

As far as I can tell (I hope I am not saying something stupid here-- my understanding of all this is rudimentary to the extreme) the chunk of code in question allows the dumping of closures with the up-value preserved – a feat which string.dump can’t do in 5.1. (I believe it is possible in 5.2 but only with a reset up-value.)

What can I say? It worked when I posted it. Codea has changed in some way since then.

@Bortels is probably right that something has changed.

However the sandbox has only changed twice — once in 1.1.2 to allow os.time/clock functions and again in 1.2 to allow loadstring().

@Blanchot - You know how to enable getfenv(), right? I did it :slight_smile: Just see my discussion on how to enable file io.

And please don’t disable LoadString (although I’d rather sockets than LoadString) because I was looking into making a Codea Jr. kind of like Scratch (look it up). You would drag in little chunks of code, and it would execute them when you press run. I’d also integrate a few other librarys out there.

@Zoyt thanks I’ve seen your thread. You might think me crazy but I’d rather keep my system kosher if possible. Especially as a lua/Codea newbie. But again thanks!

Ya, I hack around with Codea a lot… It doesn’t seem to affect anything else. I do it for fun… Mainly. And I don’t think you’re crazy… You might as well call me crazy. :slight_smile: