Was trying to import:


And it looks like “loadstring” isn’t supported. Eep! My concept of serialize-as-code is in jeopardy.

Having said that - there’s a good chance I really don’t know what I’m doing. Is loadstring supported?

loadstring was removed as part of the sandboxing, however I’ve put it back in, as it doesn’t seem that dangerous. It won’t be available until the update following 1.1.2.

I was just trying the same thing. The new save data stuff looks useful, but it would be nice to be able to easily serialise and unserialise data to be able to save more interesting data. All the unserialising code that I’ve found uses loadstring.

loadstring() has been enabled for the next update.


print v

returns 0, not the expected 1. This is in the beta. I’m missing something simple, right?

The goal, incidentally, is to make using a font (it’s always fonts with him!) as easy as



loadstring() loads the string as a “chunk” into the Lua interpreter. You then need to execute it. So your example should be written:

v = 0
loadstring("v = 1")() -- note the function call

You can also do:

v = 0
chunk = loadstring("v = 1")

And so on.

Heh - I figured it was something simple. Thanks!

Sweet - I have data marshalling/unmarshalling working with the code on this page https://gist.github.com/1255382 - it’s a derived version of the code linked above (not mine). More fun - it works unmodified - just load that gist into a blank tab, and

v={"hello", "world"}


return { "hello", "world"}

which means I could do

v = d()

to restore my table. This should work on anything that doesn’t have userdata (ie. an image() will break it) - but I’ve not tested it exhaustively, caveat emptor.

Reminds me of the exec() function in python :slight_smile:

indeed - it’s similar to exec() in javascript or perl as well.

When does this come in handy?

the big thing, the reason I asked for it, is marshalling/unmarshalling data structures. A common way to save a complex data structure to persistent memory is to create the code necessary to re-create that data structure, and save the code - the idea being, when you want to load it back in, all you need to do is grab the block of code and execute it. Without that, saving/loading data means you need to write a save routine, and a load routine, specially for each type of data you want to persist.

An example is spritely - it can save, to persistent memory, the code you need to draw a sprite. That makes it easy for a person to use in their own code - they don’t need to include some custom spritely loader, they just load and execute the code.

Problem is - if you can loadstring() random code, and you can download random code - you can download and execute random code, and apple freaks out about that unless the thing executing the code is their javascript implementation, Sigh. So - the likely scenario is we get loadstring() or sockets - but not both. And given their utility - sockets is way more useful. We can marshall/unmarshall data without loadstring(), it’s just a pain. But without sockets - no talking to the world. And - the world is interesting to talk to.

But @Bortels, you could write a lua interpreter in lua, implementing your own loadstring function, thus allowing the executing of downloadable code. WILL THIS MADNESS EVER END?

I think having the two systems exist independently is probably enough for Apple, though who knows, from our talks with them even they don’t really know what is allowed. It seems to be very much up to the individual reviewer and their rules of thumb.

Dylan - you’re absolutely correct. Which is why I think this restriction is ultimately futile. I think Apple is coming to its senses, slowly… But too slowly for my tastes.

I also think you’re right in thinking Apple themselves don’t know for sure what is allowed and what’s not. It’s what happens when you throw common sense out the window in favor of strict policy guidelines.

Anything sufficiently powerful can be abused - punishing the majority of users based on what some might do is a losing strategy, long run.

e-mail this to them (prior to 1.2.7), it may help

--What is Codea Allowed to do
function setup()
    print("Think of a feature Codea will implement.")
    print("Then, press the red circle to determine if it's allowed")

function draw()
    background(0, 0, 0)
    fill(255, 0, 0, 255)
    if CurrentTouch.state == BEGAN then
        x = math.random(5)
        if x == 1 then print("Why even ask, of course that's allowed.")
        elseif x == 2 then print("That should be fine.")
        elseif x == 3 then print("Yes, there is another approved app that does this.")
        elseif x == 4 then print("Whoa there, lemme check ... oh ya, no prob")
        elseif x == 5 then print("That may have been an issue with iOS 4 but with 5 your good.")

@ipda41001 Perfect!

Hmm… Sockets + LoadString() + File IO = Mahem. Of only apple would really loses up… X(

You don’t really need loadstring() - it just makes it easier.

Ya. But it’s nice… But your right.