Lua

For any modders / other game devs interested in this stuff: I'm a huge fan of using Lua. It's an easy-to-learn language, it's small to add to your games, and it's portable. The luajit implementation is also fast.

Here's a note on how you can embed Lua with C on either windows or mac (linux is easy too, although I don't think I included all the details for linux on this post):

http://gaarlicbread.com/post/embedding_luajit

Comments

  • Thanks I will take a look. I've intentionally avoided Lua up to this point but I can definitely see its utility. It was going to be my first choice for scripting languages.
  • @‌tyler I have always wanted to learn lua. I really should get around to it.
    Another project I am supporting has modding and it uses LUA scripting so, it could be useful.

    @gavanw you could always add support once Voxel quest gets to a point where its playable.
  • Even though it's not currently a particularly good language on its own, I like the idea of using JavaScript, because there are so many other languages projects use it as a compilation target target. It sort-of gives you the most flexibility with the actual language you write your code in in. I realize that there are disadvantages with languages compiled-to-JavaScript, but they're often at least decent. Maybe there'd even be a decent way to write and debug Lua (random link from Google, don't know if it's any good).

    I guess the performance of this kind of stuff might be annoyingly poor, compared with straight-up luajit. Hmm.
  • I'm already learning Lua for a web development project using OpenResty. So a +1 for using Lua as a scripting language. :D
  • @Jeremy‌ - I did originally use javascript for the web editor (which is still in use but needs to be phased out). Code is still there - you can send JSON messages over a websocket to the client. Allows for some interesting stuff like controlling aspects of the game via any device, including a tablet. But it became too hard to work with, so I put the GUI in the game itself.

    JS performance is generally pretty poor, but as long as you leave heavy lifting to C++ or WebGL you are usually fine.

    Right now, I'm using mostly a data-driven philosophy. "Scripting" is done by reloading data, then processing that data in C++. The one problem with writing scripts (aside from the code redundancy) is that you tend to become dependent on them such that you cannot easily reload a script without carefully marshaling all of your data. With data-driven, it is pretty straight forward - you delete anything necessary, the reload, then reconstruct any dependent classes and initializer functions. In programming terms, there are no "side effects."
  • Learning Lua:

    Here's an overview of learning the core of Lua quickly. It's faster to learn than most other languages. If you want to learn it in detail, this online book is the best free resource.

    Learn fast (one page): http://tylerneylon.com/a/learn-lua/
    Learn slow (good book): http://www.lua.org/pil/contents.html

    I didn't know about moonshine before - that looks fun.

    For js vs Lua:

    I've read in a few places that Lua runs significantly faster, and it's easier to integrate with C or C-supersets like C++ or Objective-C. JS has the advantage of running directly in browsers.

    node.js itself has the advantage of supporting asynchronous operations for networking and file i/o. But! Those advantages are purely added by the libuv library, which could just as well be added to Lua. Lua as a language is just as capable as js as handling callbacks - you can pass around functions, define anonymous functions, and use closures.
Sign In or Register to comment.