michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkLua_DEFINED michael@0: #define SkLua_DEFINED michael@0: michael@0: #include "SkClipStack.h" michael@0: #include "SkColor.h" michael@0: #include "SkScalar.h" michael@0: #include "SkString.h" michael@0: michael@0: struct lua_State; michael@0: michael@0: class SkCanvas; michael@0: class SkMatrix; michael@0: class SkPaint; michael@0: class SkPath; michael@0: struct SkRect; michael@0: class SkRRect; michael@0: michael@0: #define SkScalarToLua(x) SkScalarToDouble(x) michael@0: #define SkLuaToScalar(x) SkDoubleToScalar(x) michael@0: michael@0: class SkLua { michael@0: public: michael@0: static void Load(lua_State*); michael@0: michael@0: SkLua(const char termCode[] = NULL); // creates a new L, will close it michael@0: SkLua(lua_State*); // uses L, will not close it michael@0: ~SkLua(); michael@0: michael@0: lua_State* get() const { return fL; } michael@0: lua_State* operator*() const { return fL; } michael@0: lua_State* operator->() const { return fL; } michael@0: michael@0: bool runCode(const char code[]); michael@0: bool runCode(const void* code, size_t size); michael@0: michael@0: void pushBool(bool, const char tableKey[] = NULL); michael@0: void pushString(const char[], const char tableKey[] = NULL); michael@0: void pushString(const char[], size_t len, const char tableKey[] = NULL); michael@0: void pushString(const SkString&, const char tableKey[] = NULL); michael@0: void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL); michael@0: void pushColor(SkColor, const char tableKey[] = NULL); michael@0: void pushU32(uint32_t, const char tableKey[] = NULL); michael@0: void pushScalar(SkScalar, const char tableKey[] = NULL); michael@0: void pushRect(const SkRect&, const char tableKey[] = NULL); michael@0: void pushRRect(const SkRRect&, const char tableKey[] = NULL); michael@0: void pushMatrix(const SkMatrix&, const char tableKey[] = NULL); michael@0: void pushPaint(const SkPaint&, const char tableKey[] = NULL); michael@0: void pushPath(const SkPath&, const char tableKey[] = NULL); michael@0: void pushCanvas(SkCanvas*, const char tableKey[] = NULL); michael@0: void pushClipStack(const SkClipStack&, const char tableKey[] = NULL); michael@0: void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL); michael@0: michael@0: // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas. michael@0: static int lcanvas_getReducedClipStack(lua_State* L); michael@0: michael@0: private: michael@0: lua_State* fL; michael@0: SkString fTermCode; michael@0: bool fWeOwnL; michael@0: }; michael@0: michael@0: #endif