diff options
author | 2013-05-21 12:20:39 +0000 | |
---|---|---|
committer | 2013-05-21 12:20:39 +0000 | |
commit | f02fe3d4fec9120da009c941d14af66980911a4e (patch) | |
tree | 632d25cd46eb28bace4c428663caaca87df809e8 /tools/lua/lua_pictures.cpp | |
parent | 3e50e99fe7e6d5dbc3f3f834c8c312474d3ad057 (diff) |
support SkCanvas as a real lua object
git-svn-id: http://skia.googlecode.com/svn/trunk@9208 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/lua/lua_pictures.cpp')
-rw-r--r-- | tools/lua/lua_pictures.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp index d0343a4548..36e8c93bf1 100644 --- a/tools/lua/lua_pictures.cpp +++ b/tools/lua/lua_pictures.cpp @@ -99,6 +99,20 @@ private: SkString fTermCode; }; +static void call_setcanvas(lua_State* L, SkLuaCanvas* canvas) { + lua_getglobal(L, "setcanvas"); + if (!lua_isfunction(L, -1)) { + int t = lua_type(L, -1); + SkDebugf("--- expected setcanvas function %d\n", t); + lua_settop(L, -2); + } else { + canvas->pushThis(); + if (lua_pcall(L, 1, 0, 0) != LUA_OK) { + SkDebugf("lua err: %s\n", lua_tostring(L, -1)); + } + } +} + int tool_main(int argc, char** argv); int tool_main(int argc, char** argv) { SkCommandLineFlags::SetUsage("apply lua script to .skp files."); @@ -139,8 +153,11 @@ int tool_main(int argc, char** argv) { SkAutoTUnref<SkPicture> pic(load_picture(path)); if (pic.get()) { - SkLuaCanvas canvas(pic->width(), pic->height(), L.get(), "accumulate"); - canvas.drawPicture(*pic); + SkAutoTUnref<SkLuaCanvas> canvas(new SkLuaCanvas(pic->width(), pic->height(), L.get(), "accumulate")); + + call_setcanvas(L.get(), canvas.get()); + + canvas->drawPicture(*pic); } else { SkDebugf("failed to load\n"); } |