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
16namespace app {
17namespace script {
18
19using namespace doc;
20
21namespace {
22
23int 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
30int 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
41const luaL_Reg Tilesets_methods[] = {
42 { "__len", Tilesets_len },
43 { "__index", Tilesets_index },
44 { nullptr, nullptr }
45};
46
47} // anonymous namespace
48
49DEF_MTNAME(Tilesets);
50
51void register_tilesets_class(lua_State* L)
52{
53 REG_CLASS(L, Tilesets);
54}
55
56void push_tilesets(lua_State* L, Tilesets* tilesets)
57{
58 push_docobj(L, tilesets);
59}
60
61} // namespace script
62} // namespace app
63