A class like in OOP languages? Lua introduces only tables (Lua’s associative array) as a type that is like a class: Programming in Lua : 16.
You can store functions in variables, because Lua treats functions as first-class types, so using such power you can add functions to tables and that’s how you make a structure/class!
If you seek for inheritance, check out: Programming in Lua : 16.2 or search for some repositories with libraries (modules) providing somehow different, maybe more convenient approach for OOP.
If you want to group some tables or functions you can utilize modules: Lua modules in Defold
So, simple example if you want to create a class for handling animations:
local Animator_Class = {
current_anim = hash("idle")
function play_anim(anim)
if current_anjm ~= anim then
sprite.play_flipbook("#sprite", anim)
current_anim = anim
end
end
}
Then you can call functions from your class:
Animator_Class.play_anim(hash("run"))
Then you can advance your class, for example if you want to create different instances of the class you might want to write a function that returns an instance of your table (your class) or use metatables: Programming in Lua : 13