23
23
struct section_file;
25
/* internal api error function. */
25
/* internal api error functions */
26
26
int script_error(const char *fmt, ...)
27
27
fc__attribute((__format__ (__printf__, 1, 2)));
29
/* Returns additional arguments on failure. */
30
#define SCRIPT_ASSERT_CAT(str1, str2) str1 ## str2
31
#define SCRIPT_ASSERT(check, ...) \
33
script_error("in %s() [%s::%d]: the assertion '%s' failed.", \
34
__FUNCTION__, __FILE__, __LINE__, #check); \
35
return SCRIPT_ASSERT_CAT(, __VA_ARGS__); \
29
int script_arg_error(int narg, const char *msg);
38
31
/* callback invocation function. */
39
32
bool script_callback_invoke(const char *callback_name,
44
37
/* script functions. */
45
38
bool script_init(void);
46
39
void script_free(void);
40
bool script_do_string(const char *str);
47
41
bool script_do_file(const char *filename);
49
43
/* script state i/o. */
50
44
void script_state_load(struct section_file *file);
51
45
void script_state_save(struct section_file *file);
48
/* Returns additional arguments on failure. */
49
#define SCRIPT_ASSERT_CAT(str1, str2) str1 ## str2
51
/* Script assertion (for debugging only) */
53
#define SCRIPT_ASSERT(check, ...) \
55
script_error("in %s() [%s::%d]: the assertion '%s' failed.", \
56
__FUNCTION__, __FILE__, __LINE__, #check); \
57
return SCRIPT_ASSERT_CAT(, __VA_ARGS__); \
60
#define SCRIPT_ASSERT(check, ...)
63
/* script_error on failed check */
64
#define SCRIPT_CHECK(check, msg, ...) \
67
return SCRIPT_ASSERT_CAT(, __VA_ARGS__); \
70
/* script_arg_error on failed check */
71
#define SCRIPT_CHECK_ARG(check, narg, msg, ...) \
73
script_arg_error(narg, msg); \
74
return SCRIPT_ASSERT_CAT(, __VA_ARGS__); \
77
/* script_arg_error on nil value */
78
#define SCRIPT_CHECK_ARG_NIL(value, narg, type, ...) \
79
if ((value) == NULL) { \
80
script_arg_error(narg, "got 'nil', '" #type "' expected"); \
81
return SCRIPT_ASSERT_CAT(, __VA_ARGS__); \
84
/* script_arg_error on nil value */
85
#define SCRIPT_CHECK_SELF(value, ...) \
86
if ((value) == NULL) { \
87
script_arg_error(1, "got 'nil' for self"); \
88
return SCRIPT_ASSERT_CAT(, __VA_ARGS__); \
91
#endif /* FC__SCRIPT_H */