Howdy, Stranger!

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

1.3.7 beta

BortelsBortels Mod
edited March 2012 in Beta Posts: 1,557

W00t!

I am converting over some of my old socket stuff (never delete anything!) - I'll let you know how that goes.

any chance of getting mime (specifically, mime.unb64 and mime.b64)? I think I have code somewhere to do it, but better if it's built-in. (Ditto for URLencode/decode, probably, but that's just thinking ahead)

I am having rotation issues with my ipad, noticed the Network docs run off the right when you're in portrait mode. (Doh! rebooted, tried in landscape, still cut off)

If you do not provide a fail function, I assume it fails silently?

Comments

  • BortelsBortels Mod
    Posts: 1,557

    Seeing a weird problem with text() and WIDTH.

    I'm in landscape mode - WIDTH is returning 768 (with the console, makes sense).

    but "text("Hello", 0, HEIGHT/2)" comes out under the console - "0" for text is still apparently the far left of the screen under the console. Adding 350 seems to put it in the right place.

    Same issue in portrait, but the console is thinner so 350 isn't the right offset.

  • Posts: 447

    ohhh this is htttp.get is a big one!

  • BortelsBortels Mod
    Posts: 1,557

    Yup. Working beautifully, btw.

    Of possible interest: http://lua-users.org/wiki/JsonModules

    (I started writing a cool "show me recent #Codea twitter posts, all floaty across the screen", and it's all coming back as JSON, which is fine, but we need to parse it...)

  • BortelsBortels Mod
    Posts: 1,557

    Hmmm.

    Push notification. It would be handy. Ideally in a way such that the push notification would let you touch it, open up codea, and autorun a project. Just thinking out loud. The type of game I want to make in the long run is scheduled (ie. turns run every day at noon, for example), so notification isn't important. But for other turn-based stuff (Hero Academy is the model there) it would be darn handy. (I plan on faking it with either email or SMS messaging, both of which are doable server-side).

  • BortelsBortels Mod
    Posts: 1,557

    After messing with it for a while, http.get stopped calling either return function. Other apps (safari anyway) continued to work. Had to kill and restart codea to make it work again. Trying to reproduce.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    Thanks for all the feedback, @Bortels — It's really helpful!

    Interesting about the text bug — the view doesn't even extend under the console so I'm not too sure what's happening there.

    Push notification is very tricky and might be against Apple's rules. As the service is provided on a per-app basis. It would probably have some server requirements on our part.

    The last one sounds like a state bug with the HTTP request framework, will look into it.

    Mime may make another appearance. Note, though, that we will be handling PNG and JPG decoding transparently so you won't have to.

    E.g.

    http.get( "http://twolivesleft.com/Codea/logo.png", 
              function( img, s, r )
                  -- Here img is actually an image() type
              end )
    
  • BortelsBortels Mod
    Posts: 1,557

    Good on the handling of PNG and JPG automatically. I was gonna say "GIF too", but meh - it's easy enough to convert, really, and technically PNG is superior.

    In this particular case, I was grabbing font data (sockets were a looong time ago!) for the Atari font; the base 64 isn't a killer, it's not that hard to implement. The rest of mime isn't as exciting.

    The workaround for push for us end-users is to grab a free texting app - many of them support receiving a push notification via email (you email to the company who pushes to the app).

    Been waiting for this for a while - my brain keeps jumping from "ooh, do this" and "ooh, do that" with http.get. I may do the twitter thing - it's pretty straightforward, and might make a good demo of using this (and maybe of JSON, although I might just fake it for this case) in a non-trivial application. Unless I get distracted :-)

  • BortelsBortels Mod
    Posts: 1,557

    Feeling stupid right now.

    After some research, this seems to be the "best" json encode/decode out there - http://chiselapp.com/user/dhkolf/repository/dkjson/home - best meaning "pure lua, reasonable license, well documented". Your best may vary.

    One thing I like about it from a traditional sense is it doesn't pollute the global namespace - you do 'json = require("dkjson")' and now use the json object to access it.

    But - we don't "require" in Codea. I'd normally make this into a class and have you instance it, but it feels... inelegant? Point being - there's got to be an idiom to say "treat this tab like a file and require it". It's maybe automatic - but I need that object it references.

    I'm sure I'm just missing something stupid. And - if I'm not - we need some way to do just this. There's lots of good libraries out there we can and should be using, and to have to wrap them up is not viable long-run. One of the core strengths of Codea is underneath, it's bog-standard Lua - so there must be some way to do standard lua things.

    Server side, I'm looking at a simple node.js front-end to redis for what I'm working on - I'll share details as soon as I have a working proof-of-concept. The idea is that the Codea app can poll state of objects via http.get (ships, planets, etc), post changes (orders), and a server-side engine (probably in perl) will periodically update them (daily).

  • SimeonSimeon Admin Mod
    Posts: 5,387

    That sounds pretty cool (the space simulation).

    That JSON module looks really nice, thanks for finding it! "Require" wouldn't be necessary if we were to include it by default. I don't think there's any harm in having a global json library for parsing assistance.

  • BortelsBortels Mod
    Posts: 1,557

    Including the json library I found (or another good one) is an excellent idea.

    But - my question/suggestion still stands - is there a good way with Codea now to do the functional equivalent of "require" with a tab, without wrapping it up as a class? And - if there's not - adding one would make a ton of good stuff more easily accessible.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    If it's a tab it will just be loaded straight into the Lua interpreter — so a "require" is not necessary. I think I'm missing the point, require() works with code, but you want something for data files?

  • BortelsBortels Mod
    Posts: 1,557

    The json library is written with the intent in normal Lua that you invoke it with:

    json = require("dkjson.lua")
    

    This gives you a json object that you can use to json.decode() and so on.

    What I'm wanting to do is drop a "required" file into a tab, then simulate the "require" call, such that I end up with an object that's the result of the require() call. I just haven't dived deeply enough into Lua's guts to know what that actually entails, or if it's even feasable to use a Codea tab in that manner. I can always wrap the whole thing up in a Class, but it's inelegant - it is desirable to be able to grab code off the net and use it in the manner it's intended to be invoked in (ie. require() returning an object).

    The end goal being making it easier for a desktop Lua user to go to Codea - I want to be able to say "If you have a chunk of code that you'd normally use with require() - here's what to do in the Codea environment", and ideally NOT have it be "modify the code by wrapping it up in a class".

    In the case of the json library, the require() is the mechanism by which an object is created that acts as a "handle" for that library's invocation. If I just drop it in a tab, that object isn't created.

  • BortelsBortels Mod
    Posts: 1,557

    So - I'm trying to make an authentication mechanism that will be reasonably secure without https (because http.get() doesn't support SSL - right?)

    And I'm having problems without some sort of secure hashing function (I plan to implement basic APOP).

    Any chance we could add an MD5 library? Most of the variants I find out there are coded in C for speed. It won't slow me down to not have one, but the game will be trivially hackable by anyone sniffing it (maybe I'm paranoid...)

  • SimeonSimeon Admin Mod
    Posts: 5,387

    I typed this yesterday, but stupidly forgot to press "Post Comment"

    All "require" does is set the variable to the result of evaluating the specified Lua file.

    For example, you'll notice the JSON library is formed as follows:

    local json = { some table }
    
    -- Lots of implementation
    
    return json
    

    So "require" is similar to just evaluating a chunk of Lua code (in a file or string) as a function.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    I'll have to ask @Dylan about whether http.get supports SSL. I'll think about MD5, or maybe just adding SSL support to http.get instead.

  • BortelsBortels Mod
    Posts: 1,557

    SSL support would be nearly as good for my particular use-case, and FAR better for many others. (I can fake my way around it missing - but there are other cases where that can't happen).

    So the take-away is that instead of "require", drop the library in a tab and look for the return and simply make that global? Ok. I guess that makes sense. I'll give it a shot. (I've since abandoned json because my needs are way simpler, but it's still gonna be handy).

    I'm coding my server-side tonight, or that's the plan - but I'm also going to pick up my new iPad, so we'll see what wins. :-)

  • SimeonSimeon Admin Mod
    Posts: 5,387

    @Dylan tells me it should support https, let me know if you have any issues with it.

    For require you could add the following lines to the library:

    At the start:

    function createJSONParser()

    At the end:

    end

    Then you can do:

    json = createJSONParser()

    Require is more sensible, but doesn't really work with concept of tabs — as they are loaded automatically.

  • BortelsBortels Mod
    Posts: 1,557

    I'll give both a shot - restoring my old ipad to my new one now.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    If you have a new iPad you will need to register the device with TestFlight — then the next build of Codea will be compatible (I will need to add your device ID to the provisioning profile).

  • BortelsBortels Mod
    Posts: 1,557

    Yep - I'll register, and post.

  • BortelsBortels Mod
    Posts: 1,557

    Ok - re-registered, waiting on your permission for testflight to install.

  • SimeonSimeon Admin Mod
    edited March 2012 Posts: 5,387

    I have to actually make a new build of Codea for it to work on your iPad. So when the next build comes out it will be compatible.

    Edit: Can I remove your old iPad from provisioning? Or will you still be using it?

  • BortelsBortels Mod
    Posts: 1,557

    Okeydokey. Gave the old iPad to the wife, doubt she will want to hack codea much :-) so sure, nuke that one. I'll work on my server side while waiting for the next build - plenty to do there...

  • BortelsBortels Mod
    Posts: 1,557

    Off topic but not worth a new thread.

    Looking for stuff for the new iPad, a genius recommendation pointed me to "python for iOS" (I dislike python - any language that has syntactically-significant white space is damaged on launch)

    Their first screenshot shows it doing a http get. :-) so if apple gives you crap - prior art. Not that it'll help.

    There's also a processing clone based on processing.js out there, I won't try to type the name because it's all "leet".

  • Posts: 2,161

    I dislike python - any language that has syntactically-significant white space is damaged on launch

    guess you're not a TeX fan, then

  • BortelsBortels Mod
    edited March 2012 Posts: 1,557

    I... I don't know TeX. /hangs head in shame

    Never had a need for what it offers - heck, I never needed to go beyond ASCII, truth be told. You should see my web pages. They are... Spartan.

    I'm not sure it counts, though. TeX is largely formatting, yes? No?

    The issue with significant white space is that it's just to easy to screw up scope, unless you're using an IDE, or it has been for me at least. Is it prettier? Perhaps - but pretty at the expense of robustness doesn't strike me as a great trade. Besides - in vi, I'm addicted to jumping between matched sets of brackets, which you can't do without brackets, oddly enough.

    I have the same issues with coffescript. Prettier than JavaScript? Yes! Easier to write? Certainly! Subject to weird errors because I screwed up spacing somewhere? Yep.

    Languages should save me from myself by design, not force me into an IDE to do it. My opinions.

  • BortelsBortels Mod
    Posts: 1,557

    I am contemplating http Cookie support.

    It would help my pet project. That's not a deciding factor, nor should it be.

    But - it may be useful. Lots of sites can and do use cookies for authentication and session handling (both of which are why I'm looking at it).

    Before I make the SSL error again - maybe it's already built-in and I just don't know about it? If it's there, I'll code the server side expecting it, and if it's not - I need to decide if it's worth implementing on the client side to make the server side easier, or if it's better to implement something special server side.

    If not, no monster biggie - it is straightforward enough (if not simple) to roll our own.

  • BortelsBortels Mod
    edited March 2012 Posts: 1,557

    O. M. G.

    You have NO IDEA what a relief it is to be able to just load a graphic without having to monkey with encoding it and cut and paste and whatnot.

    Out of curiosity - does it decode based on the actual binary content, or mime type?

    Anyway - working beautifully. It's startling how small these icons I've been using are on the retina display. I have one ( http://home.bortels.us/images/fighter.png - and yes, that's a nice alpha-blended shadow.) that I've been using as a test image for various things throughout the years, and on my computer it's goodly-sized - a good 4 cm wide. On the retina display, it's like maybe 1.5 cm (my home screen is an ancient Cinema Display. I don't want to say what I paid for it, it's grim. But - I've been using it for... 8 years? and it's still nicer than what I use at work...)

    Because I'm sharing - got sessions and authentication working on my server side, time to make a client in Codea. So I'll be exercising SSL and post and that jazz. It's gonna be fun. :-)

    Ok - trying https, just got back "SSL problem (possible causes include a bad/expired/self-signed certificate, clock set to wrong date". Well - the server cert is self-signed, so that's what that is. I had expected that might come up - is there a way to say "ignore the server cert validity" (ie. "curl -k") or to give it a Cert Authority to use?

    also - is there a way to set a timeout? It's async, so I could simply watch the elapsedtime and punt, ignoring the result if it came back after timeout, but that's... inelegant?

    (BTW - async with callbacks is so the way to go, good call; it's eliminated a ton of issues that I was running into back in the olden days with sockets and blocking calls)

  • BortelsBortels Mod
    Posts: 1,557

    Heh - when I try to print the image returned from a http.get - it tells me it's a table.

    but when I try to iterate pairs, it tells me it's userdata.

    I'm just trying to figure out how big it is so I can see if we're keeping it compressed or uncompressed, in preparation for trying to marshall them out to local storage (which will be an issue if they're an odd userdata type).

    Or maybe I'm doing something wrong - I'm pooped.

    I guess I could just try saving them off and loading them back, and see what happens.

    so - now that I've got my precious graphics, it would be nice to be able to save them locally to avoid the lag in loading them (and the load on a server), and maybe to allow offline play, although my particular app will... well, I guess I could set it so you could play offline, or at least view the saved state...

    So yeah - saving graphics. Not a showstopper, I can just load em.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    Glad it's working for you!

    It's based on the binary content. I believe it supports a pretty large range of image formats, too (all iOS supported formats).

    I'll have to speak to @Dylan about the certificate possibilities and timeout.

    Yes — if we ever do a blocking-call version we will enforce a modal interface (i.e. progress bar + cancel button for the user). And the developer won't have control over whether that appears during a blocking call.

  • Posts: 159

    Now that it's so easy to pull images into Codea, I started my first little project that uses external resources. I'm porting Flixel's FlxInvader example over to Codea. Images are loaded directly from FlxInvader's Github repository :)

    Current progress:

  • BortelsBortels Mod
    edited March 2012 Posts: 1,557

    I am almost thinking for a modal "simple" image fetch, we're better off doing it in user-land. It would mean that someone who wanted to could just tweak the class. On the whole, I think we're better off with as much source as possible exposed - some sort of library management (or simple file I/o and require) seems more and more useful.

    iOS huh? I wonder if svg will work. I'll have to try.

    I think something like an image loader may just fall out of our stuff - the need will be universal.

    @frosty, I love the concept of simply hosting from github!

  • BortelsBortels Mod
    Posts: 1,557

    so, confirming gif and jpeg work, and svg does not.

    Mind you, I didn't expect svg to work, but I was an optimist :-)

    I was also happy to see it supports all the image() stuff, including .width and .height.

  • BortelsBortels Mod
    Posts: 1,557

    Can I set the .data for an image? the http.get does, clearly. I was to as well.

    I'm still on caching an image locally - I like the concept of putting images up on github or imgur, but I want to avoid hammering them and hitting rate limiting. So - I want to save off loaded images to persistent storage.

    I see if I have image "i", I can do i.width and i.height, and the docs say i.data will have (if I read it correctly) the encoded jpeg/png (and I assume gif). That's good - that will be the smallest practical representation. I can take that, b64 encode it, and save it to persistent storage.

    Question is - can I load it back in? In other words, can I assign to image.data? and if I do, will it decode and display properly?

    The answer appears to be "no" - but maybe I'm doing it wrong. Here's the code chunk (this is my "on success" callback):


    function success(body, result, headers) s = body ss = image(s.width, s.height) ss.data = s.data end

    Note this doesn't work. Indeed - ss isn't even an image, it's nil after the above fun.

  • BortelsBortels Mod
    edited March 2012 Posts: 1,557

    Following through with a threat of wrapping the async up behind a nice modal interface:


    ImageLoader = class() function ImageLoader:init()     self.base = "http://github.com/bortels/planets/raw/master/images/"     self.loadimg = "Planet Cute:Brown Block"     self.loading = 0     self.imgs = {} end function ImageLoader:fetch(tag, name)     self.imgs[tag] = self.loadimg     http.get(self.base .. name, self:newsuccess(tag))     self.loading = self.loading + 1 end function ImageLoader:newsuccess(tag)     return function(body, result, headers)         self.imgs[tag] = body         self.loading = self.loading - 1     end end

    Closures! /flex

    I need to find a better built-in "loading" graphic.

    Call with:


    function setup()     iload = ImageLoader()     iload:fetch("f", "fighter.png") end function draw() -- regular draw stuff here     sprite(iload.imgs["f"], 300, 300) end

    If you don't want to view the "loading" graphic, you can check iload.loading and display a loading screen...

  • SimeonSimeon Admin Mod
    Posts: 5,387

    I am thinking we might allow modal loading of images through the following interface:

    sprite( "http://url/to/image.png", x, y, w, h )

    This will not render anything until the data at the URL is downloaded and cached. So images will pop-in some time after running. This might be okay for quick uses. Alternatively we could add a temporary loading image, but that won't have the correct width and height until after download.

  • BortelsBortels Mod
    edited March 2012 Posts: 1,557

    Add a placeholder image to that call, and an optional "ok it's loaded" callback, and that would support most uses.

    How would you handle an update? Would you (could you) send a "If-Modified-Since" header? Honor the "Expires" header (which would mean caching it along with the image)? Would you (could you) have a method to clear or expire (or examine!) the image cache? Ideally, you'd be able to show the image cache (perhaps for a given domain name) as a spritepack...

    The code I have above is short enough that when someone says "I don't understand how to do a http.get to get images", they can just be pointed at that (or ideally at a demo project that handles image fetching in an asynchronous manner elegantly).

  • JohnJohn Admin Mod
    Posts: 625

    I'm working on the api for loading and saving images in and out of sprite packs. For now there is a Documents sprite pack, which lets you save and load images from the apps documents directory, which will also be exposed in iTunes file sharing. There is also the Project sprite pack, which saves and loads them inside the project itself.

    The api is as follows:

    -- load a from a sprite into an image
    docImage = readImage("Documents:Image")
    
    -- save an image back again
    saveImage("Documents:someImage", someImage)
    
    -- list all images for a sprite pack (returns an array with all the sprite names)
    spriteList("Documents")
    
    -- change project icon
    saveImage("Project:Icon", image)
    

    The built in sprite packs can be read from but not modified (they are read-only). The intention is to give users many avenues for getting sprites in and out of the app. I imagine that someone could write a simple piece of code to bootstap an app by downloading images into its project sprite pack to make it easier to share an asset rich project.

  • BortelsBortels Mod
    Posts: 1,557

    The sprite save/load API looks dandy!

    And you hit it on the head in the last line - idea being when we made cosmetic changes in an app (for mine, adding new ship/race/planet graphics), it's not a code change - we grab the new graphics, persist them, and move on.

    This ability (http.get an image and persist) completely removes the ugly concept of cut/paste reams of encoded binary data for graphics. It's awesome and long-anticipated.

  • BortelsBortels Mod
    Posts: 1,557

    Hey, when you're name-checked in a beta, you gotta check it out, right?

    • John has implemented a Project quick search feature. (Bortels, this might be of interest to you.)

    It took me a while to find the icon, hidden in plain sight - very nice! I can stop naming projects I'm currently working on 1-something :-)

    This is tremendously helpful - I can see all the way down to the C's (I have a lot of projects), and the scroll to the T's is like a swipe, not 15 of them. Bravo!

    I was going to suggest multiple columns, but they still wouldn't all fit on the screen. Maybe an icon grid with smaller text (but that starts to smell very close to the ipad's normal app screen, and Apple may get bunched...)

    I forget - can we set a project icon yet? I'll go look.

  • Posts: 159

    @Bortels: how about an alphabetic index down the side of the list?

  • BortelsBortels Mod
    Posts: 1,557

    Oh, like a skip forward scrolly thing (like contacts for example)?

    Sounds good, but I won't use that - fingers too big, in general. The way it's implemented now in the beta is light-years better than it's been.

    Just pie-in-the-sky - maybe a way to mark "favorites", or sort by most recently modified, as well as alpha? That would keep active projects toward the front of the list.

  • Posts: 159

    @Bortels I mean in addition to the current tableview in the beta - so, you have the searchable scrollable list, and it has an index down the side so you could quickly jump to a particular letter if you want.

    Yeah, perhaps an alternative sort (between alphabetical and most-recent) could be good... Don't want to clutter the UI too much though! :)

  • BortelsBortels Mod
    Posts: 1,557

    So - the world is a weird place, and lua wraps back around to itself.

    I was working on my game, server side, and have been thinking that I really need to do that in lua as well, because the combat routines want to be portable, so they can be used server-side to decide combats, and client-side to show them like a movie.

    And if I'm doing server-side lua to host the turns, I may as well go full-bore and do the webserver in lua as well (it was/is in ruby using sinatra right now - highly recommended) so that I can share even more code (in this case, the redis I/O and procedures). So I start digging into lua stuff, and come across:

    http://luvit.io/

    That is, in a nutshell, node.js (which I like, except I'm not keen on javascript) using lua instead of javascript (neat!). Problem is, there are no redis bindings for it, yet. And I'm thinking of doing my own, but we're starting to get into yak-shaving territory, not game building.

    But - as I was researching things, I came across this thread:

    http://lua-list.2524044.n2.nabble.com/ANN-Luvit-Lua-UV-Jit-NodeJS-re-implemented-in-Lua-td7048032.html

    That suggests, among other things, that the old callbacks stuff I did, for example in the code above, is sub-optimal - that lua coroutines are the way to go, giving you the power of async callbacks, without the callback confusions/complexity (and I'm getting that big-time).

    Problem is - I don't understand coroutines well enough to actually understand how that would work, and can't find good examples.

    I'd like, very much, for there to be good example code if/when http.get is approved - and if coroutines are the way to go, I'd like to try to get my head wrapped around it and "do it right".

    So - is anyone here lua-savvy enough that you say "oh, yeah - coroutines would do that easy! Look, here's how..." and be able to post a small example? I think I just need a gentle push. I'll keep reading, and maybe going back to "normal" coroutine stuff rather than callback related - but if this is easy/trivial for someone already, a good example would be much appreciated.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    gunnar_z posted quite a good coroutine example set just recently:

    http://twolivesleft.com/Codea/Talk/discussion/818/coroutines-examples

  • BortelsBortels Mod
    Posts: 1,557

    You're right - that's a good example. I need to grok the fullness of it - thank you for pointing it out.

  • BortelsBortels Mod
    Posts: 1,557

    Was loadstring() nuked? Or do I have the wrong name? I have a table I fetched from http.get that I want to parse. Can't find it in docs...

  • SimeonSimeon Admin Mod
    Posts: 5,387

    loadstring() should still work. It's not in the docs but it should be active.

  • BortelsBortels Mod
    Posts: 1,557

    Heh - since I asked, I went and got a json importer working.

    And I may not use either - I may just parse key/value pairs.

    Making excellent progress on the game. Hope to have something to show soon. Hope apple doesn't balk at http.get!!!

Sign In or Register to comment.