blob: a7fceaaa81370ff95b63f520300d0a34d4b95185 [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"
commit-bot@chromium.org4d803a92014-05-14 16:03:14 +000013#include "SkPathEffect.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000014#include "SkScalar.h"
reed@google.com3597b732013-05-22 20:12:50 +000015#include "SkString.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000016
17struct lua_State;
18
19class SkCanvas;
20class SkMatrix;
21class SkPaint;
22class SkPath;
23struct SkRect;
24class SkRRect;
reed@google.com74ce6f02013-05-22 15:13:18 +000025
26#define SkScalarToLua(x) SkScalarToDouble(x)
27#define SkLuaToScalar(x) SkDoubleToScalar(x)
28
29class SkLua {
30public:
31 static void Load(lua_State*);
32
reed@google.com3597b732013-05-22 20:12:50 +000033 SkLua(const char termCode[] = NULL); // creates a new L, will close it
34 SkLua(lua_State*); // uses L, will not close it
reed@google.com74ce6f02013-05-22 15:13:18 +000035 ~SkLua();
36
reed@google.com3597b732013-05-22 20:12:50 +000037 lua_State* get() const { return fL; }
38 lua_State* operator*() const { return fL; }
39 lua_State* operator->() const { return fL; }
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +000040
reed@google.com3597b732013-05-22 20:12:50 +000041 bool runCode(const char code[]);
42 bool runCode(const void* code, size_t size);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +000043
reed@google.com74ce6f02013-05-22 15:13:18 +000044 void pushBool(bool, const char tableKey[] = NULL);
45 void pushString(const char[], const char tableKey[] = NULL);
reed@google.come3823fd2013-05-30 18:55:14 +000046 void pushString(const char[], size_t len, const char tableKey[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000047 void pushString(const SkString&, const char tableKey[] = NULL);
reed@google.come3823fd2013-05-30 18:55:14 +000048 void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL);
commit-bot@chromium.org1301bf32014-03-17 23:09:47 +000049 void pushArrayPoint(const SkPoint[], int count, const char key[] = NULL);
commit-bot@chromium.org4d803a92014-05-14 16:03:14 +000050 void pushArrayScalar(const SkScalar[], int count, const char key[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000051 void pushColor(SkColor, const char tableKey[] = NULL);
reed@google.come3823fd2013-05-30 18:55:14 +000052 void pushU32(uint32_t, const char tableKey[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000053 void pushScalar(SkScalar, const char tableKey[] = NULL);
54 void pushRect(const SkRect&, const char tableKey[] = NULL);
55 void pushRRect(const SkRRect&, const char tableKey[] = NULL);
commit-bot@chromium.org4d803a92014-05-14 16:03:14 +000056 void pushDash(const SkPathEffect::DashInfo&, const char tableKey[] = NULL);
reed@google.com74ce6f02013-05-22 15:13:18 +000057 void pushMatrix(const SkMatrix&, const char tableKey[] = NULL);
58 void pushPaint(const SkPaint&, const char tableKey[] = NULL);
59 void pushPath(const SkPath&, const char tableKey[] = NULL);
60 void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
commit-bot@chromium.org5cc25352014-02-24 18:59:48 +000061 void pushClipStack(const SkClipStack&, const char tableKey[] = NULL);
bsalomon@google.com4ebe3822014-02-26 20:22:32 +000062 void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL);
63
64 // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas.
65 static int lcanvas_getReducedClipStack(lua_State* L);
reed@google.com74ce6f02013-05-22 15:13:18 +000066
67private:
reed@google.com3597b732013-05-22 20:12:50 +000068 lua_State* fL;
69 SkString fTermCode;
70 bool fWeOwnL;
reed@google.com74ce6f02013-05-22 15:13:18 +000071};
72
73#endif