diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-08-02 12:54:15 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-08-02 12:54:15 +0000 |
commit | d5e5340c3926d1cf97f6cba151ffaecb20bfb35f (patch) | |
tree | d1faf7d5b27df8f3c523a8dd33357804118e62b1 /trunk/source/clua.h | |
parent | 7b2204d69f21d7075e4666ee032d7a129081bc4b (diff) | |
download | crawl-ref-d5e5340c3926d1cf97f6cba151ffaecb20bfb35f.tar.gz crawl-ref-d5e5340c3926d1cf97f6cba151ffaecb20bfb35f.zip |
Integrated travel patch as of 20060727
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'trunk/source/clua.h')
-rwxr-xr-x | trunk/source/clua.h | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/trunk/source/clua.h b/trunk/source/clua.h new file mode 100755 index 0000000000..88f0f45cc0 --- /dev/null +++ b/trunk/source/clua.h @@ -0,0 +1,122 @@ +#ifndef __CLUA_H__ +#define __CLUA_H__ + +#include "AppHdr.h" + +#ifdef CLUA_BINDINGS + +extern "C" { +#include <lua.h> +#include <lauxlib.h> +#include <lualib.h> +} + +#include <cstdio> +#include <cstdarg> +#include <string> +#include <set> + +#include "libutil.h" +#include "externs.h" + +class CLua +{ +public: + CLua(); + ~CLua(); + + lua_State *state(); + + operator lua_State * () + { + return state(); + } + + void save(const char *filename); + + void setglobal(const char *name); + void getglobal(const char *name); + + // Assigns the value on top of the stack to a unique name in the registry + // and returns the name. + std::string setuniqregistry(); + + void setregistry(const char *name); + void getregistry(const char *name); + + int execstring(const char *str, const char *context = "init.txt"); + int execfile(const char *filename); + + bool callbooleanfn(bool defval, const char *fn, const char *params, ...); + bool callfn(const char *fn, int nargs, int nret = 1); + bool callfn(const char *fn, const char *params, ...); + void fnreturns(const char *params, ...); + bool runhook(const char *hook, const char *params, ...); + + static int file_write(lua_State *ls); + + std::string error; +private: + lua_State *_state; + typedef std::set<std::string> sfset; + sfset sourced_files; + unsigned long uniqindex; + + void init_lua(); + void set_error(int err, lua_State *ls = NULL); + void load_cmacro(); + void load_chooks(); + + void vfnreturns(const char *par, va_list va); + + bool proc_returns(const char *par) const; + + bool calltopfn(lua_State *ls, const char *format, va_list args, + int retc = -1, va_list *fnr = NULL); + + int push_args(lua_State *ls, const char *format, va_list args, + va_list *cpto = NULL); + int return_count(lua_State *ls, const char *format); + + struct CLuaSave + { + const char *filename; + FILE *handle; + + FILE *get_file(); + }; +}; + +class lua_text_pattern : public base_pattern +{ +public: + lua_text_pattern(const std::string &pattern); + ~lua_text_pattern(); + + bool valid() const; + bool matches(const std::string &s) const; + + static bool is_lua_pattern(const std::string &s); + +private: + bool translated; + bool isvalid; + std::string pattern; + std::string lua_fn_name; + + static unsigned long lfndx; + + bool translate() const; + void pre_pattern(std::string &pat, std::string &fn) const; + void post_pattern(std::string &pat, std::string &fn) const; + + static std::string new_fn_name(); +}; + +extern CLua clua; + +void lua_set_exclusive_item(const item_def *item = NULL); + +#endif // CLUA_BINDINGS + +#endif |