SkLua.h 2.3 KB

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