diff --git a/class.lua b/class.lua index d578ae4..20319f0 100644 --- a/class.lua +++ b/class.lua @@ -51,7 +51,7 @@ end -- returns a deep copy of `other' local function clone(other) - return include({}, other) + return setmetatable(include({}, other), getmetatable(other)) end local function new(class) diff --git a/gamestate.lua b/gamestate.lua index 854100c..c440180 100644 --- a/gamestate.lua +++ b/gamestate.lua @@ -36,6 +36,7 @@ function GS.new(t) return t or {} end -- constructor - deprecated! function GS.switch(to, ...) assert(to, "Missing argument: Gamestate to switch to") + assert(to ~= GS, "Can't call switch with colon operator") local pre = stack[#stack] ;(pre.leave or __NULL__)(pre) ;(to.init or __NULL__)(to) @@ -46,6 +47,7 @@ end function GS.push(to, ...) assert(to, "Missing argument: Gamestate to switch to") + assert(to ~= GS, "Can't call push with colon operator") local pre = stack[#stack] ;(to.init or __NULL__)(to) to.init = nil @@ -53,11 +55,12 @@ function GS.push(to, ...) return (to.enter or __NULL__)(to, pre, ...) end -function GS.pop() +function GS.pop(...) assert(#stack > 1, "No more states to pop!") local pre = stack[#stack] stack[#stack] = nil - return (pre.leave or __NULL__)(pre) + ;(pre.leave or __NULL__)(pre) + return (stack[#stack].resume or __NULL__)(pre, ...) end function GS.current() diff --git a/signal.lua b/signal.lua index 7cb246e..52b4d63 100644 --- a/signal.lua +++ b/signal.lua @@ -83,7 +83,7 @@ local default = new() return setmetatable({ new = new, - register = function(...) default:register(...) end, + register = function(...) return default:register(...) end, emit = function(...) default:emit(...) end, remove = function(...) default:remove(...) end, clear = function(...) default:clear(...) end, diff --git a/vector-light.lua b/vector-light.lua index c352ebc..962c2c4 100644 --- a/vector-light.lua +++ b/vector-light.lua @@ -116,7 +116,7 @@ end -- ref.: http://blog.signalsondisplay.com/?p=336 local function trim(maxLen, x, y) local s = maxLen * maxLen / len2(x, y) - s = s < 1 and 1 or math.sqrt(s) + s = s > 1 and 1 or math.sqrt(s) return x * s, y * s end diff --git a/vector.lua b/vector.lua index 0762ce5..9abdf34 100644 --- a/vector.lua +++ b/vector.lua @@ -36,7 +36,7 @@ end local zero = new(0,0) local function isvector(v) - return getmetatable(v) == vector + return type(v) == 'table' and type(v.x) == 'number' and type(v.y) == 'number' end function vector:clone() @@ -169,16 +169,16 @@ end -- ref.: http://blog.signalsondisplay.com/?p=336 function vector:trim_inplace(maxLen) local s = maxLen * maxLen / self:len2() - s = s < 1 and 1 or math.sqrt(s) + s = (s > 1 and 1) or math.sqrt(s) self.x, self.y = self.x * s, self.y * s return self end function vector:angleTo(other) if other then - return atan2(self.y, self.y) - atan2(other.y, other.x) + return atan2(self.y, self.x) - atan2(other.y, other.x) end - return atan2(self.y, self.y) + return atan2(self.y, self.x) end function vector:trimmed(maxLen)