blob: bd453e3d1bfc6ce566e20a3f4955a0f0917a363e [file] [log] [blame]
reed@google.com74ce6f02013-05-22 15:13:18 +00001/*
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#include "SkLua.h"
9#include "SkCanvas.h"
10#include "SkPaint.h"
11#include "SkPath.h"
12#include "SkMatrix.h"
13#include "SkRRect.h"
14#include "SkString.h"
reed@google.come3823fd2013-05-30 18:55:14 +000015#include "SkTypeface.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000016
17extern "C" {
reed@google.com3597b732013-05-22 20:12:50 +000018 #include "lua.h"
19 #include "lualib.h"
20 #include "lauxlib.h"
reed@google.com74ce6f02013-05-22 15:13:18 +000021}
22
reed@google.comfd345872013-05-22 20:53:42 +000023// return the metatable name for a given class
reed@google.com3597b732013-05-22 20:12:50 +000024template <typename T> const char* get_mtname();
reed@google.comfd345872013-05-22 20:53:42 +000025#define DEF_MTNAME(T) \
26 template <> const char* get_mtname<T>() { \
27 return #T "_LuaMetaTableName"; \
28 }
29
30DEF_MTNAME(SkCanvas)
31DEF_MTNAME(SkMatrix)
32DEF_MTNAME(SkRRect)
33DEF_MTNAME(SkPath)
34DEF_MTNAME(SkPaint)
reed@google.com74ce6f02013-05-22 15:13:18 +000035
reed@google.com3597b732013-05-22 20:12:50 +000036template <typename T> T* push_new(lua_State* L) {
37 T* addr = (T*)lua_newuserdata(L, sizeof(T));
38 new (addr) T;
39 luaL_getmetatable(L, get_mtname<T>());
40 lua_setmetatable(L, -2);
41 return addr;
42}
reed@google.com74ce6f02013-05-22 15:13:18 +000043
44template <typename T> void push_obj(lua_State* L, const T& obj) {
45 new (lua_newuserdata(L, sizeof(T))) T(obj);
reed@google.com3597b732013-05-22 20:12:50 +000046 luaL_getmetatable(L, get_mtname<T>());
reed@google.com74ce6f02013-05-22 15:13:18 +000047 lua_setmetatable(L, -2);
48}
49
50template <typename T> void push_ref(lua_State* L, T* ref) {
51 *(T**)lua_newuserdata(L, sizeof(T*)) = SkRef(ref);
reed@google.com3597b732013-05-22 20:12:50 +000052 luaL_getmetatable(L, get_mtname<T>());
reed@google.com74ce6f02013-05-22 15:13:18 +000053 lua_setmetatable(L, -2);
54}
55
56template <typename T> T* get_ref(lua_State* L, int index) {
reed@google.com3597b732013-05-22 20:12:50 +000057 return *(T**)luaL_checkudata(L, index, get_mtname<T>());
reed@google.com74ce6f02013-05-22 15:13:18 +000058}
59
60template <typename T> T* get_obj(lua_State* L, int index) {
reed@google.com3597b732013-05-22 20:12:50 +000061 return (T*)luaL_checkudata(L, index, get_mtname<T>());
reed@google.com74ce6f02013-05-22 15:13:18 +000062}
63
reed@google.com88c9ec92013-05-22 15:43:21 +000064static bool lua2bool(lua_State* L, int index) {
65 return !!lua_toboolean(L, index);
66}
67
reed@google.com74ce6f02013-05-22 15:13:18 +000068///////////////////////////////////////////////////////////////////////////////
69
reed@google.com3597b732013-05-22 20:12:50 +000070SkLua::SkLua(const char termCode[]) : fTermCode(termCode), fWeOwnL(true) {
71 fL = luaL_newstate();
72 luaL_openlibs(fL);
73 SkLua::Load(fL);
74}
75
76SkLua::SkLua(lua_State* L) : fL(L), fWeOwnL(false) {}
77
78SkLua::~SkLua() {
79 if (fWeOwnL) {
80 if (fTermCode.size() > 0) {
81 lua_getglobal(fL, fTermCode.c_str());
82 if (lua_pcall(fL, 0, 0, 0) != LUA_OK) {
83 SkDebugf("lua err: %s\n", lua_tostring(fL, -1));
84 }
85 }
86 lua_close(fL);
87 }
88}
89
90bool SkLua::runCode(const char code[]) {
91 int err = luaL_loadstring(fL, code) || lua_pcall(fL, 0, 0, 0);
92 if (err) {
93 SkDebugf("--- lua failed\n");
94 return false;
95 }
96 return true;
97}
98
99bool SkLua::runCode(const void* code, size_t size) {
100 SkString str((const char*)code, size);
101 return this->runCode(str.c_str());
102}
103
104///////////////////////////////////////////////////////////////////////////////
105
106#define CHECK_SETFIELD(key) do if (key) lua_setfield(fL, -2, key); while (0)
107
reed@google.com74ce6f02013-05-22 15:13:18 +0000108static void setfield_string(lua_State* L, const char key[], const char value[]) {
109 lua_pushstring(L, value);
110 lua_setfield(L, -2, key);
111}
112
113static void setfield_number(lua_State* L, const char key[], double value) {
114 lua_pushnumber(L, value);
115 lua_setfield(L, -2, key);
116}
117
reed@google.com3597b732013-05-22 20:12:50 +0000118static void setfield_function(lua_State* L,
119 const char key[], lua_CFunction value) {
120 lua_pushcfunction(L, value);
121 lua_setfield(L, -2, key);
reed@google.com74ce6f02013-05-22 15:13:18 +0000122}
123
reed@google.come3823fd2013-05-30 18:55:14 +0000124static void setarray_number(lua_State* L, int index, double value) {
125 lua_pushnumber(L, value);
126 lua_rawseti(L, -2, index);
127}
128
reed@google.com74ce6f02013-05-22 15:13:18 +0000129void SkLua::pushBool(bool value, const char key[]) {
130 lua_pushboolean(fL, value);
131 CHECK_SETFIELD(key);
132}
133
134void SkLua::pushString(const char str[], const char key[]) {
135 lua_pushstring(fL, str);
136 CHECK_SETFIELD(key);
137}
138
reed@google.come3823fd2013-05-30 18:55:14 +0000139void SkLua::pushString(const char str[], size_t length, const char key[]) {
140 // TODO: how to do this w/o making a copy?
141 SkString s(str, length);
142 lua_pushstring(fL, s.c_str());
143 CHECK_SETFIELD(key);
144}
145
reed@google.com74ce6f02013-05-22 15:13:18 +0000146void SkLua::pushString(const SkString& str, const char key[]) {
147 lua_pushstring(fL, str.c_str());
148 CHECK_SETFIELD(key);
149}
150
151void SkLua::pushColor(SkColor color, const char key[]) {
152 lua_newtable(fL);
153 setfield_number(fL, "a", SkColorGetA(color) / 255.0);
154 setfield_number(fL, "r", SkColorGetR(color) / 255.0);
155 setfield_number(fL, "g", SkColorGetG(color) / 255.0);
156 setfield_number(fL, "b", SkColorGetB(color) / 255.0);
157 CHECK_SETFIELD(key);
158}
159
reed@google.come3823fd2013-05-30 18:55:14 +0000160void SkLua::pushU32(uint32_t value, const char key[]) {
161 lua_pushnumber(fL, (double)value);
162 CHECK_SETFIELD(key);
163}
164
reed@google.com74ce6f02013-05-22 15:13:18 +0000165void SkLua::pushScalar(SkScalar value, const char key[]) {
166 lua_pushnumber(fL, SkScalarToLua(value));
167 CHECK_SETFIELD(key);
168}
169
reed@google.come3823fd2013-05-30 18:55:14 +0000170void SkLua::pushArrayU16(const uint16_t array[], int count, const char key[]) {
171 lua_newtable(fL);
172 for (int i = 0; i < count; ++i) {
173 // make it base-1 to match lua convention
174 setarray_number(fL, i + 1, (double)array[i]);
175 }
176 CHECK_SETFIELD(key);
177}
178
reed@google.com74ce6f02013-05-22 15:13:18 +0000179void SkLua::pushRect(const SkRect& r, const char key[]) {
180 lua_newtable(fL);
181 setfield_number(fL, "left", SkScalarToLua(r.fLeft));
182 setfield_number(fL, "top", SkScalarToLua(r.fTop));
183 setfield_number(fL, "right", SkScalarToLua(r.fRight));
184 setfield_number(fL, "bottom", SkScalarToLua(r.fBottom));
185 CHECK_SETFIELD(key);
186}
187
188void SkLua::pushRRect(const SkRRect& rr, const char key[]) {
189 push_obj(fL, rr);
190 CHECK_SETFIELD(key);
191}
192
193void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) {
194 push_obj(fL, matrix);
195 CHECK_SETFIELD(key);
196}
197
198void SkLua::pushPaint(const SkPaint& paint, const char key[]) {
199 push_obj(fL, paint);
200 CHECK_SETFIELD(key);
201}
202
203void SkLua::pushPath(const SkPath& path, const char key[]) {
204 push_obj(fL, path);
205 CHECK_SETFIELD(key);
206}
207
208void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) {
209 push_ref(fL, canvas);
210 CHECK_SETFIELD(key);
211}
212
213///////////////////////////////////////////////////////////////////////////////
214///////////////////////////////////////////////////////////////////////////////
215
216static SkScalar lua2scalar(lua_State* L, int index) {
217 SkASSERT(lua_isnumber(L, index));
218 return SkLuaToScalar(lua_tonumber(L, index));
219}
220
221static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) {
222 SkASSERT(lua_istable(L, index));
223 lua_pushstring(L, key);
224 lua_gettable(L, index);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000225
reed@google.com74ce6f02013-05-22 15:13:18 +0000226 SkScalar value = lua2scalar(L, -1);
227 lua_pop(L, 1);
228 return value;
229}
230
231static U8CPU unit2byte(SkScalar x) {
232 if (x <= 0) {
233 return 0;
234 } else if (x >= 1) {
235 return 255;
236 } else {
237 return SkScalarRoundToInt(x * 255);
238 }
239}
240
241static SkColor lua2color(lua_State* L, int index) {
242 return SkColorSetARGB(unit2byte(getfield_scalar(L, index, "a")),
243 unit2byte(getfield_scalar(L, index, "r")),
244 unit2byte(getfield_scalar(L, index, "g")),
245 unit2byte(getfield_scalar(L, index, "b")));
246}
247
248static SkRect* lua2rect(lua_State* L, int index, SkRect* rect) {
249 rect->set(getfield_scalar(L, index, "left"),
250 getfield_scalar(L, index, "top"),
251 getfield_scalar(L, index, "right"),
252 getfield_scalar(L, index, "bottom"));
253 return rect;
254}
255
256static int lcanvas_drawColor(lua_State* L) {
257 get_ref<SkCanvas>(L, 1)->drawColor(lua2color(L, 2));
258 return 0;
259}
260
261static int lcanvas_drawRect(lua_State* L) {
262 SkRect rect;
263 get_ref<SkCanvas>(L, 1)->drawRect(*lua2rect(L, 2, &rect),
264 *get_obj<SkPaint>(L, 3));
265 return 0;
266}
267
268static int lcanvas_drawOval(lua_State* L) {
269 SkRect rect;
270 get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect),
271 *get_obj<SkPaint>(L, 3));
272 return 0;
273}
274
275static int lcanvas_drawCircle(lua_State* L) {
276 get_ref<SkCanvas>(L, 1)->drawCircle(lua2scalar(L, 2),
277 lua2scalar(L, 3),
278 lua2scalar(L, 4),
279 *get_obj<SkPaint>(L, 5));
280 return 0;
281}
282
reed@google.comfd345872013-05-22 20:53:42 +0000283static int lcanvas_drawPath(lua_State* L) {
284 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
285 *get_obj<SkPaint>(L, 3));
286 return 0;
287}
288
reed@google.com74ce6f02013-05-22 15:13:18 +0000289static int lcanvas_getSaveCount(lua_State* L) {
290 lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount());
291 return 1;
292}
293
294static int lcanvas_getTotalMatrix(lua_State* L) {
295 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix());
296 return 1;
297}
298
reed@google.com3597b732013-05-22 20:12:50 +0000299static int lcanvas_translate(lua_State* L) {
300 get_ref<SkCanvas>(L, 1)->translate(lua2scalar(L, 2), lua2scalar(L, 3));
301 return 0;
302}
303
reed@google.com74ce6f02013-05-22 15:13:18 +0000304static int lcanvas_gc(lua_State* L) {
305 get_ref<SkCanvas>(L, 1)->unref();
306 return 0;
307}
308
309static const struct luaL_Reg gSkCanvas_Methods[] = {
310 { "drawColor", lcanvas_drawColor },
311 { "drawRect", lcanvas_drawRect },
312 { "drawOval", lcanvas_drawOval },
313 { "drawCircle", lcanvas_drawCircle },
reed@google.comfd345872013-05-22 20:53:42 +0000314 { "drawPath", lcanvas_drawPath },
reed@google.com74ce6f02013-05-22 15:13:18 +0000315 { "getSaveCount", lcanvas_getSaveCount },
316 { "getTotalMatrix", lcanvas_getTotalMatrix },
reed@google.com3597b732013-05-22 20:12:50 +0000317 { "translate", lcanvas_translate },
reed@google.com74ce6f02013-05-22 15:13:18 +0000318 { "__gc", lcanvas_gc },
319 { NULL, NULL }
320};
321
322///////////////////////////////////////////////////////////////////////////////
323
324static int lpaint_isAntiAlias(lua_State* L) {
325 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias());
326 return 1;
327}
328
329static int lpaint_setAntiAlias(lua_State* L) {
reed@google.com88c9ec92013-05-22 15:43:21 +0000330 get_obj<SkPaint>(L, 1)->setAntiAlias(lua2bool(L, 2));
reed@google.com74ce6f02013-05-22 15:13:18 +0000331 return 0;
332}
333
334static int lpaint_getColor(lua_State* L) {
335 SkLua(L).pushColor(get_obj<SkPaint>(L, 1)->getColor());
336 return 1;
337}
338
339static int lpaint_setColor(lua_State* L) {
340 get_obj<SkPaint>(L, 1)->setColor(lua2color(L, 2));
341 return 0;
342}
343
reed@google.come3823fd2013-05-30 18:55:14 +0000344static int lpaint_getTextSize(lua_State* L) {
345 SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getTextSize());
346 return 1;
347}
348
349static int lpaint_setTextSize(lua_State* L) {
350 get_obj<SkPaint>(L, 1)->setTextSize(lua2scalar(L, 2));
351 return 0;
352}
353
354static int lpaint_getFontID(lua_State* L) {
355 SkTypeface* face = get_obj<SkPaint>(L, 1)->getTypeface();
356 SkLua(L).pushU32(SkTypeface::UniqueID(face));
357 return 1;
358}
359
reed@google.com74ce6f02013-05-22 15:13:18 +0000360static int lpaint_gc(lua_State* L) {
361 get_obj<SkPaint>(L, 1)->~SkPaint();
362 return 0;
363}
364
365static const struct luaL_Reg gSkPaint_Methods[] = {
366 { "isAntiAlias", lpaint_isAntiAlias },
367 { "setAntiAlias", lpaint_setAntiAlias },
368 { "getColor", lpaint_getColor },
369 { "setColor", lpaint_setColor },
reed@google.come3823fd2013-05-30 18:55:14 +0000370 { "getTextSize", lpaint_getTextSize },
371 { "setTextSize", lpaint_setTextSize },
372 { "getFontID", lpaint_getFontID },
reed@google.com74ce6f02013-05-22 15:13:18 +0000373 { "__gc", lpaint_gc },
374 { NULL, NULL }
375};
376
377///////////////////////////////////////////////////////////////////////////////
378
379static int lpath_getBounds(lua_State* L) {
380 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds());
381 return 1;
382}
383
384static int lpath_isEmpty(lua_State* L) {
385 lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty());
386 return 1;
387}
388
389static int lpath_isRect(lua_State* L) {
390 SkRect r;
391 bool pred = get_obj<SkPath>(L, 1)->isRect(&r);
392 int ret_count = 1;
393 lua_pushboolean(L, pred);
394 if (pred) {
395 SkLua(L).pushRect(r);
396 ret_count += 1;
397 }
398 return ret_count;
399}
400
401static const char* dir2string(SkPath::Direction dir) {
402 static const char* gStr[] = {
403 "unknown", "cw", "ccw"
404 };
405 SkASSERT((unsigned)dir < SK_ARRAY_COUNT(gStr));
406 return gStr[dir];
407}
408
409static int lpath_isNestedRects(lua_State* L) {
410 SkRect rects[2];
411 SkPath::Direction dirs[2];
412 bool pred = get_obj<SkPath>(L, 1)->isNestedRects(rects, dirs);
413 int ret_count = 1;
414 lua_pushboolean(L, pred);
415 if (pred) {
416 SkLua lua(L);
417 lua.pushRect(rects[0]);
418 lua.pushRect(rects[1]);
419 lua_pushstring(L, dir2string(dirs[0]));
420 lua_pushstring(L, dir2string(dirs[0]));
421 ret_count += 4;
422 }
423 return ret_count;
424}
425
426static int lpath_reset(lua_State* L) {
427 get_obj<SkPath>(L, 1)->reset();
428 return 0;
429}
430
431static int lpath_moveTo(lua_State* L) {
432 get_obj<SkPath>(L, 1)->moveTo(lua2scalar(L, 2), lua2scalar(L, 3));
433 return 0;
434}
435
436static int lpath_lineTo(lua_State* L) {
437 get_obj<SkPath>(L, 1)->lineTo(lua2scalar(L, 2), lua2scalar(L, 3));
438 return 0;
439}
440
441static int lpath_quadTo(lua_State* L) {
442 get_obj<SkPath>(L, 1)->quadTo(lua2scalar(L, 2), lua2scalar(L, 3),
443 lua2scalar(L, 4), lua2scalar(L, 5));
444 return 0;
445}
446
447static int lpath_cubicTo(lua_State* L) {
448 get_obj<SkPath>(L, 1)->cubicTo(lua2scalar(L, 2), lua2scalar(L, 3),
449 lua2scalar(L, 4), lua2scalar(L, 5),
450 lua2scalar(L, 6), lua2scalar(L, 7));
451 return 0;
452}
453
454static int lpath_close(lua_State* L) {
455 get_obj<SkPath>(L, 1)->close();
456 return 0;
457}
458
459static int lpath_gc(lua_State* L) {
460 get_obj<SkPath>(L, 1)->~SkPath();
461 return 0;
462}
463
464static const struct luaL_Reg gSkPath_Methods[] = {
465 { "getBounds", lpath_getBounds },
466 { "isEmpty", lpath_isEmpty },
467 { "isRect", lpath_isRect },
468 { "isNestedRects", lpath_isNestedRects },
469 { "reset", lpath_reset },
470 { "moveTo", lpath_moveTo },
471 { "lineTo", lpath_lineTo },
472 { "quadTo", lpath_quadTo },
473 { "cubicTo", lpath_cubicTo },
474 { "close", lpath_close },
475 { "__gc", lpath_gc },
476 { NULL, NULL }
477};
478
479///////////////////////////////////////////////////////////////////////////////
480
481static const char* rrect_type(const SkRRect& rr) {
482 switch (rr.getType()) {
483 case SkRRect::kUnknown_Type: return "unknown";
484 case SkRRect::kEmpty_Type: return "empty";
485 case SkRRect::kRect_Type: return "rect";
486 case SkRRect::kOval_Type: return "oval";
487 case SkRRect::kSimple_Type: return "simple";
488 case SkRRect::kComplex_Type: return "complex";
489 }
490 SkASSERT(!"never get here");
491 return "";
492}
493
494static int lrrect_rect(lua_State* L) {
495 SkLua(L).pushRect(get_obj<SkRRect>(L, 1)->rect());
496 return 1;
497}
498
499static int lrrect_type(lua_State* L) {
500 lua_pushstring(L, rrect_type(*get_obj<SkRRect>(L, 1)));
501 return 1;
502}
503
504static int lrrect_radii(lua_State* L) {
505 int corner = lua_tointeger(L, 2);
506 SkVector v;
507 if (corner < 0 || corner > 3) {
508 SkDebugf("bad corner index %d", corner);
509 v.set(0, 0);
510 } else {
511 v = get_obj<SkRRect>(L, 1)->radii((SkRRect::Corner)corner);
512 }
513 lua_pushnumber(L, v.fX);
514 lua_pushnumber(L, v.fY);
515 return 2;
516}
517
518static int lrrect_gc(lua_State* L) {
519 get_obj<SkRRect>(L, 1)->~SkRRect();
520 return 0;
521}
522
523static const struct luaL_Reg gSkRRect_Methods[] = {
524 { "rect", lrrect_rect },
525 { "type", lrrect_type },
526 { "radii", lrrect_radii },
527 { "__gc", lrrect_gc },
528 { NULL, NULL }
529};
530
531///////////////////////////////////////////////////////////////////////////////
532
533class AutoCallLua {
534public:
535 AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) {
536 lua_getglobal(L, func);
537 if (!lua_isfunction(L, -1)) {
538 int t = lua_type(L, -1);
539 SkDebugf("--- expected function %d\n", t);
540 }
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000541
reed@google.com74ce6f02013-05-22 15:13:18 +0000542 lua_newtable(L);
543 setfield_string(L, "verb", verb);
544 }
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000545
reed@google.com74ce6f02013-05-22 15:13:18 +0000546 ~AutoCallLua() {
547 if (lua_pcall(fL, 1, 0, 0) != LUA_OK) {
548 SkDebugf("lua err: %s\n", lua_tostring(fL, -1));
549 }
550 lua_settop(fL, -1);
551 }
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000552
reed@google.com74ce6f02013-05-22 15:13:18 +0000553private:
554 lua_State* fL;
555};
556
557#define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb)
558
559///////////////////////////////////////////////////////////////////////////////
560
reed@google.com3597b732013-05-22 20:12:50 +0000561static int lsk_newPaint(lua_State* L) {
562 push_new<SkPaint>(L);
563 return 1;
564}
565
566static int lsk_newPath(lua_State* L) {
567 push_new<SkPath>(L);
568 return 1;
569}
570
571static int lsk_newRRect(lua_State* L) {
572 SkRRect* rr = push_new<SkRRect>(L);
573 rr->setEmpty();
574 return 1;
575}
576
577static const struct luaL_Reg gSk_Functions[] = {
578 { "newPaint", lsk_newPaint },
579 { "newPath", lsk_newPath },
580 { "newRRect", lsk_newRRect },
581 { NULL, NULL }
582};
583
584static void register_Sk(lua_State* L) {
585 lua_newtable(L);
586 lua_pushvalue(L, -1);
587 lua_setglobal(L, "Sk");
588 // the Sk table is still on top
589
590 setfield_function(L, "newPaint", lsk_newPaint);
591 setfield_function(L, "newPath", lsk_newPath);
592 setfield_function(L, "newRRect", lsk_newRRect);
593 lua_pop(L, 1); // pop off the Sk table
594}
595
reed@google.com74ce6f02013-05-22 15:13:18 +0000596#define REG_CLASS(L, C) \
597 do { \
reed@google.com3597b732013-05-22 20:12:50 +0000598 luaL_newmetatable(L, get_mtname<C>()); \
reed@google.com74ce6f02013-05-22 15:13:18 +0000599 lua_pushvalue(L, -1); \
600 lua_setfield(L, -2, "__index"); \
601 luaL_setfuncs(L, g##C##_Methods, 0); \
602 lua_pop(L, 1); /* pop off the meta-table */ \
603 } while (0)
604
605void SkLua::Load(lua_State* L) {
reed@google.com3597b732013-05-22 20:12:50 +0000606 register_Sk(L);
reed@google.com74ce6f02013-05-22 15:13:18 +0000607 REG_CLASS(L, SkCanvas);
608 REG_CLASS(L, SkPath);
609 REG_CLASS(L, SkPaint);
610 REG_CLASS(L, SkRRect);
611}