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