Hi,
I just started experimenting with the lua player and I was wondering if objects are supported. Haven't found any code that uses objects.
By objects I mean creating your own objects.
And if not , is it planned , because I don't think you will see any serious game attempts if you can't create objects.
other than that , it rocks :)
I prolly release something soon, and better stuff if I can use objects :)
greeetz
objects supported ?
Moderators: Shine, Insert_witty_name
What do you mean by object ?? You mean Object Oriented Program ??
Well Lua support this kind of feature.
I don't know for inheritance and other oop stuff but this can be a good start....
Well Lua support this kind of feature.
Code: Select all
-- -----------------------------------------------------------------------
-- CObject
-- -----------------------------------------------------------------------
CObject = {}
CObjectMetaTable = { __index = CObject }
-- -----------------------------------------------------------------------
-- CObject:new
-- -----------------------------------------------------------------------
function CObject:new()
local Table =
{
m_TextValue = "TextData",
m_BoolValue = true,
}
setmetatable(Table, CObjectMetaTable);
return (Table);
end
-- -----------------------------------------------------------------------
-- CObject:doSomething
-- -----------------------------------------------------------------------
function CObject:doSomething()
if (true == self.m_BoolValue) then
self.m_TextValue = "OK";
else
self.m_TextValue = "CANCEL";
end
end
-- -----------------------------------------------------------------------
--
-- -----------------------------------------------------------------------
function main()
local MyObj1 = CObject:new();
local MyObj2 = CObject:new();
MyObj1.m_BoolValue = true;
MyObj2.m_BoolValue = false;
MyObj1:doSomething();
MyObj2:doSomething();
end
main();
I often say this, but read the book. Especially the chapter on classes. It is a bit dry, but very helpful.