HSCALE - MySQL Partitioning

LUA

Syntax

  • All names are written using CamelHumps. So it is myCoolMethod and not my_cool_method.
  • Use braces where possible.
Common patterns
local withBraces = require("withBraces")

if (termA == termB) then
    someFunction()
end

Visibility

  • Always use the smallest visibility.
  • Never use the global scope.
  • Thus all variables and functions must be declared as local. This is checked by a lint (i.e. code analysis) task.

Variables

  • Member variables which are local to a module or a class begin with an underscore.

Modules and classes

Example of a module
local _module = {}

local _myModuleLocalVariable = "Invisible to users"
_module.myPublicVariable = "Visibile to users"

function _module.someFunction()
    _myModuleLocalVariable = "Some secret stuff."
    _module.myPublicVariable = "Open to everyone"
...
end

return _module
Example of a class
local MyClass = {}
MyClass.__index = MyClass

-- Since a file can only contain a single class it is the only thing we export.
_module = MyClass

-- Static function.
MyClass.staticFunction()
end

-- Instance creation.
MyClass.create()
    local self = {}
    setmetatable(self, Query)

    self._memberVariable = "member"

    return self
end

MyClass:instanceFunction()
    self._memberVariable = "realMember"
end

-- Private functions begin with two underscores.
MyClass:__privateFunction()
end

return _module

Imports / require

  • Imports have to be assigned to local variables.
  • Classes are assigned to a variable beginning with an uppercase character.
Example import
local MyClass = require("myClass")
local myNormalModule = require("myNormalModule")

-- Create an instance.
local myInstance = MyClass.create()