summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_libs.h
blob: aca91d8699f9995fb2a30b029f5b54bcb032e216 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * File:     l_libs.h
 * Summary:  Library definitions for dlua.
 */

#ifndef L_LIBS_H
#define L_LIBS_H

#include "clua.h"

/*
 * Libraries and loaders, accessed from init_dungeon_lua().
 */

extern const struct luaL_reg crawl_lib[];
extern const struct luaL_reg debug_lib[];
extern const struct luaL_reg dgn_lib[];
extern const struct luaL_reg dgn_build_lib[];
extern const struct luaL_reg dgn_event_lib[];
extern const struct luaL_reg dgn_grid_lib[];
extern const struct luaL_reg dgn_item_lib[];
extern const struct luaL_reg dgn_level_lib[];
extern const struct luaL_reg dgn_mons_lib[];
extern const struct luaL_reg dgn_tile_lib[];
extern const struct luaL_reg file_lib[];
extern const struct luaL_reg los_lib[];
extern const struct luaL_reg mapmarker_lib[];
extern const struct luaL_reg you_lib[];

void luaopen_dgnevent(lua_State *ls);
void luaopen_mapmarker(lua_State *ls);
void luaopen_ray(lua_State *ls);

void register_monslist(lua_State *ls);
void register_itemlist(lua_State *ls);
void register_builder_funcs(lua_State *ls);
    
/*
 * Macros for processing object arguments.
 */
#define GETCOORD(c, p1, p2, boundfn)                      \
    coord_def c;                                          \
    c.x = luaL_checkint(ls, p1);                          \
    c.y = luaL_checkint(ls, p2);                          \
    if (!boundfn(c))                                        \
        luaL_error(                                             \
            ls,                                                 \
            make_stringf("Point (%d,%d) is out of bounds",      \
                         c.x, c.y).c_str());                    \
    else ;


#define COORDS(c, p1, p2)                                \
    GETCOORD(c, p1, p2, in_bounds)

#define FEAT(f, pos) \
dungeon_feature_type f = check_lua_feature(ls, pos)
  
#define LEVEL(lev, br, pos)                                             \
const char *level_name = luaL_checkstring(ls, pos);                 \
level_area_type lev = str_to_level_area_type(level_name);           \
if (lev == NUM_LEVEL_AREA_TYPES)                                    \
luaL_error(ls, "Expected level name");                          \
const char *branch_name = luaL_checkstring(ls, pos);                \
branch_type br = str_to_branch(branch_name);                        \
if (lev == LEVEL_DUNGEON && br == NUM_BRANCHES)                     \
luaL_error(ls, "Expected branch name");

#define MAP(ls, n, var)                             \
map_def *var = *(map_def **) luaL_checkudata(ls, n, MAP_METATABLE)
#define DEVENT(ls, n, var) \
dgn_event *var = *(dgn_event **) luaL_checkudata(ls, n, DEVENT_METATABLE)
#define MAPMARKER(ls, n, var) \
map_marker *var = *(map_marker **) luaL_checkudata(ls, n, MAPMARK_METATABLE)


/*
 * Some shared helper functions.
 */
class map_lines;
int dgn_map_add_transform(lua_State *ls,
          std::string (map_lines::*add)(const std::string &s));
unsigned int get_tile_idx(lua_State *ls, int arg);
level_id dlua_level_id(lua_State *ls, int ndx);
dungeon_feature_type check_lua_feature(lua_State *ls, int idx);

#endif