Skip to content
Permalink
Browse files
Changed class importing to happen after class has loaded. Added __sta…
…tic invocation to support this.
  • Loading branch information
James King committed Aug 9, 2013
1 parent f900646 commit d0b7f98
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 91 deletions.
@@ -288,18 +288,6 @@ end
@param string:name The name of this class, including the full package.
]]
function SeeVM:loadClass(def, annotations, name)
local abool = true
if self.base.Object then
for _, annotation in pairs(annotations) do
if annotation:sub(1, 7) == "extends" then
abool = false
break
end
end
else
abool = false
end

local className = getPackageName(name)

if self.classes[name] then
@@ -327,11 +315,6 @@ function SeeVM:loadClass(def, annotations, name)
return self
end

-- Extend Object by default.
if abool then
setmetatable(class, self.base.Object)
end

-- Import base classes.
for k, class in pairs(self.base) do
env[k] = class
@@ -340,11 +323,33 @@ function SeeVM:loadClass(def, annotations, name)
-- Setup class environment.
env[className] = class
setfenv(def, env)
def()
self.classes[name] = class

for _, annotation in pairs(annotations) do
self:executeAnnotation(env, class, annotation)
end
def()
self.classes[name] = class

local abool = true
if self.base.Object then
for _, annotation in pairs(annotations) do
if annotation:sub(1, 7) == "extends" then
abool = false
break
end
end
else
abool = false
end

-- Extend Object by default.
if abool then
setmetatable(class, self.base.Object)
end

if class.__static then
class.__static()
end

return class
end
@@ -32,6 +32,7 @@ end
function Array.__meta:__newindex(index, value)
if typeof(index) == "number" then
self:set(index, value)
return
end
rawset(self, index, value)
end
@@ -43,9 +44,6 @@ end
@return any The value of the given index.
]]
function Array:get(index)
if typeof(index) ~= "number" then
return rawget(self, index)
end
if index < 0 then
index = self.length + index + 1
end
@@ -61,15 +59,13 @@ end
@param any:value The value to set the given index to.
]]
function Array:set(index, value)
if typeof(index) ~= "number" then
rawset(t, index, value)
return
end
if index < 0 then
index = self.length + index + 1
end
if index <= self.length + 1 and index > 0 then
self.length = self.length + 1
if index == self.length + 1 then
self.length = self.length + 1
end
self.luaArray[index] = value
end
end
@@ -1,7 +1,11 @@
--@native string
--@native tostring
--@native rawget
--@native rawset

--@import see.base.Array
--@import see.base.System
--@import see.util.ArgumentUtils

--[[
A mutable, Array-backed string. Faster and more memory efficient than native strings.
@@ -16,7 +20,7 @@ function String.__cast(value)
if typeof(type) == "table" and value.__type then
return value:toString()
end

local str = tostring(value)
local ret = String.new()

@@ -50,14 +54,34 @@ function String:init(...)
end
end

local oldindex = String.__meta.__index

function String.__meta:__index(index)
if typeof(index) == "number" then
return self.charArray[index]
end
return oldindex[index]
end

function String.__meta:__newindex(index, value)
if typeof(index) == "number" then
if typeof(value) == "string" then
value = string.byte(value)
end
self.charArray[index] = value
return
end
rawset(self, index, value)
end

--[[
Gets a Lua string from this String.
@return string The Lua string.
]]
function String:lstr()
local str = ""
for i = 1, self.charArray.length do
str = str .. string.char(self.charArray:get(i))
str = str .. string.char(self.charArray[i])
end
return str
end
@@ -94,7 +118,7 @@ end
function String:sub(a, b)
if not b then b = self:length() end

-- TODO

end

function String:toString()
@@ -1,4 +1,5 @@
--@import see.rt.RuntimeException
--@import see.base.String
--@extends see.rt.RuntimeException

function InvalidArgumentException:init(n, expected, got)
@@ -1,3 +1,4 @@
--@import see.base.Exception
--@extends see.base.Exception

--[[
@@ -1,8 +1,10 @@
--@native math
--@import see.util.ArgumentUtils

Math.HUGE = math.huge
Math.PI = math.pi
function Math.__static()
Math.HUGE = math.huge
Math.PI = math.pi
end

function Math.abs(x)
ArgumentUtils.check(1, x, "number")

0 comments on commit d0b7f98

Please sign in to comment.