blob: 2f29343d595c4f863245ad0591e84297e058dddf [file] [log] [blame]
reed@google.com74ce6f02013-05-22 15:13:18 +00001/*
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
bsalomon@google.com4ebe3822014-02-26 20:22:32 +000011#include "SkClipStack.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000012#include "SkColor.h"
13#include "SkScalar.h"
reed@google.com3597b732013-05-22 20:12:50 +000014#include "SkString.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000015
16struct lua_State;
17
18class SkCanvas;
19class SkMatrix;
20class SkPaint;
21class SkPath;
22struct SkRect;
23class SkRRect;
reed@google.com74ce6f02013-05-22 15:13:18 +000024
25#define SkScalarToLua(x) SkScalarToDouble(x)
26#define SkLuaToScalar(x) SkDoubleToScalar(x)
27
28class SkLua {
29public:
30 static void Load(lua_State*);
31
reed@google.com3597b732013-05-22 20:12:50 +000032 SkLua(const char termCode[] = NULL); // creates a new L, will close it
33 SkLua(lua_State*); // uses L, will not close it
reed@google.com74ce6f02013-05-22 15:13:18 +000034 ~SkLua();
35
reed@google.com3597b732013-05-22 20:12:50 +000036 lua_State* get() const { return fL; }
37 lua_State* operator*() const { return fL; }
38 lua_State* operator->() const { return fL; }
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +000039
reed@google.com3597b732013-05-22 20:12:50 +000040 bool runCode(const char code[]);
41 bool runCode(const void* code, size_t size);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +000042
reed@google.com74ce6f02013-05-22 15:13:18 +000043 void pushBool(bool, const char tableKey[] = NULL);
44 void pushString(const char[], const char tableKey[] = NULL);
reed@google.come3823fd2013-05-30 18:55:14 +000045 void pushString(const char[], size_t len, const char tableKey[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000046 void pushString(const SkString&, const char tableKey[] = NULL);
reed@google.come3823fd2013-05-30 18:55:14 +000047 void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000048 void pushColor(SkColor, const char tableKey[] = NULL);
reed@google.come3823fd2013-05-30 18:55:14 +000049 void pushU32(uint32_t, const char tableKey[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000050 void pushScalar(SkScalar, const char tableKey[] = NULL);
51 void pushRect(const SkRect&, const char tableKey[] = NULL);
52 void pushRRect(const SkRRect&, const char tableKey[] = NULL);
53 void pushMatrix(const SkMatrix&, const char tableKey[] = NULL);
54 void pushPaint(const SkPaint&, const char tableKey[] = NULL);
55 void pushPath(const SkPath&, const char tableKey[] = NULL);
56 void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
commit-bot@chromium.org5cc25352014-02-24 18:59:48 +000057 void pushClipStack(const SkClipStack&, const char tableKey[] = NULL);
bsalomon@google.com4ebe3822014-02-26 20:22:32 +000058 void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL);
59
60 // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas.
61 static int lcanvas_getReducedClipStack(lua_State* L);
reed@google.com74ce6f02013-05-22 15:13:18 +000062
63private:
reed@google.com3597b732013-05-22 20:12:50 +000064 lua_State* fL;
65 SkString fTermCode;
66 bool fWeOwnL;
reed@google.com74ce6f02013-05-22 15:13:18 +000067};
68
69#endif