While LUA is not an object oriented programming language, you can mimick your code to act like one. The key here is with the setmetatable() function.

Here is a .lua file containing a simple class.

That’s it! That is all there is to it. Save it as object.lua and now you can simply create a new instance of your class like this:

There is no data type casting conversion feature available in LUA so an alternative to convert float values to integer would be to use the math library.

This returns the largest integer smaller than or equal to the value.

Related Posts Plugin for WordPress, Blogger...