Page 1 of 1

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

Posted: Thu Dec 21, 2017 11:48 am
by monkyyy
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?

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

Posted: Thu Dec 21, 2017 12:21 pm
by Tjakka5
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/

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

Posted: Sat Dec 30, 2017 12:31 am
by jojomickymack
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
http://www.lua.org/pil/contents.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
end
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".

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

Posted: Sun Dec 31, 2017 11:40 am
by Rucikir
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.

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

Posted: Wed Jan 10, 2018 5:34 pm
by kbmonkey
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.

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

Posted: Thu Jan 11, 2018 7:26 pm
by Ostego160
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!

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

Posted: Fri Jan 12, 2018 7:28 am
by Roland_Yonaba
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.