aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/utils/SkLua.h
blob: ad6f996ac3fe65954a3ca12f795231f3836e0a2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkLua_DEFINED
#define SkLua_DEFINED

#include "SkClipStack.h"
#include "SkColor.h"
#include "SkPathEffect.h"
#include "SkScalar.h"
#include "SkString.h"

struct lua_State;

class SkCanvas;
class SkMatrix;
class SkPaint;
class SkPath;
struct SkRect;
class SkRRect;
class SkTextBlob;

#define SkScalarToLua(x)    SkScalarToDouble(x)
#define SkLuaToScalar(x)    SkDoubleToScalar(x)

class SkLua {
public:
    static void Load(lua_State*);

    SkLua(const char termCode[] = NULL);    // creates a new L, will close it
    SkLua(lua_State*);                      // uses L, will not close it
    ~SkLua();

    lua_State* get() const { return fL; }
    lua_State* operator*() const { return fL; }
    lua_State* operator->() const { return fL; }

    bool runCode(const char code[]);
    bool runCode(const void* code, size_t size);

    void pushBool(bool, const char tableKey[] = NULL);
    void pushString(const char[], const char tableKey[] = NULL);
    void pushString(const char[], size_t len, const char tableKey[] = NULL);
    void pushString(const SkString&, const char tableKey[] = NULL);
    void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL);
    void pushArrayPoint(const SkPoint[], int count, const char key[] = NULL);
    void pushArrayScalar(const SkScalar[], int count, const char key[] = NULL);
    void pushColor(SkColor, const char tableKey[] = NULL);
    void pushU32(uint32_t, const char tableKey[] = NULL);
    void pushScalar(SkScalar, const char tableKey[] = NULL);
    void pushRect(const SkRect&, const char tableKey[] = NULL);
    void pushRRect(const SkRRect&, const char tableKey[] = NULL);
    void pushDash(const SkPathEffect::DashInfo&, const char tableKey[] = NULL);
    void pushMatrix(const SkMatrix&, const char tableKey[] = NULL);
    void pushPaint(const SkPaint&, const char tableKey[] = NULL);
    void pushPath(const SkPath&, const char tableKey[] = NULL);
    void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
    void pushClipStack(const SkClipStack&, const char tableKey[] = NULL);
    void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL);
    void pushTextBlob(const SkTextBlob*, const char tableKey[] = NULL);

    // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas.
    static int lcanvas_getReducedClipStack(lua_State* L);

private:
    lua_State*  fL;
    SkString    fTermCode;
    bool        fWeOwnL;
};

#endif