allow multiple lua files to be used in lua_pictures
begin "stdlib" for skia in lua add comments to scrape.lua git-svn-id: http://skia.googlecode.com/svn/trunk@9206 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
cef454e7b8
commit
0e59b796e5
@ -109,17 +109,20 @@ int tool_main(int argc, char** argv) {
|
||||
exit(-1);
|
||||
}
|
||||
if (FLAGS_luaFile.isEmpty()) {
|
||||
SkDebugf("missing luaFile\n");
|
||||
SkDebugf("missing luaFile(s)\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
SkAutoDataUnref data(read_into_data(FLAGS_luaFile[0]));
|
||||
|
||||
SkAutoGraphics ag;
|
||||
SkAutoLua L("summarize");
|
||||
if (!L.load(data->data(), data->size())) {
|
||||
SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[0]);
|
||||
exit(-1);
|
||||
|
||||
for (int i = 0; i < FLAGS_luaFile.count(); ++i) {
|
||||
SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i]));
|
||||
SkDebugf("loading %s...\n", FLAGS_luaFile[i]);
|
||||
if (!L.load(data->data(), data->size())) {
|
||||
SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < FLAGS_skpPath.count(); i ++) {
|
||||
|
@ -1,11 +1,19 @@
|
||||
-- just a helper function to dump the parameters, for debugging
|
||||
function tostr(t)
|
||||
local str = ""
|
||||
for k, v in next, t do
|
||||
str = str .. tostring(k) .. " "
|
||||
if type(v) == "table" then
|
||||
str = str .. "{ " .. tostr(v) .. "} "
|
||||
if #str > 0 then
|
||||
str = str .. ", "
|
||||
end
|
||||
if type(k) == "number" then
|
||||
str = str .. "[" .. k .. "] = "
|
||||
else
|
||||
str = str .. tostring(v) .. " "
|
||||
str = str .. tostring(k) .. " = "
|
||||
end
|
||||
if type(v) == "table" then
|
||||
str = str .. "{ " .. tostr(v) .. " }"
|
||||
else
|
||||
str = str .. tostring(v)
|
||||
end
|
||||
end
|
||||
return str
|
||||
@ -14,30 +22,25 @@ end
|
||||
canvas = {}
|
||||
total = 0
|
||||
|
||||
-- called with the parameters to each canvas.draw call
|
||||
function accumulate(t)
|
||||
local verb = t.verb
|
||||
t.verb = nil
|
||||
|
||||
total = total + 1
|
||||
local n = canvas[verb] or 0
|
||||
n = n + 1
|
||||
canvas[verb] = n
|
||||
local n = canvas[t.verb] or 0
|
||||
canvas[t.verb] = n + 1
|
||||
|
||||
io.write(verb, " ")
|
||||
io.write(tostr(t), "\n")
|
||||
-- enable to dump all of the parameters we were sent
|
||||
if false then
|
||||
-- dump the params in t, specifically showing the verb first, which we
|
||||
-- then nil out so it doesn't appear in tostr()
|
||||
io.write(t.verb, " ")
|
||||
t.verb = nil
|
||||
io.write(tostr(t), "\n")
|
||||
end
|
||||
end
|
||||
|
||||
-- lua_pictures will call this function after all of the files have been
|
||||
-- "accumulated"
|
||||
function summarize()
|
||||
io.write("total ", total, "\n", tostr(canvas), "\n")
|
||||
end
|
||||
|
||||
--[[
|
||||
function drawsomething()
|
||||
local s = skia_newsurface(100, 100)
|
||||
local c = s:getcanvas();
|
||||
c:setColor(1, 0, 0, 1)
|
||||
c:drawRect(10, 10, 50, 50)
|
||||
s:saveImage("image.png")
|
||||
end
|
||||
--]]
|
||||
|
||||
|
81
tools/lua/skia.lua
Normal file
81
tools/lua/skia.lua
Normal file
@ -0,0 +1,81 @@
|
||||
Sk = {}
|
||||
|
||||
function Sk.isFinite(x)
|
||||
return x * 0 == 0
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Sk.Rect = { left = 0, top = 0, right = 0, bottom = 0 }
|
||||
Sk.Rect.__index = Sk.Rect
|
||||
|
||||
function Sk.Rect.new(l, t, r, b)
|
||||
local rect
|
||||
if r then
|
||||
-- 4 arguments
|
||||
rect = { left = l, top = t, right = r, bottom = b }
|
||||
elseif l then
|
||||
-- 2 arguments
|
||||
rect = { right = l, bottom = t }
|
||||
else
|
||||
-- 0 arguments
|
||||
rect = {}
|
||||
end
|
||||
setmetatable(rect, Sk.Rect)
|
||||
return rect;
|
||||
end
|
||||
|
||||
function Sk.Rect:width()
|
||||
return self.right - self.left
|
||||
end
|
||||
|
||||
function Sk.Rect:height()
|
||||
return self.bottom - self.top
|
||||
end
|
||||
|
||||
function Sk.Rect:isEmpty()
|
||||
return self:width() <= 0 or self:height() <= 0
|
||||
end
|
||||
|
||||
function Sk.Rect:isFinite()
|
||||
local value = self.left * 0
|
||||
value = value * self.top
|
||||
value = value * self.right
|
||||
value = value * self.bottom
|
||||
return 0 == value
|
||||
end
|
||||
|
||||
function Sk.Rect:setEmpty()
|
||||
self.left = 0
|
||||
self.top = 0
|
||||
self.right = 0
|
||||
self.bottom = 0
|
||||
end
|
||||
|
||||
function Sk.Rect:set(l, t, r, b)
|
||||
self.left = l
|
||||
self.top = t
|
||||
self.right = r
|
||||
self.bottom = b
|
||||
end
|
||||
|
||||
function Sk.Rect:offset(dx, dy)
|
||||
dy = dy or dx
|
||||
|
||||
self.left = self.left + dx
|
||||
self.top = self.top + dy
|
||||
self.right = self.right + dx
|
||||
self.bottom = self.bottom + dy
|
||||
end
|
||||
|
||||
function Sk.Rect:inset(dx, dy)
|
||||
dy = dy or dx
|
||||
|
||||
self.left = self.left + dx
|
||||
self.top = self.top + dy
|
||||
self.right = self.right - dx
|
||||
self.bottom = self.bottom - dy
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user