blob: 8f48bc1ee19fa054bfa0144d68325af70ccbf204 [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"
12#include "SkScalar.h"
reed@google.com3597b732013-05-22 20:12:50 +000013#include "SkString.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000014
15struct lua_State;
16
17class SkCanvas;
18class SkMatrix;
19class SkPaint;
20class SkPath;
21struct SkRect;
22class SkRRect;
reed@google.com74ce6f02013-05-22 15:13:18 +000023
24#define SkScalarToLua(x) SkScalarToDouble(x)
25#define SkLuaToScalar(x) SkDoubleToScalar(x)
26
27class SkLua {
28public:
29 static void Load(lua_State*);
30
reed@google.com3597b732013-05-22 20:12:50 +000031 SkLua(const char termCode[] = NULL); // creates a new L, will close it
32 SkLua(lua_State*); // uses L, will not close it
reed@google.com74ce6f02013-05-22 15:13:18 +000033 ~SkLua();
34
reed@google.com3597b732013-05-22 20:12:50 +000035 lua_State* get() const { return fL; }
36 lua_State* operator*() const { return fL; }
37 lua_State* operator->() const { return fL; }
38
39 bool runCode(const char code[]);
40 bool runCode(const void* code, size_t size);
41
reed@google.com74ce6f02013-05-22 15:13:18 +000042 void pushBool(bool, const char tableKey[] = NULL);
43 void pushString(const char[], const char tableKey[] = NULL);
44 void pushString(const SkString&, const char tableKey[] = NULL);
45 void pushColor(SkColor, const char tableKey[] = NULL);
46 void pushScalar(SkScalar, const char tableKey[] = NULL);
47 void pushRect(const SkRect&, const char tableKey[] = NULL);
48 void pushRRect(const SkRRect&, const char tableKey[] = NULL);
49 void pushMatrix(const SkMatrix&, const char tableKey[] = NULL);
50 void pushPaint(const SkPaint&, const char tableKey[] = NULL);
51 void pushPath(const SkPath&, const char tableKey[] = NULL);
52 void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
53
54private:
reed@google.com3597b732013-05-22 20:12:50 +000055 lua_State* fL;
56 SkString fTermCode;
57 bool fWeOwnL;
reed@google.com74ce6f02013-05-22 15:13:18 +000058};
59
60#endif