blob: 651c4a71d5459669029f1f4e7e8dde08ef3e859a [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
11#include "SkColor.h"
commit-bot@chromium.org4d803a92014-05-14 16:03:14 +000012#include "SkPathEffect.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000013#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;
fmalitab7425172014-08-26 07:56:44 -070024class SkTextBlob;
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
Ben Wagnera93a14a2017-08-28 10:34:05 -040033 SkLua(const char termCode[] = nullptr); // creates a new L, will close it
reed@google.com3597b732013-05-22 20:12:50 +000034 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
Ben Wagnera93a14a2017-08-28 10:34:05 -040044 void pushBool(bool, const char tableKey[] = nullptr);
45 void pushString(const char[], const char tableKey[] = nullptr);
46 void pushString(const char[], size_t len, const char tableKey[] = nullptr);
47 void pushString(const SkString&, const char tableKey[] = nullptr);
48 void pushArrayU16(const uint16_t[], int count, const char tableKey[] = nullptr);
49 void pushArrayPoint(const SkPoint[], int count, const char key[] = nullptr);
50 void pushArrayScalar(const SkScalar[], int count, const char key[] = nullptr);
51 void pushColor(SkColor, const char tableKey[] = nullptr);
52 void pushU32(uint32_t, const char tableKey[] = nullptr);
53 void pushScalar(SkScalar, const char tableKey[] = nullptr);
54 void pushRect(const SkRect&, const char tableKey[] = nullptr);
55 void pushRRect(const SkRRect&, const char tableKey[] = nullptr);
56 void pushDash(const SkPathEffect::DashInfo&, const char tableKey[] = nullptr);
57 void pushMatrix(const SkMatrix&, const char tableKey[] = nullptr);
58 void pushPaint(const SkPaint&, const char tableKey[] = nullptr);
59 void pushPath(const SkPath&, const char tableKey[] = nullptr);
60 void pushCanvas(SkCanvas*, const char tableKey[] = nullptr);
61 void pushTextBlob(const SkTextBlob*, const char tableKey[] = nullptr);
bsalomon@google.com4ebe3822014-02-26 20:22:32 +000062
reed@google.com74ce6f02013-05-22 15:13:18 +000063private:
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