Classes in Lua

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Locked
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Classes in Lua

Post by LuMo »

i learned programming with java so i like programing with classes...
i read some tutorials on simulation classes in lua, but i am not really sure if i got it right...

Code: Select all

public class WallInfo
{

    public WallInfo(double d,  double d1,  double d2,  double d3,  double d4)
    {
        top=d2;
        bottom=d3;
        left=d;
        right=d1;
        ctop=d2+d4;
        cbottom=d3-d4;
        cleft=d+d4;
        cright=d1-d4;
    }

    public double top;
    public double bottom;
    public double left;
    public double right;
    public double ctop;
    public double cbottom;
    public double cleft;
    public double cright;
}
this code provides me information about the wall

is the equivalent in lua the following?

Code: Select all

WallInfo={}
WallInfo_mt={}

function WallInfo:new(d,  d1,  d2,  d3,  d4)
	return setmetatable({top=d2, bottom=d3, left=d, right=d1, ctop=d2+d4, cbottom=d3-d4, cleft=d+d4, cright=d1-d4},  WallInfo_mt)
end
so that i can call it same way as in java...
greets
LuMo
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

This is not a general Lua forum, try Lua users wiki and search for class.
Locked