Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local type, tostring, sprintf
- = type, tostring, string.format
- --[[-----------------------------------------------------------------------\--
- :: Class: XsObj
- --\\-----------------------------------------------------------------------]]--
- -- TODO Maybe abandon luabind classes altogether?
- -- Debugging would be easier, since tables can be compared. And it should
- -- be possible to implement a OO-system that mimics luabind.
- class "XsObj"
- --[[-------------------------------------------------------------------\--
- :: Fields: Static
- --\\-------------------------------------------------------------------]]--
- local __xs_uid = 0
- --[[-------------------------------------------------------------------\--
- :: Constructor / Finalizer
- --\\-------------------------------------------------------------------]]--
- function XsObj:__init(cls)
- if type(cls) ~= "string" or cls:len() == 0 then
- abort("[XsObj:__init]: Invalid argument #1; expected the name of subclass.")
- end
- __xs_uid = __xs_uid + 1
- self.__uid = __xs_uid
- self.__cls = cls
- end
- --[[-------------------------------------------------------------------\--
- :: Methods: Overloads
- --\\-------------------------------------------------------------------]]--
- -- TODO Move and rename to xs_utils.equals making it a more useful utility.
- function XsObj:__eq(L, R)
- local xL = type(L) == "userdata"
- local xR = type(R) == "userdata"
- if xL and xR then
- -- XsObj
- xL = type(L.__uid) == "number"
- xR = type(R.__uid) == "number"
- if xL and xR then
- return L.__uid == R.__uid
- elseif xL or xR then
- return false
- else
- -- game_object
- xL = type(L.clsid) == "function"
- xR = type(R.clsid) == "function"
- if xL and xR then
- return L:clsid() == R:clsid() and L:id() == R:id()
- elseif xL or xR then
- return false
- else
- abort("[XsObj.__eq]: Unable to determine object equality.")
- end
- end
- elseif xL or xR then
- return false
- else
- return L == R
- end
- end
- function XsObj:__tostring()
- return sprintf("%s [%08X]", self.__cls, self.__uid)
- end
- function XsObj:__add(L, R)
- self:failFromCall("__add")
- end
- function XsObj:__sub(L, R)
- self:failFromCall("__sub")
- end
- function XsObj:__mul(L, R)
- self:failFromCall("__mul")
- end
- function XsObj:__div(L, R)
- self:failFromCall("__div")
- end
- function XsObj:__pow(L, R)
- self:failFromCall("__pow")
- end
- function XsObj:__lt(L, R)
- self:failFromCall("__lt")
- end
- function XsObj:__le(L, R)
- self:failFromCall("__le")
- end
- function XsObj:__call()
- self:failFromCall("__call")
- end
- function XsObj:__unm(obj)
- self:failFromCall("__unm")
- end
- function XsObj:__len(obj)
- self:failFromCall("__len")
- end
- --[[-------------------------------------------------------------------\--
- :: Methods: Private
- --\\-------------------------------------------------------------------]]--
- function XsObj:failFromCall(func)
- abort("[%s:%s]: Unsupported operator/function call.", self.__cls, func)
- end
- --[[-------------------------------------------------------------------\--
- :: Methods: Public
- --\\-------------------------------------------------------------------]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement