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.
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"}
d=DataDumper(v)
print(d)
gives
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.
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.
--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")
end
function draw()
rect(0,0,1,1)
background(0, 0, 0)
fill(255, 0, 0, 255)
ellipse(WIDTH/2,HEIGHT/2,WIDTH,WIDTH)
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.")
end
end
end