OLD | NEW |
(Empty) | |
| 1 Skia Lua Bindings |
| 2 ================= |
| 3 |
| 4 **Warning: The following has only been tested on Linux, but it will likely |
| 5 work for any Unix.** |
| 6 |
| 7 Prerequisites |
| 8 ------------- |
| 9 |
| 10 This assumes one already has Skia building normally. If not, refer to the |
| 11 quick start guides. In addition to that, you will need Lua 5.2 installed on |
| 12 your system in order to use the bindings. |
| 13 |
| 14 Building lua requires the readline development library. If missing this can be i
nstalled (on Ubuntu) by executing: |
| 15 |
| 16 * `apt-cache search libreadline` to see the available libreadline libraries |
| 17 * `sudo apt-get install libreadline6 libreadline6-dev` to actually install the
libraries |
| 18 |
| 19 Build |
| 20 ----- |
| 21 |
| 22 The build process starts the same way as described in the quick starts, but |
| 23 before using gyp or make, do this instead: |
| 24 |
| 25 $ export GYP_DEFINES="skia_shared_lib=1" |
| 26 $ make tools |
| 27 |
| 28 This tells Skia to build as a shared library, which enables a build of another s
hared library called 'skia.so' that exposes Skia bindings to Lua. |
| 29 |
| 30 Try It Out |
| 31 ---------- |
| 32 |
| 33 Once the build is complete, use the same terminal: |
| 34 |
| 35 $ cd out/Debug/ |
| 36 $ lua |
| 37 |
| 38 Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio |
| 39 > require 'skia' |
| 40 > paint = Sk.newPaint() |
| 41 > paint:setColor{a=1, r=1, g=0, b=0} |
| 42 > doc = Sk.newDocumentPDF('test.pdf') |
| 43 > canvas = doc:beginPage(72*8.5, 72*11) |
| 44 > canvas:drawText('Hello Lua', 300, 300, paint) |
| 45 > doc:close() |
| 46 |
| 47 The key part to loading the bindings is `require 'skia'` which tells lua to look |
| 48 for 'skia.so' in the current directory (among many others) and provides the |
| 49 bindings. 'skia.so' in turn will load 'libskia.so' from the current directory or |
| 50 in our case the lib.target directory. 'libskia.so' is what contains the native |
| 51 skia code. The script shown above uses skia to draw Hello Lua in red text onto |
| 52 a pdf that will be outputted into the current folder as 'test.pdf'. Go ahead and |
| 53 open 'test.pdf' to confirm that everything is working. |
| 54 |
OLD | NEW |