1 | // Aseprite |
2 | // Copyright (C) 2019 Igara Studio S.A. |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "app/script/docobj.h" |
12 | #include "app/script/engine.h" |
13 | #include "app/script/luacpp.h" |
14 | #include "doc/tilesets.h" |
15 | |
16 | namespace app { |
17 | namespace script { |
18 | |
19 | using namespace doc; |
20 | |
21 | namespace { |
22 | |
23 | int Tilesets_len(lua_State* L) |
24 | { |
25 | auto obj = get_docobj<Tilesets>(L, 1); |
26 | lua_pushinteger(L, obj->size()); |
27 | return 1; |
28 | } |
29 | |
30 | int Tilesets_index(lua_State* L) |
31 | { |
32 | auto obj = get_docobj<Tilesets>(L, 1); |
33 | const int i = lua_tonumber(L, 2); |
34 | if (i >= 1 && i <= int(obj->size())) |
35 | push_docobj(L, *(obj->begin()+i-1)); |
36 | else |
37 | lua_pushnil(L); |
38 | return 1; |
39 | } |
40 | |
41 | const luaL_Reg Tilesets_methods[] = { |
42 | { "__len" , Tilesets_len }, |
43 | { "__index" , Tilesets_index }, |
44 | { nullptr, nullptr } |
45 | }; |
46 | |
47 | } // anonymous namespace |
48 | |
49 | DEF_MTNAME(Tilesets); |
50 | |
51 | void register_tilesets_class(lua_State* L) |
52 | { |
53 | REG_CLASS(L, Tilesets); |
54 | } |
55 | |
56 | void push_tilesets(lua_State* L, Tilesets* tilesets) |
57 | { |
58 | push_docobj(L, tilesets); |
59 | } |
60 | |
61 | } // namespace script |
62 | } // namespace app |
63 | |