4 ms·
Write a nice, clean C library and export a decent header. Then, use the tolua tool to read that header and generate the bindings for the Lua VM. Build the Lua
by primitur 14y ago
Write a nice, clean C library and export a decent header. Then, use the tolua tool to read that header and generate the bindings for the Lua VM. Build the LuaVM with those bindings, and suddenly you have the features of your C library available to you within the Lua language environment.
There are some great tutorials on this, here are a few I found with google-fu:
http://lua-users.org/wiki/BindingCodeToLua http://lua-users.org/wiki/BindingCodeToLua
http://csl.sublevel3.org/lua/ http://csl.sublevel3.org/lua/
http://www.nicolasgoles.com/2012/08/03/lua-tutorial---c-bindings.html http://www.nicolasgoles.com/2012/08/03/lua-tutorial---c-bind...
http://www.gandogames.com/2011/01/tutorial-using-luabind-to-integrate-lua-with-cc-pt-1/ http://www.gandogames.com/2011/01/tutorial-using-luabind-to-...
I think you will see, once you study the above, that there is a vast amount of power available to you. The Lua VM, written itself in pure C, is an utter joy to behold, and I encourage every new C programmer to inspect the Lua VM sources (its only about 12 files..) and see for yourself just what it has to offer you. C+Lua can be a very, very powerful tool .. and anyone learning C today would benefit greatly from also doing some Lua bindings, themselves, to see what I mean ..
- primitur 14y agoI just wanted to add that the LOAD81 project is another great way to learn Lua: http://github.com/antirez/load81 http://github.com/antirez/load81 (Yes, that antirez..) I strongly encourage anyone who wants to learn Lua to check out LOAD81 - its a lot simpler than MOAI, but reflects the same basic principles.