Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

cached data (sockets and persistent storage)

BortelsBortels Mod
edited November 2011 in Suggestions Posts: 1,557

So - I ran across this:

if not love.filesystem.exists("expo.png") then
  local http = require("socket.http")
  local b, c, h = http.request("http://love2d.org/w/images/e/e3/ResourceExplosion.png")
  love.filesystem.write("expo.png", b)
end

In my case, it's font data I'm hankerin to grab and store.

I think the analog with the published API (is this coming in the next update?) is:

fontdata = readLocalData("font", nil)
if not fontdata then
    local http = require("socket.http")
    local b, c, h = http.request("http://raw.github.com/bortels/HersheyCodea/master/romansimplex.dat")
    fontdata = b
    saveLocalData("font", fontdata)
end

Yes, no sockets yet (and presumably they won't be a "require", but that's a placeholder) - but I wanted to publish something concrete as to what I'd like to do. Idea being, look in local store, and if the data needed isn't there, go grab it and cache it for later use. (we can do this in safari/javascript today)

Why am I posting? Memory mostly - now I can forget about this, and I know where to look. Also to see if the data store is in the current waiting-to-be-approved app, and to provide a sample use case. In my case, the font data is binary-safe, but this is why I was asking before if the store would be able to hold arbitrary binary data; I could see doing the same thing with a png and wanting to store it, and that's not 8-bit-clean (and having to based64 encode it would be a kludge).

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,782

    Yes, the data store stuff is in 1.1.2, waiting to be approved.

    If you use readProjectData and saveProjectData, the data would be sent around with your project when you share it. (Each project folder can contain a Data.plist item for key-value data storage.)

    Sockets seem fairly straight forward, it's on the list of things we'd like to have in. We have three big new features implemented (physics, image library, custom sprites), so whatever update comes out after this review process is over will be pretty large.

  • BortelsBortels Mod
    Posts: 1,557

    I don't think I want it sent around (yes, I realize I can choose) - I think I'd rather keep the project size smaller and load data on-demand. I mulled that over as I was writing the sample code. In theory, if it's distributed by the project, I don't need the socket stuff at all - I make a temporary thing in main to build the data into the store, then delete it. I'm still not sure how I feel about that from a code-distribution standpoint - I hate hidden (and therefore not easily re-usable) code.

Sign In or Register to comment.