By this I mean Lua already has Object oriented Programming, especially using Roblox's ModuleScripts. Is it possible to create an Interface, much like Java, so objects can implement undefined functions?
It is possible. Here's a Roblox wiki article on OOP: http://wiki.roblox.com/index.php?title=OOP
For inheritance, define a class instantiation function in terms of a superior class. Here's an example:
vector={ new=function(...) local components={...} local length=#components return setmetatable({class="vector"},{ __index=function(t,k) if type(k)=="number"then return components[k] end end, __newindex=function(t,k,v) if type(k)=="number"then if type(v)=="number"then components[k]=v return else error("Must be a number") end end error("Cannot set "..k) end, __add=function(a,b) if a.class==b.class and a.length==b.length then local t={} for i=1,#a do t[i]=a[i]+b[i] end return vector.new(unpack(t)) end end, __sub=function(a,b) if a.class==b.class and a.length==b.length then local t={} for i=1,#a do t[i]=a[i]-b[i] end return vector.new(unpack(t)) end end, __tostring=function() return table.concat(components,", ") end }) end } vector3={ new=function(x,y,z) local object=vector.new(x,y,z) rawset(object,"magnitude",math.sqrt(x*x+y*y+z*z)) rawset(object,"class","vector3") local meta=getmetatable(object) meta.__add=function(a,b) if a.class==b.class then return vector3.new(a.x+b.x,a.y+b.y,a.z+b.z) end end meta.__sub=function(a,b) if a.class==b.class then return vector3.new(a.x-b.x,a.y-b.y,a.z-b.z) end end meta.__index=function(t,k) if k=="x"then return x elseif k=="y"then return y elseif k=="z"then return z end end local old=meta.__newindex meta.__newindex=function(t,k,v) if type(v)=="number"then if k=="x"or k=="y"or k=="z"then if k=="x"then x=v elseif k=="y"then y=v elseif k=="z"then z=v end rawset(object,"magnitude",math.sqrt(x*x+y*y+z*z)) return end end return old(t,k,v) end return object end } local v=vector3.new(12,23,34) print(v.x) local a=vector3.new(23,12,1) local b=v+a print(b)
Without the help of an external library (or writing your own if you're so inclined), no this isn't possible. There are libraries in Lua that do make this possible, but it is not a feature of Lua. Lua is not intended to be object oriented.