I’m going off my normal web development track here to just mention something which happens very very rarely. Let me start by making an outrageous claim: Lua is a work of a genius. If that interested you at all or if you just want to see how I support this claim, then please continue reading. Otherwise… read anyways?
A project (which has to do with the web, really!) which I’m currently working on personally has some backend written in C which is pluginnable using Lua. Originally this was in Ruby with… plugins being in Ruby, but Ruby is… like… impossible to sandbox. All Ruby has is crappy $SAFE levels. So I made the decision, a little late (after the tool was written), to rewrite it using old fashioned C and Lua, since Lua was built for these things.
Let me throw up a quick disclaimer and assure everyone that I’ve never used Lua extensively. But I do play World of Warcraft quite a bit (shame on me!) and I know that their addons are written in Lua, and through a few google searches I’ve come to find that a lot of big name companies use it for plugins. It is what Lua was made for afterall.
First of all… Lua the language itself is pretty cool. Its functional, it can be object oriented, it supports these wacky but powerful things called coroutines, and its fast (for a scripted language). It has a few things that take a while to get used to (metatables et al), but I picked it up in about 2 hours.
Next, Lua was built in mind with being a super light-weight, extensible language built for plug-in type jobs. So it comes with basically no standard libraries straight out of the box, you’re expected to add them in via the C API. Doing this is super simple…
OKAY BLAH! ON TO WHY ITS SO GENIUS…
It uses this really ingenious idea of a stack to store everything. Want to call a function? Push the function name onto the Lua stack, followed by the arguments, call the function. So they’re not genius for coming up with this idea, since this is all that computers do under the covers with every application, but they’re genius for choosing to use it to talk with C. Why? Because what I would have done is come up with a ton of nice little functions like “lua_call_func(name, …)” where … are the args to cover up all the dirty internals. But then… how would you know the types of the variables given? How would Lua know whether to garbage collect them? (It is a garbage collected language) Plus, Lua has some abstract types like “tables” which can get even more abstract with metatables! Ahhh!
Using a stack keeps it simple stupid! There are only a few types you can push onto a stack (integer, string, nil, c function, basically). Then using various tricks of the stack, complicated structures can be created such as entire objects with inheritance, private variables, and more, using… 3 data types? AWESOME.
And I never have to think whether I own the memory or Lua. I know that whatever I push onto a stack, Lua owns. I may have to pop it myself but I can free my HEAP-allocated memory after pushing it onto the stack. I never have to question anything.
Anyways, that was my quick 5-minute unedited heart-pouring to Lua. 

Posted at 10:36 PM |

Written by Mitchell Hashimoto |
No Comments made.
Jul
26
I feel terrible as I type this post right now. I’m an avid Apple user, I’ve had my MacBook pro since it came out (it is the original!) and I’ve had iPods and everything in between. I also got an iPhone later last year after becoming an Apple Store retail employee.
This year I decided to sit out and get the iPhone 3G! It was a lot of fun sitting out and was quite an experience but unfortunately the phone itself does not deliver.
In addition to getting the iPhone 3G I had been acquainted to the iPhone 2.0 software early since I was in the developer program. When I heard that the build number on the 3G was the same as last beta of the iPhone 2.0 software, I was terrified. My beta build was riddled with crashes, hangs, slow-syncs, and more.
I hoped this was specific to the iPhone and that the 3G hardware would somehow magically fix this.
It did not.
Just now I received a phone call and “swiped” to answer it and the phone CRASHED. That’s right, it crashed. I restarted it, got another phone call, answered it, and this time it froze for a solid 5 to 10 seconds before answering. After finishing the call, I moved the phone away from my ear, awaiting the screen to turn back on so I could “End Call.” Unfortunately, the screen never turned back on! And the person on the other line (luckily a family member) heard me cussing and hitting my screen to get it to hang up.
This crossed the line.
I can deal with my touch keypad hanging up, I can deal with painfully slow syncing, I can deal with a few instabilities with user-land software. But I can NOT handle that the iPhone — which as I remember Steve Jobs saying the most important part was the PHONE — cannot be a reliable phone.
I will not get rid of the phone, it is far too valuable to me with my contacts, calendars, software, etc. to throw away so easily, but I just have to say: Shame on you Apple, shame on you! How could such poor quality software ship out the door so quickly?

Posted at 1:38 AM |

Written by Mitchell Hashimoto |
3 Comments made.