Add asADash to Lua for scraping

BUG=skia:
R=robertphillips@google.com, reed@google.com

Author: egdaniel@google.com

Review URL: https://codereview.chromium.org/267423006

git-svn-id: http://skia.googlecode.com/svn/trunk@14733 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/utils/SkLua.h b/include/utils/SkLua.h
index 9a1ebfd..a7fceaa 100644
--- a/include/utils/SkLua.h
+++ b/include/utils/SkLua.h
@@ -10,6 +10,7 @@
 
 #include "SkClipStack.h"
 #include "SkColor.h"
+#include "SkPathEffect.h"
 #include "SkScalar.h"
 #include "SkString.h"
 
@@ -46,11 +47,13 @@
     void pushString(const SkString&, const char tableKey[] = NULL);
     void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL);
     void pushArrayPoint(const SkPoint[], int count, const char key[] = NULL);
+    void pushArrayScalar(const SkScalar[], int count, const char key[] = NULL);
     void pushColor(SkColor, const char tableKey[] = NULL);
     void pushU32(uint32_t, const char tableKey[] = NULL);
     void pushScalar(SkScalar, const char tableKey[] = NULL);
     void pushRect(const SkRect&, const char tableKey[] = NULL);
     void pushRRect(const SkRRect&, const char tableKey[] = NULL);
+    void pushDash(const SkPathEffect::DashInfo&, const char tableKey[] = NULL);
     void pushMatrix(const SkMatrix&, const char tableKey[] = NULL);
     void pushPaint(const SkPaint&, const char tableKey[] = NULL);
     void pushPath(const SkPath&, const char tableKey[] = NULL);
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 346899a..5047877 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -18,7 +18,6 @@
 #include "SkMatrix.h"
 #include "SkPaint.h"
 #include "SkPath.h"
-#include "SkPathEffect.h"
 #include "SkPixelRef.h"
 #include "SkRRect.h"
 #include "SkString.h"
@@ -157,6 +156,10 @@
     lua_rawseti(L, -2, index);
 }
 
+static void setarray_scalar(lua_State* L, int index, SkScalar value) {
+    setarray_number(L, index, SkScalarToLua(value));
+}
+
 void SkLua::pushBool(bool value, const char key[]) {
     lua_pushboolean(fL, value);
     CHECK_SETFIELD(key);
@@ -219,6 +222,15 @@
     CHECK_SETFIELD(key);
 }
 
+void SkLua::pushArrayScalar(const SkScalar array[], int count, const char key[]) {
+    lua_newtable(fL);
+    for (int i = 0; i < count; ++i) {
+        // make it base-1 to match lua convention
+        setarray_scalar(fL, i + 1, array[i]);
+    }
+    CHECK_SETFIELD(key);
+}
+
 void SkLua::pushRect(const SkRect& r, const char key[]) {
     lua_newtable(fL);
     setfield_scalar(fL, "left", r.fLeft);
@@ -233,6 +245,14 @@
     CHECK_SETFIELD(key);
 }
 
+void SkLua::pushDash(const SkPathEffect::DashInfo& info, const char key[]) {
+    lua_newtable(fL);
+    setfield_scalar(fL, "phase", info.fPhase);
+    this->pushArrayScalar(info.fIntervals, info.fCount, "intervals");
+    CHECK_SETFIELD(key);
+}
+
+
 void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) {
     push_obj(fL, matrix);
     CHECK_SETFIELD(key);
@@ -1006,12 +1026,29 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+static int lpatheffect_asADash(lua_State* L) {
+    SkPathEffect* pe = get_ref<SkPathEffect>(L, 1);
+    if (pe) {
+        SkPathEffect::DashInfo info;
+        SkPathEffect::DashType dashType = pe->asADash(&info);
+        if (SkPathEffect::kDash_DashType == dashType) {
+            SkAutoTArray<SkScalar> intervals(info.fCount);
+            info.fIntervals = intervals.get();
+            pe->asADash(&info);
+            SkLua(L).pushDash(info);
+            return 1;
+        }
+    }
+    return 0;
+}
+
 static int lpatheffect_gc(lua_State* L) {
     get_ref<SkPathEffect>(L, 1)->unref();
     return 0;
 }
 
 static const struct luaL_Reg gSkPathEffect_Methods[] = {
+    { "asADash",        lpatheffect_asADash },
     { "__gc",           lpatheffect_gc },
     { NULL, NULL }
 };