reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkLua_DEFINED |
| 9 | #define SkLua_DEFINED |
| 10 | |
| 11 | #include "SkColor.h" |
| 12 | #include "SkScalar.h" |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 14 | |
| 15 | struct lua_State; |
| 16 | |
| 17 | class SkCanvas; |
| 18 | class SkMatrix; |
| 19 | class SkPaint; |
| 20 | class SkPath; |
| 21 | struct SkRect; |
| 22 | class SkRRect; |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 23 | |
| 24 | #define SkScalarToLua(x) SkScalarToDouble(x) |
| 25 | #define SkLuaToScalar(x) SkDoubleToScalar(x) |
| 26 | |
| 27 | class SkLua { |
| 28 | public: |
| 29 | static void Load(lua_State*); |
| 30 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 31 | SkLua(const char termCode[] = NULL); // creates a new L, will close it |
| 32 | SkLua(lua_State*); // uses L, will not close it |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 33 | ~SkLua(); |
| 34 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 35 | lua_State* get() const { return fL; } |
| 36 | lua_State* operator*() const { return fL; } |
| 37 | lua_State* operator->() const { return fL; } |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 38 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 39 | bool runCode(const char code[]); |
| 40 | bool runCode(const void* code, size_t size); |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 41 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 42 | void pushBool(bool, const char tableKey[] = NULL); |
| 43 | void pushString(const char[], const char tableKey[] = NULL); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame^] | 44 | void pushString(const char[], size_t len, const char tableKey[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 45 | void pushString(const SkString&, const char tableKey[] = NULL); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame^] | 46 | void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 47 | void pushColor(SkColor, const char tableKey[] = NULL); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame^] | 48 | void pushU32(uint32_t, const char tableKey[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 49 | void pushScalar(SkScalar, const char tableKey[] = NULL); |
| 50 | void pushRect(const SkRect&, const char tableKey[] = NULL); |
| 51 | void pushRRect(const SkRRect&, const char tableKey[] = NULL); |
| 52 | void pushMatrix(const SkMatrix&, const char tableKey[] = NULL); |
| 53 | void pushPaint(const SkPaint&, const char tableKey[] = NULL); |
| 54 | void pushPath(const SkPath&, const char tableKey[] = NULL); |
| 55 | void pushCanvas(SkCanvas*, const char tableKey[] = NULL); |
| 56 | |
| 57 | private: |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 58 | lua_State* fL; |
| 59 | SkString fTermCode; |
| 60 | bool fWeOwnL; |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif |