Imagine yourself in a late night coding session, eyes pulsing – your hands tingling and your heart pumping away to the sound of the keystrokes. You are on the last stretch here, this is the last puzzle piece. This is what all those hours were for. Not even a whole minute passes, what felt like years all converging into a single experience right underneath your finger tips… As you hit F5 your console comes alive with output, the game starts up and you are presented with a blank screen and some debug spew in the standard output window. What feels like a mixture of adrenaline and, probably caffeine induced shaking you realise just exactly what it is you have achieved – almost nothing. There is no game play, no sounds, not even a single sprite to greet you with a silent nod of the head. All you have done is wired something into your creation, something exciting, something with huge potential but all you have done – is something you never have before. You have stepped in a direction that is new to you.
If this is so little, then why do I feel like I just launched myself one thousand miles into the sky and I am now ( probably ) invincible? Could it be that something as simple as a change of tools has fired up the passion and fun I had while programming when I started? What makes programming so addictive ( yea I said it! ) for hungry minds like ours? I think I like new challenges. New grounds.
Change is as good as a holiday?
I have no idea. What I do know, is that some times in my programming cycle I find myself doing things with the same set of tools over and over. Maybe it is work, maybe it is a personal project but damned if I don’t get some fresh air. I need something invigorating again, I need that rush to kick me in the shin and remind me exactly what it is that drives me to learn more. Whatever my fancy, whatever I do – get some fresh air. Do something else. Something small and silly. Just because I never have. Break grounds, for myself. Uncover ground I never knew about. DIG AROUND. There is so much fun to be had, even if it leads to pointless, useless and horribly written mess – I will still feel like a million bucks – and whatever it is I come back to in the morning always feels a little more fun.
In 2009, I decided to do just that. I moved away from the things I knew well, things I had worked on, left the comfort zone for something new.
Is this an evangelism post for v8 vs lua vs whateverScript? No. Is this a conversion pitch to turn over to my favorite technology? No.
This is a post I would have loved to stumble upon in 2009. This is the spearhead of a long and sometimes frustrating journey. What happened was the story above, re kindling of my favorite parts of learning something new – but it only happened in the beginning of 2010. This is a post that I hope someone somewhere, curious about v8 (in search of something new to learn) can find their way into the story above a lot sooner than I did.
What else made me like it?
While browser wars are an amusing internet culture (among many other fan boy groups), the benefits are obvious. Everyone wants to have the fastest VM, the fastest JIT compiler and the fastest user experience. For me, I like that. I like seeing a repository bursting with changes daily, most if not all of those changes aimed at performance. I like seeing websites and domains with graphs plotting DAILY performance hits on changes to the code of the different engines ( see www.tinyclouds.org) .
The actual v8 stuff in this post starts here
Since the v8 scene has started to liven up, the mailing list is often filled with the same beginner questions I had but there are now many knowledgeable users ready to help those who haven’t grasped it all yet. Here is my contribution to the community, a few tutorials with code, examples and implementations of the most commonly asked and misunderstood aspects when embedding v8 into a game or application.
The usual disclaimer
I am no professional v8 developer, I am no c++ ninja, but what I can offer I will do my best. Please, if there are things you can suggest for performance, usage or clarity it would be great if you could post it in the comments or send me an email so it can be included for the other readers of the tutorials :)
Diving right in
I am not going to cover installing, compiling or configuring (there is plenty of that around – and you should learn the tools you want to use). What these tutorials will cover is split up over 4 simpler parts , each expanding on the previous one, aiming to cover the very first steps of throwing v8 into your application. The examples are written using vs2008 express, and if desired it would be trivial to make Mac or Linux project files too. The binaries included are for windows, but the code is heavily commented and hopefully clear and straight forward.
Note : Each heading is a link to the source of the example on github.
This one is the raw , simple basics. Load a file, execute the string, return the results.
Standing on tutorial 01, this example shows how to make a global function accessible in scripts.
Something everybody seems to ask at some point. How do you expose native c++ classes in a chunky fashion.
I hope this blabber is rewarded by the examples if anything, and that you don’t feel robbed D:
I am posting to learn, don’t hold back on code, performance, implementation details and general feedback.
Download the examples and source