Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1150)

Unified Diff: src/utils/SkLua.cpp

Issue 15773002: use macro to encapsulate building get_mtname() specializations (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleLua.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkLua.cpp
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index c425a262b67182ef3e0f654d51ad4b61ab350136..ca6f493f57abaeedb911ca8ea14d57ffd3860566 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -19,12 +19,18 @@ extern "C" {
#include "lauxlib.h"
}
+// return the metatable name for a given class
template <typename T> const char* get_mtname();
-template <> const char* get_mtname<SkCanvas>() { return "SkCanvas_LuaMetaTableName"; }
-template <> const char* get_mtname<SkMatrix>() { return "SkMatrix_LuaMetaTableName"; }
-template <> const char* get_mtname<SkRRect>() { return "SkSkRRect_LuaMetaTableName"; }
-template <> const char* get_mtname<SkPath>() { return "SkPath_LuaMetaTableName"; }
-template <> const char* get_mtname<SkPaint>() { return "SkPaint_LuaMetaTableName"; }
+#define DEF_MTNAME(T) \
+ template <> const char* get_mtname<T>() { \
+ return #T "_LuaMetaTableName"; \
+ }
+
+DEF_MTNAME(SkCanvas)
+DEF_MTNAME(SkMatrix)
+DEF_MTNAME(SkRRect)
+DEF_MTNAME(SkPath)
+DEF_MTNAME(SkPaint)
template <typename T> T* push_new(lua_State* L) {
T* addr = (T*)lua_newuserdata(L, sizeof(T));
@@ -247,6 +253,12 @@ static int lcanvas_drawCircle(lua_State* L) {
return 0;
}
+static int lcanvas_drawPath(lua_State* L) {
+ get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
+ *get_obj<SkPaint>(L, 3));
+ return 0;
+}
+
static int lcanvas_getSaveCount(lua_State* L) {
lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount());
return 1;
@@ -272,6 +284,7 @@ static const struct luaL_Reg gSkCanvas_Methods[] = {
{ "drawRect", lcanvas_drawRect },
{ "drawOval", lcanvas_drawOval },
{ "drawCircle", lcanvas_drawCircle },
+ { "drawPath", lcanvas_drawPath },
{ "getSaveCount", lcanvas_getSaveCount },
{ "getTotalMatrix", lcanvas_getTotalMatrix },
{ "translate", lcanvas_translate },
« no previous file with comments | « samplecode/SampleLua.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698