Google V8 engine

Jay Vaughan jayv at synth.net
Tue Jul 24 22:11:13 CEST 2012


> Just to be sure, it support in place change, i.e. that I can leave the
> application running,modify the lua code and it will take changes into
> account ?

The way to set it up is you have the Lua VM operate in its own context.  Anything you want to expose to the VM, in terms of API's and functions and C/C++ structs/objects, you can.  You need to write some glue code to get stuff across the Lua->C/C++ runtime bridge, but this is actually delightfully easy and fun to boot (mostly just simple stack-based pushXX methods where XX is any of various C/C++ types).  Of all languages, I like the Lua typing scheme pretty much most of all, these days.  There is very little of importance that cannot be represented by a combination of hash, array, or associative array. Okay, just kidding, but honestly you can have a lot of fun where you construct entire sets of data in simple table form, plug this into some elegant functions whose purpose is to simply grok the table, and off you go .. 

e.g.

graph_ = {}
graph_["default"] = { {in: "vco", out: "vca", mix=0.82 }, { in: "vca", out: "vcf", r=0.234 }, &etc... }

nostromo_synth:connect(graph_)
-- where nostromo_synth is a C-derived object, and :connect is a Lua-attached function for crossing the C gap.

The VM and all tables in the stack can be accessed from the C/C++ side with full access to the VM instruction set and state machine.  The entire state of the VM is held in a *lua_State, which gets passed around as needed in your glue code in order to push/pull things on the stack, load VM bytecode, run it, etc.  To add a Lua VM to your project, add the .c files (there are only like .. I think .. 12 .c files to get the VM integrated), declare a global lua_State, and have at it. :)

I imagine you want to have all your parameters in Lua-land, so you can easily handle things like loading files, running Lua functions that make connections between modules, maybe do user-interface'ish things, and so on.  So your use of the VM would mean 'expose these data structs as Lua table types', 'have functions (on either Lua or C/C++ side) callable from either/or side', and so on.  Then you'd use the Lua side to script the hell out of everything, pushing values across the VM to C functions, and vice-versa, as needed.

http://trac.caspring.org/wiki/LuaPerformance
http://lua-users.org/wiki/OptimisationTips
http://www.lua.org/gems/sample.pdf

http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf

http://stackoverflow.com/questions/2685636/lua-game-state-and-game-loop

http://lua-users.org/lists/lua-l/2005-12/msg00340.html


(And can I just say .. I love Lua, and what this would represent were you to use it in such a way.  Count me definitely interested in constructing a Lua-based environment for your efforts - I will seriously help you in real time. :)  I am using the Lua-VM with MOAI at work: http://getmoai.com/ .. lately I'm doing a lot of non-native mobile UI stuff, which is awesome in MOAI.  Also, extending the MOAI host .. masses of potential in the idea of using a Lua VM to glue warring platforms together in Peace..)

 
;
--
Jay Vaughan






More information about the music-bar mailing list