1/* 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 "SkClipStack.h" 12#include "SkColor.h" 13#include "SkPathEffect.h" 14#include "SkScalar.h" 15#include "SkString.h" 16 17struct lua_State; 18 19class SkCanvas; 20class SkMatrix; 21class SkPaint; 22class SkPath; 23struct SkRect; 24class SkRRect; 25class SkTextBlob; 26 27#define SkScalarToLua(x) SkScalarToDouble(x) 28#define SkLuaToScalar(x) SkDoubleToScalar(x) 29 30class SkLua { 31public: 32 static void Load(lua_State*); 33 34 SkLua(const char termCode[] = NULL); // creates a new L, will close it 35 SkLua(lua_State*); // uses L, will not close it 36 ~SkLua(); 37 38 lua_State* get() const { return fL; } 39 lua_State* operator*() const { return fL; } 40 lua_State* operator->() const { return fL; } 41 42 bool runCode(const char code[]); 43 bool runCode(const void* code, size_t size); 44 45 void pushBool(bool, const char tableKey[] = NULL); 46 void pushString(const char[], const char tableKey[] = NULL); 47 void pushString(const char[], size_t len, const char tableKey[] = NULL); 48 void pushString(const SkString&, const char tableKey[] = NULL); 49 void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL); 50 void pushArrayPoint(const SkPoint[], int count, const char key[] = NULL); 51 void pushArrayScalar(const SkScalar[], int count, const char key[] = NULL); 52 void pushColor(SkColor, const char tableKey[] = NULL); 53 void pushU32(uint32_t, const char tableKey[] = NULL); 54 void pushScalar(SkScalar, const char tableKey[] = NULL); 55 void pushRect(const SkRect&, const char tableKey[] = NULL); 56 void pushRRect(const SkRRect&, const char tableKey[] = NULL); 57 void pushDash(const SkPathEffect::DashInfo&, const char tableKey[] = NULL); 58 void pushMatrix(const SkMatrix&, const char tableKey[] = NULL); 59 void pushPaint(const SkPaint&, const char tableKey[] = NULL); 60 void pushPath(const SkPath&, const char tableKey[] = NULL); 61 void pushCanvas(SkCanvas*, const char tableKey[] = NULL); 62 void pushClipStack(const SkClipStack&, const char tableKey[] = NULL); 63 void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL); 64 void pushTextBlob(const SkTextBlob*, const char tableKey[] = NULL); 65 66 // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas. 67 static int lcanvas_getReducedClipStack(lua_State* L); 68 69private: 70 lua_State* fL; 71 SkString fTermCode; 72 bool fWeOwnL; 73}; 74 75#endif 76