Fawkes API
Fawkes Development Version
|
Lua C++ wrapper. More...
#include <>>
Public Member Functions | |
LuaContext (bool enable_tracebacks=true) | |
Constructor. More... | |
LuaContext (lua_State *L) | |
Wrapper contstructor. More... | |
~LuaContext () | |
Destructor. More... | |
void | setup_fam (bool auto_restart, bool conc_thread) |
Setup file alteration monitor. More... | |
RefPtr< FileAlterationMonitor > | get_fam () const |
Get file alteration monitor. More... | |
void | set_start_script (const char *start_script) |
Set start script. More... | |
void | set_finalization_calls (std::string finalize, std::string finalize_prepare, std::string finalize_cancel) |
Set code to execute during finalization. More... | |
void | restart () |
Restart Lua. More... | |
void | add_package_dir (const char *path, bool prefix=false) |
Add a Lua package directory. More... | |
void | add_cpackage_dir (const char *path, bool prefix=false) |
Add a Lua C package directory. More... | |
void | add_package (const char *package) |
Add a default package. More... | |
lua_State * | get_lua_state () |
Get Lua state. More... | |
void | lock () |
Lock Lua state. More... | |
bool | try_lock () |
Try to lock the Lua state. More... | |
void | unlock () |
Unlock Lua state. More... | |
void | do_file (const char *filename) |
Execute file. More... | |
void | do_string (const char *format,...) |
Execute string. More... | |
void | load_string (const char *s) |
Load Lua string. More... | |
void | pcall (int nargs=0, int nresults=0, int errfunc=0) |
Protected call. More... | |
void | set_usertype (const char *name, void *data, const char *type_name, const char *name_space=0) |
Assign usertype to global variable. More... | |
void | set_string (const char *name, const char *value) |
Assign string to global variable. More... | |
void | set_number (const char *name, lua_Number value) |
Assign number to global variable. More... | |
void | set_boolean (const char *name, bool value) |
Assign boolean to global variable. More... | |
void | set_integer (const char *name, lua_Integer value) |
Assign integer to global variable. More... | |
void | set_cfunction (const char *name, lua_CFunction f) |
Assign cfunction to global variable. More... | |
void | remove_global (const char *name) |
Remove global variable. More... | |
void | set_global (const char *name) |
Set a global value. More... | |
void | push_boolean (bool value) |
Push boolean on top of stack. More... | |
void | push_fstring (const char *format,...) |
Push formatted string on top of stack. More... | |
void | push_integer (lua_Integer value) |
Push integer on top of stack. More... | |
void | push_light_user_data (void *p) |
Push light user data on top of stack. More... | |
void | push_lstring (const char *s, size_t len) |
Push substring on top of stack. More... | |
void | push_nil () |
Push nil on top of stack. More... | |
void | push_number (lua_Number value) |
Push number on top of stack. More... | |
void | push_string (const char *value) |
Push string on top of stack. More... | |
void | push_thread () |
Push thread on top of stack. More... | |
void | push_value (int idx) |
Push a copy of the element at the given index on top of the stack. More... | |
void | push_vfstring (const char *format, va_list arg) |
Push formatted string on top of stack. More... | |
void | push_usertype (void *data, const char *type_name, const char *name_space=0) |
Push usertype on top of stack. More... | |
void | push_cfunction (lua_CFunction f) |
Push C function on top of stack. More... | |
std::string | type_name (int idx) |
Get name of type of value at a given index. More... | |
void | pop (int n) |
Pop value(s) from stack. More... | |
void | remove (int idx) |
Remove value from stack. More... | |
int | stack_size () |
Get size of stack. More... | |
void | create_table (int narr=0, int nrec=0) |
Create a table on top of the stack. More... | |
void | set_table (int t_index=-3) |
Set value of a table. More... | |
void | set_field (const char *key, int t_index=-2) |
Set field of a table. More... | |
void | get_table (int idx) |
Get value from table. More... | |
void | get_field (int idx, const char *k) |
Get named value from table. More... | |
void | get_global (const char *name) |
Get global variable. More... | |
bool | table_next (int idx) |
Iterate to next entry of table. More... | |
void | raw_set (int idx) |
Set value without invoking meta methods. More... | |
void | raw_seti (int idx, int n) |
Set indexed value without invoking meta methods. More... | |
void | raw_get (int idx) |
Get value without invoking meta methods. More... | |
void | raw_geti (int idx, int n) |
Get indexed value without invoking meta methods. More... | |
lua_Number | to_number (int idx) |
Retrieve stack value as number. More... | |
lua_Integer | to_integer (int idx) |
Retrieve stack value as integer. More... | |
bool | to_boolean (int idx) |
Retrieve stack value as boolean. More... | |
const char * | to_string (int idx) |
Retrieve stack value as string. More... | |
void * | to_userdata (int idx) |
Retrieve stack value as userdata. More... | |
void * | to_pointer (int idx) |
Retrieve stack value as pointer. More... | |
void * | to_usertype (int idx) |
Retrieve stack value as a tolua++ user type. More... | |
bool | is_boolean (int idx) |
Check if stack value is a boolean. More... | |
bool | is_cfunction (int idx) |
Check if stack value is a C function. More... | |
bool | is_function (int idx) |
Check if stack value is a function. More... | |
bool | is_light_user_data (int idx) |
Check if stack value is light user data. More... | |
bool | is_nil (int idx) |
Check if stack value is nil. More... | |
bool | is_number (int idx) |
Check if stack value is a number. More... | |
bool | is_string (int idx) |
Check if stack value is a string. More... | |
bool | is_table (int idx) |
Check if stack value is a table. More... | |
bool | is_thread (int idx) |
Check if stack value is a thread. More... | |
size_t | objlen (int idx) |
Get object length. More... | |
void | setfenv (int idx=-2) |
Set function environment. More... | |
void | add_watcher (LuaContextWatcher *watcher) |
Add a context watcher. More... | |
void | remove_watcher (LuaContextWatcher *watcher) |
Remove a context watcher. More... | |
virtual void | fam_event (const char *filename, unsigned int mask) |
Event has been raised. More... | |
void | process_fam_events () |
Process FAM events. More... | |
![]() | |
virtual | ~FamListener () |
Virtual empty destructor. More... | |
Additional Inherited Members | |
![]() | |
static const unsigned int | FAM_ACCESS = 0x00000001 |
File was accessed. More... | |
static const unsigned int | FAM_MODIFY = 0x00000002 |
File was modified. More... | |
static const unsigned int | FAM_ATTRIB = 0x00000004 |
Metadata changed. More... | |
static const unsigned int | FAM_CLOSE_WRITE = 0x00000008 |
Writtable file was closed. More... | |
static const unsigned int | FAM_CLOSE_NOWRITE = 0x00000010 |
Unwrittable file closed. More... | |
static const unsigned int | FAM_CLOSE = (FAM_CLOSE_WRITE | FAM_CLOSE_NOWRITE) |
Close. More... | |
static const unsigned int | FAM_OPEN = 0x00000020 |
File was opened. More... | |
static const unsigned int | FAM_MOVED_FROM = 0x00000040 |
File was moved from X. More... | |
static const unsigned int | FAM_MOVED_TO = 0x00000080 |
File was moved to Y. More... | |
static const unsigned int | FAM_MOVE = (FAM_MOVED_FROM | FAM_MOVED_TO) |
Moves. More... | |
static const unsigned int | FAM_CREATE = 0x00000100 |
Subfile was created. More... | |
static const unsigned int | FAM_DELETE = 0x00000200 |
Subfile was deleted. More... | |
static const unsigned int | FAM_DELETE_SELF = 0x00000400 |
Self was deleted. More... | |
static const unsigned int | FAM_MOVE_SELF = 0x00000800 |
Self was moved. More... | |
static const unsigned int | FAM_UNMOUNT = 0x00002000 |
Backing fs was unmounted. More... | |
static const unsigned int | FAM_Q_OVERFLOW = 0x00004000 |
Event queued overflowed. More... | |
static const unsigned int | FAM_IGNORED = 0x00008000 |
File was ignored. More... | |
static const unsigned int | FAM_ONLYDIR = 0x01000000 |
Only watch the path if it is a directory. More... | |
static const unsigned int | FAM_DONT_FOLLOW = 0x02000000 |
Do not follow a sym link. More... | |
static const unsigned int | FAM_MASK_ADD = 0x20000000 |
Add to the mask of an already existing watch. More... | |
static const unsigned int | FAM_ISDIR = 0x40000000 |
Event occurred against dir. More... | |
static const unsigned int | FAM_ONESHOT = 0x80000000 |
Only send event once. More... | |
static const unsigned int | FAM_ALL_EVENTS |
All events which a program can wait on. More... | |
Lua C++ wrapper.
This thin wrapper allows for easy integration of Fawkes into other applications. It provides convenience methods to some Lua and tolua++ features like setting global variables or pushing/popping values.
It allows raw access to the Lua state since this class does not and should not provide all the features Lua provides. If you use this make sure that you lock the Lua context to avoid multi-threading problems (if that is a possible concern in your application).
LuaContext can use a FileAlterationMonitor on all added package and C package directories. If anything changes in these directories the Lua instance is then automatically restarted (closed, re-opened and re-initialized).
fawkes::LuaContext::LuaContext | ( | bool | enable_tracebacks = true | ) |
Constructor.
enable_tracebacks | if true an error function is installed at the top of the stackand used for pcalls where errfunc is 0. |
Definition at line 66 of file context.cpp.
Referenced by get_fam().
fawkes::LuaContext::LuaContext | ( | lua_State * | L | ) |
Wrapper contstructor.
This wraps around an existing Lua state. It does not initialize the state in the sense that it would add variables etc. It only provides convenient access to the state methods via a C++ interface. It's mainly intended to be used to create a LuaContext to be passed to LuaContextWatcher::lua_restarted(). The state is not closed on destruction as is done when using the other ctor.
L | Lua state to wrap |
Definition at line 87 of file context.cpp.
fawkes::LuaContext::~LuaContext | ( | ) |
Destructor.
Definition at line 98 of file context.cpp.
References fawkes::Thread::cancel(), do_string(), fawkes::Thread::join(), and fawkes::Mutex::lock().
void fawkes::LuaContext::add_cpackage_dir | ( | const char * | path, |
bool | prefix = false |
||
) |
Add a Lua C package directory.
The directory is added to the search path for lua C packages. Files with a .so suffix will be considered as Lua modules.
path | path to add |
prefix | if true, insert path at the beginning of the search path, append to end otherwise |
Definition at line 360 of file context.cpp.
References do_string(), and lock().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::add_package | ( | const char * | package | ) |
Add a default package.
Packages that are added this way are automatically loaded now and on restart().
package | package to add |
Definition at line 383 of file context.cpp.
References do_string(), and lock().
Referenced by fawkes::LuaInterfaceImporter::add_interface(), LuaAgentPeriodicExecutionThread::init(), LuaAgentContinuousExecutionThread::init(), SkillerNavGraphFeature::init_lua_context(), and fawkes::LuaInterfaceImporter::write().
void fawkes::LuaContext::add_package_dir | ( | const char * | path, |
bool | prefix = false |
||
) |
Add a Lua package directory.
The directory is added to the search path for lua packages. Files with a .lua suffix will be considered as Lua modules.
path | path to add |
prefix | if true, insert path at the beginning of the search path, append to end otherwise |
Definition at line 331 of file context.cpp.
References do_string(), and lock().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::add_watcher | ( | fawkes::LuaContextWatcher * | watcher | ) |
Add a context watcher.
watcher | watcher to add |
Definition at line 1396 of file context.cpp.
Referenced by fawkes::LuaInterfaceImporter::LuaInterfaceImporter().
void fawkes::LuaContext::create_table | ( | int | narr = 0 , |
int | nrec = 0 |
||
) |
Create a table on top of the stack.
narr | number of array elements |
nrec | number of non-array elements |
Definition at line 1002 of file context.cpp.
Referenced by SkillerExecutionThread::lua_restarted(), and fawkes::LuaInterfaceImporter::write().
void fawkes::LuaContext::do_file | ( | const char * | filename | ) |
Execute file.
filename | filet to load and excute. |
Definition at line 436 of file context.cpp.
References do_string(), and lock().
Referenced by get_fam(), and set_start_script().
void fawkes::LuaContext::do_string | ( | const char * | format, |
... | |||
) |
Execute string.
format | format of string to execute, arguments can be the same as for vasprintf. |
Definition at line 548 of file context.cpp.
References lock().
Referenced by add_cpackage_dir(), add_package(), add_package_dir(), do_file(), LuaAgentContinuousExecutionThread::fam_event(), LuaAgentPeriodicExecutionThread::finalize(), get_fam(), LuaAgentPeriodicExecutionThread::loop(), SkillerExecutionThread::loop(), SkillerExecutionThread::lua_restarted(), restart(), set_start_script(), fawkes::LuaTriggerManager::trigger(), and ~LuaContext().
|
virtual |
Event has been raised.
filename | name of the file that triggered the event |
mask | mask indicating the event. Currently inotify event flags are used, see inotify.h. |
Implements fawkes::FamListener.
Definition at line 1443 of file context.cpp.
References restart().
RefPtr< FileAlterationMonitor > fawkes::LuaContext::get_fam | ( | ) | const |
Get file alteration monitor.
Definition at line 147 of file context.cpp.
References do_file(), do_string(), and LuaContext().
Referenced by LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::get_field | ( | int | idx, |
const char * | k | ||
) |
Get named value from table.
Retrieves the t[k], where k is the given key and t is a table at the given index idx. The value is pushed onto the stack.
idx | index of the table |
k | key of the table entry |
Definition at line 1069 of file context.cpp.
Referenced by fawkes::LuaInterfaceImporter::add_interface().
void fawkes::LuaContext::get_global | ( | const char * | name | ) |
Get global variable.
name | name of the global variable |
Definition at line 1126 of file context.cpp.
Referenced by fawkes::LuaInterfaceImporter::add_interface(), SkillerNavGraphFeature::finalize_lua_context(), and SkillerNavGraphFeature::init_lua_context().
lua_State * fawkes::LuaContext::get_lua_state | ( | ) |
Get Lua state.
Allows for raw modification of the used Lua state. Remember proper locking!
Definition at line 400 of file context.cpp.
void fawkes::LuaContext::get_table | ( | int | idx | ) |
Get value from table.
Assumes that an index k is at the top of the stack. Then t[k] is retrieved, where t is a table at the given index idx. The resulting value is pushed onto the stack, while the key k is popped from the stack, thus the value replaces the key.
idx | index of the table on the stack |
Definition at line 1056 of file context.cpp.
bool fawkes::LuaContext::is_boolean | ( | int | idx | ) |
Check if stack value is a boolean.
idx | stack index of value |
Definition at line 1247 of file context.cpp.
bool fawkes::LuaContext::is_cfunction | ( | int | idx | ) |
Check if stack value is a C function.
idx | stack index of value |
Definition at line 1258 of file context.cpp.
bool fawkes::LuaContext::is_function | ( | int | idx | ) |
Check if stack value is a function.
idx | stack index of value |
Definition at line 1269 of file context.cpp.
bool fawkes::LuaContext::is_light_user_data | ( | int | idx | ) |
Check if stack value is light user data.
idx | stack index of value |
Definition at line 1280 of file context.cpp.
bool fawkes::LuaContext::is_nil | ( | int | idx | ) |
Check if stack value is nil.
idx | stack index of value |
Definition at line 1291 of file context.cpp.
bool fawkes::LuaContext::is_number | ( | int | idx | ) |
Check if stack value is a number.
idx | stack index of value |
Definition at line 1302 of file context.cpp.
bool fawkes::LuaContext::is_string | ( | int | idx | ) |
Check if stack value is a string.
idx | stack index of value |
Definition at line 1313 of file context.cpp.
bool fawkes::LuaContext::is_table | ( | int | idx | ) |
Check if stack value is a table.
idx | stack index of value |
Definition at line 1324 of file context.cpp.
bool fawkes::LuaContext::is_thread | ( | int | idx | ) |
Check if stack value is a thread.
idx | stack index of value |
Definition at line 1335 of file context.cpp.
void fawkes::LuaContext::load_string | ( | const char * | s | ) |
Load Lua string.
Loads the Lua string and places it as a function on top of the stack.
s | string to load |
Definition at line 601 of file context.cpp.
void fawkes::LuaContext::lock | ( | ) |
Lock Lua state.
Definition at line 408 of file context.cpp.
References fawkes::Mutex::lock().
Referenced by add_cpackage_dir(), add_package(), add_package_dir(), do_file(), do_string(), pop(), push_boolean(), push_cfunction(), push_fstring(), push_integer(), push_light_user_data(), push_lstring(), push_nil(), push_number(), push_string(), push_thread(), push_usertype(), push_value(), push_vfstring(), remove(), remove_global(), restart(), set_boolean(), set_cfunction(), set_integer(), set_number(), set_string(), and set_usertype().
size_t fawkes::LuaContext::objlen | ( | int | idx | ) |
Get object length.
idx | stack index of value |
Definition at line 1346 of file context.cpp.
void fawkes::LuaContext::pcall | ( | int | nargs = 0 , |
int | nresults = 0 , |
||
int | errfunc = 0 |
||
) |
Protected call.
Calls the function on top of the stack. Errors are handled gracefully.
nargs | number of arguments |
nresults | number of results |
errfunc | stack index of an error handling function |
Exception | thrown for generic runtime error or if the error function could not be executed. |
OutOfMemoryException | thrown if not enough memory was available |
Definition at line 629 of file context.cpp.
void fawkes::LuaContext::pop | ( | int | n | ) |
Pop value(s) from stack.
n | number of values to pop |
Definition at line 964 of file context.cpp.
References lock(), and stack_size().
Referenced by fawkes::LuaInterfaceImporter::add_interface(), and SkillerExecutionThread::lua_restarted().
void fawkes::LuaContext::process_fam_events | ( | ) |
Process FAM events.
Definition at line 1436 of file context.cpp.
Referenced by LuaAgentPeriodicExecutionThread::loop(), and SkillerExecutionThread::loop().
void fawkes::LuaContext::push_boolean | ( | bool | value | ) |
Push boolean on top of stack.
value | value to push |
Definition at line 797 of file context.cpp.
References lock().
void fawkes::LuaContext::push_cfunction | ( | lua_CFunction | f | ) |
Push C function on top of stack.
f | C Function to push |
Definition at line 943 of file context.cpp.
References lock().
void fawkes::LuaContext::push_fstring | ( | const char * | format, |
... | |||
) |
Push formatted string on top of stack.
format | string format |
Definition at line 809 of file context.cpp.
References lock().
void fawkes::LuaContext::push_integer | ( | lua_Integer | value | ) |
Push integer on top of stack.
value | value to push |
Definition at line 823 of file context.cpp.
References lock().
void fawkes::LuaContext::push_light_user_data | ( | void * | p | ) |
Push light user data on top of stack.
p | pointer to light user data to push |
Definition at line 834 of file context.cpp.
References lock().
void fawkes::LuaContext::push_lstring | ( | const char * | s, |
size_t | len | ||
) |
Push substring on top of stack.
s | string to push |
len | length of string to push |
Definition at line 846 of file context.cpp.
References lock().
void fawkes::LuaContext::push_nil | ( | ) |
Push nil on top of stack.
Definition at line 856 of file context.cpp.
References lock().
Referenced by SkillerNavGraphFeature::finalize_lua_context(), and SkillerExecutionThread::lua_restarted().
void fawkes::LuaContext::push_number | ( | lua_Number | value | ) |
Push number on top of stack.
value | value to push |
Definition at line 867 of file context.cpp.
References lock().
void fawkes::LuaContext::push_string | ( | const char * | value | ) |
Push string on top of stack.
value | value to push |
Definition at line 878 of file context.cpp.
References lock().
Referenced by SkillerNavGraphFeature::finalize_lua_context(), SkillerNavGraphFeature::init_lua_context(), and SkillerExecutionThread::lua_restarted().
void fawkes::LuaContext::push_thread | ( | ) |
void fawkes::LuaContext::push_usertype | ( | void * | data, |
const char * | type_name, | ||
const char * | name_space = 0 |
||
) |
Push usertype on top of stack.
data | usertype data |
type_name | type name of the data |
name_space | C++ namespace of type, prepended to type_name |
Definition at line 925 of file context.cpp.
References lock(), and type_name().
Referenced by fawkes::LuaInterfaceImporter::add_interface(), SkillerNavGraphFeature::init_lua_context(), SkillerExecutionThread::lua_restarted(), and fawkes::LuaInterfaceImporter::write().
void fawkes::LuaContext::push_value | ( | int | idx | ) |
Push a copy of the element at the given index on top of the stack.
idx | index of the value to copy |
Definition at line 899 of file context.cpp.
References lock().
void fawkes::LuaContext::push_vfstring | ( | const char * | format, |
va_list | arg | ||
) |
Push formatted string on top of stack.
format | string format |
arg | variadic argument list |
Definition at line 912 of file context.cpp.
References lock().
void fawkes::LuaContext::raw_get | ( | int | idx | ) |
Get value without invoking meta methods.
Similar to get_table(), but does raw access, i.e. without invoking meta-methods.
idx | index of the table |
Definition at line 1104 of file context.cpp.
void fawkes::LuaContext::raw_geti | ( | int | idx, |
int | n | ||
) |
Get indexed value without invoking meta methods.
Pushes t[n] onto the stack, where t is a table at index idx.
idx | index of the table |
n | index in the table |
Definition at line 1116 of file context.cpp.
void fawkes::LuaContext::raw_set | ( | int | idx | ) |
Set value without invoking meta methods.
Similar to set_table(), but does raw access, i.e. without invoking meta-methods.
idx | index of the table |
Definition at line 1080 of file context.cpp.
void fawkes::LuaContext::raw_seti | ( | int | idx, |
int | n | ||
) |
Set indexed value without invoking meta methods.
Sets t[n]=v, where t is a table at index idx and v is the value at the top of the stack.
idx | index of the table |
n | index in the table |
Definition at line 1093 of file context.cpp.
Referenced by fawkes::LuaInterfaceImporter::add_interface(), and fawkes::LuaInterfaceImporter::write().
void fawkes::LuaContext::remove | ( | int | idx | ) |
Remove value from stack.
idx | index of element to remove |
Definition at line 977 of file context.cpp.
References lock(), and stack_size().
void fawkes::LuaContext::remove_global | ( | const char * | name | ) |
Remove global variable.
Assigns nil to the given variable and removes it from internal assignment maps.
name | name of value to remove |
Definition at line 1138 of file context.cpp.
References lock().
void fawkes::LuaContext::remove_watcher | ( | fawkes::LuaContextWatcher * | watcher | ) |
Remove a context watcher.
watcher | watcher to remove |
Definition at line 1406 of file context.cpp.
Referenced by SkillerExecutionThread::finalize(), and fawkes::LuaInterfaceImporter::~LuaInterfaceImporter().
void fawkes::LuaContext::restart | ( | ) |
Restart Lua.
Creates a new Lua state, initializes it, anf if this went well the current state is swapped with the new state.
Definition at line 288 of file context.cpp.
References do_string(), lock(), fawkes::LibLogger::log_error(), fawkes::LibLogger::log_warn(), fawkes::MutexLocker::relock(), and fawkes::MutexLocker::unlock().
Referenced by LuaAgentContinuousExecutionThread::fam_event(), and fam_event().
void fawkes::LuaContext::set_boolean | ( | const char * | name, |
bool | value | ||
) |
Assign boolean to global variable.
name | name of global variable to assign the value to |
value | value to assign |
Definition at line 730 of file context.cpp.
References lock().
void fawkes::LuaContext::set_cfunction | ( | const char * | name, |
lua_CFunction | f | ||
) |
Assign cfunction to global variable.
name | name of global variable to assign the value to |
f | function |
Definition at line 781 of file context.cpp.
References lock().
Referenced by LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::set_field | ( | const char * | key, |
int | t_index = -2 |
||
) |
Set field of a table.
Does the equivalent to t[k] = v, where t is the value at the given valid index and v is the value at the top of the stack. This function pops the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event.
key | key of the field to set |
t_index | index of the table on the stack, defaults to the element just below the value to set (-2, second last element on the stack). |
Definition at line 1030 of file context.cpp.
Referenced by fawkes::LuaInterfaceImporter::add_interface(), and fawkes::LuaInterfaceImporter::write().
void fawkes::LuaContext::set_finalization_calls | ( | std::string | finalize, |
std::string | finalize_prepare, | ||
std::string | finalize_cancel | ||
) |
Set code to execute during finalization.
finalize | code string to execute (via do_string()) when eventually finalizing a context |
finalize_prepare | code string to execute (via do_string()) before finalization is performed, for example during a context restart before the new context is initialized |
finalize_cancel | code string to execute (via do_string()) if, during a restart, the initialization of the new context failed and therefore the previously prepared finalization must be cancelled |
Definition at line 1423 of file context.cpp.
void fawkes::LuaContext::set_global | ( | const char * | name | ) |
Set a global value.
Sets the global variable with the given name to the value currently on top of the stack. No check whatsoever regarding the name is done.
name | name of the variable to assign |
Definition at line 1042 of file context.cpp.
Referenced by SkillerExecutionThread::lua_restarted(), and fawkes::LuaInterfaceImporter::write().
void fawkes::LuaContext::set_integer | ( | const char * | name, |
lua_Integer | value | ||
) |
Assign integer to global variable.
name | name of global variable to assign the value to |
value | value to assign |
Definition at line 764 of file context.cpp.
References lock().
void fawkes::LuaContext::set_number | ( | const char * | name, |
lua_Number | value | ||
) |
Assign number to global variable.
name | name of global variable to assign the value to |
value | value to assign |
Definition at line 747 of file context.cpp.
References lock().
void fawkes::LuaContext::set_start_script | ( | const char * | start_script | ) |
Set start script.
The script will be executed once immediately in this method, make sure you call this after all other init-relevant routines like add_* if you need to access these in the start script!
start_script | script to execute now and on restart(). If the string is the path and name of an accessible file it is loaded via do_file(), otherwise it is considered to be the name of a module and loaded via Lua's require(). Note however, that if you use a module, special care has to be taken to correctly modify the global environment! |
Definition at line 266 of file context.cpp.
References do_file(), and do_string().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::set_string | ( | const char * | name, |
const char * | value | ||
) |
Assign string to global variable.
name | name of global variable to assign the value to |
value | value to assign |
Definition at line 713 of file context.cpp.
References lock().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::set_table | ( | int | t_index = -3 | ) |
Set value of a table.
Sets value t[k] = v. t is the table at the given index, by default it is the third-last entry (index is -3). v is the value at the top of the stack, k is the element just below the top.
t_index | index of the table on the stack |
Definition at line 1015 of file context.cpp.
Referenced by SkillerNavGraphFeature::finalize_lua_context(), SkillerNavGraphFeature::init_lua_context(), and SkillerExecutionThread::lua_restarted().
void fawkes::LuaContext::set_usertype | ( | const char * | name, |
void * | data, | ||
const char * | type_name, | ||
const char * | name_space = 0 |
||
) |
Assign usertype to global variable.
name | name of global variable to assign the value to |
data | usertype data |
type_name | type name of the data |
name_space | C++ namespace of type, prepended to type_name |
Definition at line 689 of file context.cpp.
References lock(), and type_name().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
void fawkes::LuaContext::setfenv | ( | int | idx = -2 | ) |
Set function environment.
Sets the table on top of the stack as environment of the function at the given stack index.
idx | stack index of function |
Definition at line 1358 of file context.cpp.
void fawkes::LuaContext::setup_fam | ( | bool | auto_restart, |
bool | conc_thread | ||
) |
Setup file alteration monitor.
Setup an internal file alteration monitor that can react to changes on Lua files and packages.
auto_restart | automatically restart the Lua context in case of an event |
conc_thread | true to run a concurrent thread for event processing. If and only if you set this to false, ensure that process_fam_events() periodically. |
Definition at line 128 of file context.cpp.
References fawkes::Thread::start().
Referenced by LuaAgentPeriodicExecutionThread::init(), and LuaAgentContinuousExecutionThread::init().
int fawkes::LuaContext::stack_size | ( | ) |
Get size of stack.
Definition at line 991 of file context.cpp.
bool fawkes::LuaContext::table_next | ( | int | idx | ) |
Iterate to next entry of table.
idx | stack index of table |
Definition at line 1160 of file context.cpp.
Referenced by SkillerExecutionThread::lua_restarted().
bool fawkes::LuaContext::to_boolean | ( | int | idx | ) |
Retrieve stack value as boolean.
idx | stack index of value |
Definition at line 1193 of file context.cpp.
lua_Integer fawkes::LuaContext::to_integer | ( | int | idx | ) |
Retrieve stack value as integer.
idx | stack index of value |
Definition at line 1182 of file context.cpp.
lua_Number fawkes::LuaContext::to_number | ( | int | idx | ) |
Retrieve stack value as number.
idx | stack index of value |
Definition at line 1171 of file context.cpp.
void * fawkes::LuaContext::to_pointer | ( | int | idx | ) |
Retrieve stack value as pointer.
idx | stack index of value |
Definition at line 1225 of file context.cpp.
const char * fawkes::LuaContext::to_string | ( | int | idx | ) |
Retrieve stack value as string.
idx | stack index of value |
Definition at line 1204 of file context.cpp.
Referenced by SkillerExecutionThread::lua_restarted().
void * fawkes::LuaContext::to_userdata | ( | int | idx | ) |
Retrieve stack value as userdata.
idx | stack index of value |
Definition at line 1214 of file context.cpp.
void * fawkes::LuaContext::to_usertype | ( | int | idx | ) |
Retrieve stack value as a tolua++ user type.
idx | stack index of value |
Definition at line 1236 of file context.cpp.
Referenced by SkillerExecutionThread::lua_restarted().
bool fawkes::LuaContext::try_lock | ( | ) |
Try to lock the Lua state.
Definition at line 418 of file context.cpp.
References fawkes::Mutex::try_lock().
std::string fawkes::LuaContext::type_name | ( | int | idx | ) |
Get name of type of value at a given index.
idx | index of value to get type for |
Definition at line 955 of file context.cpp.
Referenced by push_usertype(), and set_usertype().
void fawkes::LuaContext::unlock | ( | ) |