OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkLua.h" | 8 #include "SkLua.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 template <typename T> T* get_ref(lua_State* L, int index) { | 45 template <typename T> T* get_ref(lua_State* L, int index) { |
46 const T* ref = NULL; | 46 const T* ref = NULL; |
47 return *(T**)luaL_checkudata(L, index, get_mtname(*ref)); | 47 return *(T**)luaL_checkudata(L, index, get_mtname(*ref)); |
48 } | 48 } |
49 | 49 |
50 template <typename T> T* get_obj(lua_State* L, int index) { | 50 template <typename T> T* get_obj(lua_State* L, int index) { |
51 const T* obj = NULL; | 51 const T* obj = NULL; |
52 return (T*)luaL_checkudata(L, index, get_mtname(*obj)); | 52 return (T*)luaL_checkudata(L, index, get_mtname(*obj)); |
53 } | 53 } |
54 | 54 |
| 55 static bool lua2bool(lua_State* L, int index) { |
| 56 return !!lua_toboolean(L, index); |
| 57 } |
| 58 |
55 /////////////////////////////////////////////////////////////////////////////// | 59 /////////////////////////////////////////////////////////////////////////////// |
56 | 60 |
57 static void setfield_string(lua_State* L, const char key[], const char value[])
{ | 61 static void setfield_string(lua_State* L, const char key[], const char value[])
{ |
58 lua_pushstring(L, value); | 62 lua_pushstring(L, value); |
59 lua_setfield(L, -2, key); | 63 lua_setfield(L, -2, key); |
60 } | 64 } |
61 | 65 |
62 static void setfield_number(lua_State* L, const char key[], double value) { | 66 static void setfield_number(lua_State* L, const char key[], double value) { |
63 lua_pushnumber(L, value); | 67 lua_pushnumber(L, value); |
64 lua_setfield(L, -2, key); | 68 lua_setfield(L, -2, key); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 }; | 241 }; |
238 | 242 |
239 /////////////////////////////////////////////////////////////////////////////// | 243 /////////////////////////////////////////////////////////////////////////////// |
240 | 244 |
241 static int lpaint_isAntiAlias(lua_State* L) { | 245 static int lpaint_isAntiAlias(lua_State* L) { |
242 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias()); | 246 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias()); |
243 return 1; | 247 return 1; |
244 } | 248 } |
245 | 249 |
246 static int lpaint_setAntiAlias(lua_State* L) { | 250 static int lpaint_setAntiAlias(lua_State* L) { |
247 get_obj<SkPaint>(L, 1)->setAntiAlias(lua_toboolean(L, 2)); | 251 get_obj<SkPaint>(L, 1)->setAntiAlias(lua2bool(L, 2)); |
248 return 0; | 252 return 0; |
249 } | 253 } |
250 | 254 |
251 static int lpaint_getColor(lua_State* L) { | 255 static int lpaint_getColor(lua_State* L) { |
252 SkLua(L).pushColor(get_obj<SkPaint>(L, 1)->getColor()); | 256 SkLua(L).pushColor(get_obj<SkPaint>(L, 1)->getColor()); |
253 return 1; | 257 return 1; |
254 } | 258 } |
255 | 259 |
256 static int lpaint_setColor(lua_State* L) { | 260 static int lpaint_setColor(lua_State* L) { |
257 get_obj<SkPaint>(L, 1)->setColor(lua2color(L, 2)); | 261 get_obj<SkPaint>(L, 1)->setColor(lua2color(L, 2)); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 lua_pop(L, 1); /* pop off the meta-table */ \ | 469 lua_pop(L, 1); /* pop off the meta-table */ \ |
466 } while (0) | 470 } while (0) |
467 | 471 |
468 void SkLua::Load(lua_State* L) { | 472 void SkLua::Load(lua_State* L) { |
469 REG_CLASS(L, SkCanvas); | 473 REG_CLASS(L, SkCanvas); |
470 REG_CLASS(L, SkPath); | 474 REG_CLASS(L, SkPath); |
471 REG_CLASS(L, SkPaint); | 475 REG_CLASS(L, SkPaint); |
472 REG_CLASS(L, SkRRect); | 476 REG_CLASS(L, SkRRect); |
473 } | 477 } |
474 | 478 |
OLD | NEW |