When we opt into Lua, this builds SampleLua into SampleApp, and the lua_app and lua_pictures tools.
I've tested this builds with and without skia_use_system_lua on my Mac laptop and Linux desktop.
I've made lua_pictures.cpp's flags static to avoid conflicts with flags in SkCommonFlags.cpp.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4699
DOCS_PREVIEW= https://skia.org/?cl=4699
Change-Id: I8176fd51d8a38746e7d730cfcce66da42b9a015a
Reviewed-on: https://skia-review.googlesource.com/4699
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
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
}
}
+ 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" ]
":views",
":xml",
]
+
+ if (skia_use_lua) {
+ sources += [ "samplecode/SampleLua.cpp" ]
+ deps += [
+ ":lua",
+ "//third_party/lua",
+ ]
+ }
}
executable("dm") {
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
> 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.
-
--- /dev/null
+# 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",
+ ]
+ }
+}
// 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);