Whats a good resource for writing "good" lua code?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Posts: 51
Joined: Fri Mar 16, 2012 5:29 pm

Whats a good resource for writing "good" lua code?

Post by monkyyy » Thu Dec 21, 2017 11:48 am

Its one thing to bodge together something small with trial and error with banging my head against the lua api ; it's quite another to take on a major project with some semblance of sanity 3 minutes into it.

Anyone got anything worth reading on how to do the latter?

User avatar
Party member
Posts: 238
Joined: Thu Dec 26, 2013 12:17 pm

Re: Whats a good resource for writing "good" lua code?

Post by Tjakka5 » Thu Dec 21, 2017 12:21 pm

Most of it comes from practice and somewhat personal preference. (I for one like to Camelcase modules)

Other than that, Kikito has a nice website with a few things about writing proper code. check it out here: http://kiki.to/
Check out my portfolio: http://tjakka5.sorunome.de/

User avatar
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: Whats a good resource for writing "good" lua code?

Post by jojomickymack » Sat Dec 30, 2017 12:31 am

This is probably known by everyone here already, but the PIL (programming in lua) book is free online and highly relevant. Also, why not buy a copy and support the lua project? - http://www.lua.org/donations.html

Chapter 16 and 17 contains the most important part of what 'good lua' consists of - and I see the pattern below verbatim in lua source code.

Code: Select all

function Account:new (o)
  o = o or {}   -- create object if user does not provide one
  setmetatable(o, self)
  self.__index = self
  return o
don't be afraid of setmetatable or __index - it's the key to lua's prototype model - definitely worth memorizing. If that snippit makes sense to you, you're a "good lua coder".

User avatar
Party member
Posts: 125
Joined: Tue Nov 05, 2013 6:33 pm
Location: Paris

Re: Whats a good resource for writing "good" lua code?

Post by Rucikir » Sun Dec 31, 2017 11:40 am

luacheck is a tool for linting and static analysis of Lua code. While it won't check the aestetics of your code, it can check that you don't use global variables, don't shadow variables, and several more useful options. It is really handy.
Lua script to distribute your LÖVE games. love-release.lua : Forum | Github

User avatar
Party member
Posts: 127
Joined: Tue Sep 01, 2015 12:19 pm

Re: Whats a good resource for writing "good" lua code?

Post by kbmonkey » Wed Jan 10, 2018 5:34 pm

Separate game logic from the view code for major projects. Use busted and try your hand at test-driven development. Your brain will thank you when your major project doesn't resemble a bowl of spaghetti.

Posts: 14
Joined: Tue Oct 17, 2017 7:18 pm

Re: Whats a good resource for writing "good" lua code?

Post by Ostego160 » Thu Jan 11, 2018 7:26 pm

In my basic understanding, I break what we do down into two categories: proficiency in the language and design patterns.

These two things are frequently mutually exclusive as a design pattern can be applied in many languages.

On that note: I find there is plenty of information on language proficiency, not so much on patterns. As a novice myself, I find my shortcomings are unrelated to language proficiency and more to do with design patterns (where I think the gold is). I keep two reference books always on hand (besides Programming in Lua): Design Patterns: Elements of Reusable Object-Oriented Software and the more recent Game Programming Patterns.

This answered many of my 'how' questions. Too many tutorials will focus on how to draw a box or write 'hello world', not how to write an observer/listener command system (example). And let's face it, there are some great tutorials on YouTube but most are quite terrible. However, those books are organized and will teach you about how to organize your software and some industry standards instead of having to reinvent the wheel.

Hope this helps!

User avatar
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)

Re: Whats a good resource for writing "good" lua code?

Post by Roland_Yonaba » Fri Jan 12, 2018 7:28 am

I believe the Lua Style Guide might be a good reference here. Olivine-Labs also shared their own Lua Style Guide. Both of them are not meant to be authorative, but they both present good habits and idioms which are commonly adopted by the Lua community.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests