23 #ifndef __LUA_CONTEXT_H_ 24 #define __LUA_CONTEXT_H_ 26 #include <lua/exceptions.h> 27 #include <core/utils/lock_list.h> 28 #include <core/utils/refptr.h> 29 #include <utils/system/fam.h> 30 #include <utils/system/fam_thread.h> 44 class LuaContextWatcher;
54 void setup_fam(
bool auto_restart,
bool conc_thread);
59 std::string finalize_prepare,
60 std::string finalize_cancel);
74 void do_file(
const char *filename);
78 void pcall(
int nargs = 0,
int nresults = 0,
int errfunc = 0);
81 const char *name_space = 0);
82 void set_string(
const char *name,
const char *value);
83 void set_number(
const char *name, lua_Number value);
85 void set_integer(
const char *name, lua_Integer value);
102 const char *name_space = 0);
108 void remove(
int idx);
113 void set_field(
const char *key,
int t_index = -2);
151 virtual void fam_event(
const char *filename,
unsigned int mask);
156 lua_State * init_state();
157 void do_string(lua_State *L,
const char *format, ...);
158 void do_file(lua_State *L,
const char *s);
159 void assert_unique_name(
const char *name, std::string type);
165 bool __enable_tracebacks;
168 char *__start_script;
170 std::list<std::string> __package_dirs;
171 std::list<std::string> __cpackage_dirs;
172 std::list<std::string> __packages;
173 std::list<std::string>::iterator __slit;
175 std::map<std::string, std::pair<void *, std::string> > __usertypes;
176 std::map<std::string, std::pair<void *, std::string> >::iterator __utit;
177 std::map<std::string, std::string> __strings;
178 std::map<std::string, std::string>::iterator __strings_it;
179 std::map<std::string, bool> __booleans;
180 std::map<std::string, bool>::iterator __booleans_it;
181 std::map<std::string, lua_Number> __numbers;
182 std::map<std::string, lua_Number>::iterator __numbers_it;
183 std::map<std::string, lua_Integer> __integers;
184 std::map<std::string, lua_Integer>::iterator __integers_it;
185 std::map<std::string, lua_CFunction> __cfuncs;
186 std::map<std::string, lua_CFunction>::iterator __cfuncs_it;
188 std::string __finalize_call;
189 std::string __finalize_prepare_call;
190 std::string __finalize_cancel_call;
void restart()
Restart Lua.
void push_thread()
Push thread on top of stack.
void push_light_user_data(void *p)
Push light user data on top of stack.
void setup_fam(bool auto_restart, bool conc_thread)
Setup file alteration monitor.
void push_vfstring(const char *format, va_list arg)
Push formatted string on top of stack.
bool is_light_user_data(int idx)
Check if stack value is light user data.
bool is_number(int idx)
Check if stack value is a number.
void push_integer(lua_Integer value)
Push integer on top of stack.
void raw_geti(int idx, int n)
Get indexed value without invoking meta methods.
Fawkes library namespace.
bool is_thread(int idx)
Check if stack value is a thread.
void pop(int n)
Pop value(s) from stack.
void push_lstring(const char *s, size_t len)
Push substring on top of stack.
void set_cfunction(const char *name, lua_CFunction f)
Assign cfunction to global variable.
void raw_seti(int idx, int n)
Set indexed value without invoking meta methods.
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
void load_string(const char *s)
Load Lua string.
void add_package_dir(const char *path, bool prefix=false)
Add a Lua package directory.
void remove_watcher(LuaContextWatcher *watcher)
Remove a context watcher.
bool is_cfunction(int idx)
Check if stack value is a C function.
bool try_lock()
Try to lock the Lua state.
void set_field(const char *key, int t_index=-2)
Set field of a table.
void set_table(int t_index=-3)
Set value of a table.
void add_package(const char *package)
Add a default package.
void unlock()
Unlock Lua state.
void push_value(int idx)
Push a copy of the element at the given index on top of the stack.
void push_nil()
Push nil on top of stack.
int stack_size()
Get size of stack.
void pcall(int nargs=0, int nresults=0, int errfunc=0)
Protected call.
bool is_nil(int idx)
Check if stack value is nil.
lua_Number to_number(int idx)
Retrieve stack value as number.
void push_cfunction(lua_CFunction f)
Push C function on top of stack.
void do_string(const char *format,...)
Execute string.
void do_file(const char *filename)
Execute file.
void set_number(const char *name, lua_Number value)
Assign number to global variable.
LuaContext(bool enable_tracebacks=true)
Constructor.
void setfenv(int idx=-2)
Set function environment.
void get_field(int idx, const char *k)
Get named value from table.
File Alteration Monitor Listener.
void set_integer(const char *name, lua_Integer value)
Assign integer to global variable.
lua_Integer to_integer(int idx)
Retrieve stack value as integer.
void set_usertype(const char *name, void *data, const char *type_name, const char *name_space=0)
Assign usertype to global variable.
void push_usertype(void *data, const char *type_name, const char *name_space=0)
Push usertype on top of stack.
void set_string(const char *name, const char *value)
Assign string to global variable.
void push_string(const char *value)
Push string on top of stack.
bool is_table(int idx)
Check if stack value is a table.
void set_finalization_calls(std::string finalize, std::string finalize_prepare, std::string finalize_cancel)
Set code to execute during finalization.
void process_fam_events()
Process FAM events.
void set_boolean(const char *name, bool value)
Assign boolean to global variable.
RefPtr<> is a reference-counting shared smartpointer.
bool is_string(int idx)
Check if stack value is a string.
void get_global(const char *name)
Get global variable.
void push_boolean(bool value)
Push boolean on top of stack.
void add_cpackage_dir(const char *path, bool prefix=false)
Add a Lua C package directory.
void set_start_script(const char *start_script)
Set start script.
bool is_function(int idx)
Check if stack value is a function.
bool to_boolean(int idx)
Retrieve stack value as boolean.
bool table_next(int idx)
Iterate to next entry of table.
lua_State * get_lua_state()
Get Lua state.
void get_table(int idx)
Get value from table.
FileAlterationMonitor thread wrapper.
void lock()
Lock Lua state.
void remove_global(const char *name)
Remove global variable.
Mutex mutual exclusion lock.
void set_global(const char *name)
Set a global value.
void * to_pointer(int idx)
Retrieve stack value as pointer.
void create_table(int narr=0, int nrec=0)
Create a table on top of the stack.
void push_number(lua_Number value)
Push number on top of stack.
void * to_userdata(int idx)
Retrieve stack value as userdata.
void * to_usertype(int idx)
Retrieve stack value as a tolua++ user type.
const char * to_string(int idx)
Retrieve stack value as string.
void raw_get(int idx)
Get value without invoking meta methods.
size_t objlen(int idx)
Get object length.
std::string type_name(int idx)
Get name of type of value at a given index.
RefPtr< FileAlterationMonitor > get_fam() const
Get file alteration monitor.
void add_watcher(LuaContextWatcher *watcher)
Add a context watcher.
bool is_boolean(int idx)
Check if stack value is a boolean.
void push_fstring(const char *format,...)
Push formatted string on top of stack.
void raw_set(int idx)
Set value without invoking meta methods.