aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn48
-rw-r--r--site/user/special/lua.md42
-rw-r--r--third_party/lua/BUILD.gn55
-rw-r--r--tools/lua/lua_pictures.cpp12
4 files changed, 124 insertions, 33 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 4ffbb01b39..e3954d7f27 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -20,6 +20,7 @@ declare_args() {
skia_use_libjpeg_turbo = true
skia_use_libpng = true
skia_use_libwebp = !is_fuchsia
+ skia_use_lua = false
skia_use_mesa = false
skia_use_piex = !is_win
skia_use_zlib = true
@@ -960,6 +961,45 @@ if (skia_enable_tools) {
}
}
+ if (skia_use_lua) {
+ test_lib("lua") {
+ public_include_dirs = []
+ sources = [
+ "src/utils/SkLua.cpp",
+ "src/utils/SkLuaCanvas.cpp",
+ ]
+ deps = [
+ "//third_party/lua",
+ ]
+ }
+
+ executable("lua_app") {
+ sources = [
+ "tools/lua/lua_app.cpp",
+ ]
+ deps = [
+ ":lua",
+ ":skia",
+ "//third_party/lua",
+ ]
+ testonly = true
+ }
+
+ executable("lua_pictures") {
+ sources = [
+ "tools/lua/lua_pictures.cpp",
+ ]
+ deps = [
+ ":flags",
+ ":lua",
+ ":skia",
+ ":tool_utils",
+ "//third_party/lua",
+ ]
+ testonly = true
+ }
+ }
+
import("gn/samples.gni")
test_lib("samples") {
public_include_dirs = [ "samplecode" ]
@@ -977,6 +1017,14 @@ if (skia_enable_tools) {
":views",
":xml",
]
+
+ if (skia_use_lua) {
+ sources += [ "samplecode/SampleLua.cpp" ]
+ deps += [
+ ":lua",
+ "//third_party/lua",
+ ]
+ }
}
executable("dm") {
diff --git a/site/user/special/lua.md b/site/user/special/lua.md
index 448d8b9b13..b8a9cd5c9b 100644
--- a/site/user/special/lua.md
+++ b/site/user/special/lua.md
@@ -1,38 +1,35 @@
Skia Lua Bindings
=================
-**Warning: The following has only been tested on Linux, but it will likely
-work for any Unix.**
+**Warning: The following has only been tested on Mac and Linux, but it will
+likely work for any Unix.**
Prerequisites
-------------
-This assumes one already has Skia building normally. If not, refer to the
-quick start guides. In addition to that, you will need Lua 5.2 installed on
-your system in order to use the bindings.
-
-Building lua requires the readline development library. If missing this can be installed (on Ubuntu) by executing:
-
- * `apt-cache search libreadline` to see the available libreadline libraries
- * `sudo apt-get install libreadline6 libreadline6-dev` to actually install the libraries
+This assumes you already have Skia building normally. If not, refer to [How to
+build Skia](../build).
Build
-----
-The build process starts the same way as described in the quick starts, but
-before using gyp or make, do this instead:
-
- $ export GYP_DEFINES="skia_shared_lib=1"
- $ make tools
+To build Lua support into Skia tools, set the GN argument `skia_use_lua` to `true`.
+Optionally, set `skia_use_system_lua`. Then re-run GN.
-This tells Skia to build as a shared library, which enables a build of another shared library called 'skia.so' that exposes Skia bindings to Lua.
Try It Out
----------
-Once the build is complete, use the same terminal:
+The tools `lua_app` and `lua_pictures` should now be available when you compile,
+and `SampleApp` should now have a `Lua` sample.
+
+
+To-Do
+-----
+
+Skia had a feature that let it be imported as an .so by Lua.
+This feature is not yet supported by GN, but would have looked something like this:
- $ cd out/Debug/
$ lua
Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio
@@ -43,12 +40,3 @@ Once the build is complete, use the same terminal:
> canvas = doc:beginPage(72*8.5, 72*11)
> canvas:drawText('Hello Lua', 300, 300, paint)
> doc:close()
-
-The key part to loading the bindings is `require 'skia'` which tells lua to look
-for 'skia.so' in the current directory (among many others) and provides the
-bindings. 'skia.so' in turn will load 'libskia.so' from the current directory or
-in our case the lib.target directory. 'libskia.so' is what contains the native
-skia code. The script shown above uses skia to draw Hello Lua in red text onto
-a pdf that will be outputted into the current folder as 'test.pdf'. Go ahead and
-open 'test.pdf' to confirm that everything is working.
-
diff --git a/third_party/lua/BUILD.gn b/third_party/lua/BUILD.gn
new file mode 100644
index 0000000000..9967dcd675
--- /dev/null
+++ b/third_party/lua/BUILD.gn
@@ -0,0 +1,55 @@
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+declare_args() {
+ skia_use_system_lua = false
+}
+
+import("../third_party.gni")
+
+if (skia_use_system_lua) {
+ system("lua") {
+ libs = [ "lua" ]
+ }
+} else {
+ third_party("lua") {
+ public_include_dirs = [ "src" ]
+
+ sources = [
+ "src/lapi.c",
+ "src/lauxlib.c",
+ "src/lbaselib.c",
+ "src/lbitlib.c",
+ "src/lcode.c",
+ "src/lcorolib.c",
+ "src/lctype.c",
+ "src/ldblib.c",
+ "src/ldebug.c",
+ "src/ldo.c",
+ "src/ldump.c",
+ "src/lfunc.c",
+ "src/lgc.c",
+ "src/linit.c",
+ "src/liolib.c",
+ "src/llex.c",
+ "src/lmathlib.c",
+ "src/lmem.c",
+ "src/loadlib.c",
+ "src/lobject.c",
+ "src/lopcodes.c",
+ "src/loslib.c",
+ "src/lparser.c",
+ "src/lstate.c",
+ "src/lstring.c",
+ "src/lstrlib.c",
+ "src/ltable.c",
+ "src/ltablib.c",
+ "src/ltm.c",
+ "src/lundump.c",
+ "src/lvm.c",
+ "src/lzio.c",
+ ]
+ }
+}
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index bd8fda1569..68a610ec4b 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -31,13 +31,13 @@ static const char gSummarizeFunc[] = "sk_scrape_summarize";
// Example usage for the modulo flag:
// for i in {0..5}; do lua_pictures --skpPath SKP_PATH -l YOUR_SCRIPT --modulo $i 6 &; done
-DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
+static DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
"testIndex %% divisor == remainder.");
-DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir");
-DEFINE_string2(luaFile, l, "", "File containing lua script to run");
-DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning");
-DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
-DEFINE_bool2(quiet, q, false, "Silence all non-error related output");
+static DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir");
+static DEFINE_string2(luaFile, l, "", "File containing lua script to run");
+static DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning");
+static DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
+static DEFINE_bool2(quiet, q, false, "Silence all non-error related output");
static sk_sp<SkPicture> load_picture(const char path[]) {
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);