Lua script functions.
More...
|
| static bool | create_lua_vm (struct t_script_thread_arg *script_arg) |
| |
| static bool | script_load (struct t_script_thread_arg *script_arg, const char *script) |
| |
| static bool | script_load_bytecode (struct t_script_thread_arg *script_arg, sds bytecode) |
| |
| static int | save_bytecode (lua_State *lua_vm, struct t_script_list_data *data) |
| |
| static void | populate_lua_global_vars (struct t_scripts_state *scripts_state, struct t_script_thread_arg *script_arg, struct t_list *arguments) |
| |
| static void | register_lua_functions (lua_State *lua_vm) |
| |
| static int | mympd_luaopen (lua_State *lua_vm, const char *lualib) |
| |
| bool | script_start (struct t_scripts_state *scripts_state, sds scriptname, struct t_list *arguments, const char *partition, bool localscript, enum script_start_events start_event, unsigned request_id, unsigned long conn_id, sds *error) |
| |
| bool | script_validate (struct t_config *config, sds scriptname, sds script, sds *error) |
| |
| static int | dump_cb (lua_State *lua_vm, const void *p, size_t sz, void *ud) |
| |
◆ create_lua_vm()
Creates the lua instance and opens the standard and myMPD libraries
- Parameters
-
- Returns
- true on success, else false
◆ dump_cb()
| static int dump_cb |
( |
lua_State * |
lua_vm, |
|
|
const void * |
p, |
|
|
size_t |
sz, |
|
|
void * |
ud |
|
) |
| |
|
static |
Callback function for lua_dump to save the lua script bytecode
- Parameters
-
| lua_vm | lua state |
| p | chunk to write |
| sz | chunk size |
| ud | user data |
- Returns
- 0 on success
◆ mympd_luaopen()
| static int mympd_luaopen |
( |
lua_State * |
lua_vm, |
|
|
const char * |
lualib |
|
) |
| |
|
static |
Loads a lua library from filesystem or embedded in release
- Parameters
-
| lua_vm | lua instance |
| lualib | lua library to load |
- Returns
- true on success, else false
◆ populate_lua_global_vars()
Populate the global vars for script execution
- Parameters
-
| scripts_state | pointer to scripts_state |
| script_arg | pointer to t_script_thread_arg struct |
| arguments | list of arguments |
◆ register_lua_functions()
| static void register_lua_functions |
( |
lua_State * |
lua_vm | ) |
|
|
static |
Registers myMPD specific lua functions
- Parameters
-
◆ save_bytecode()
Saves the lua bytecode
- Parameters
-
| lua_vm | lua state |
| data | pointer to script_list data |
- Returns
- 0 on success
◆ script_load()
Loads the script from a string
- Parameters
-
- Returns
- 0 on success, else 1
◆ script_load_bytecode()
Loads the cached bytecode This should be faster than compiling the script on each execution.
- Parameters
-
- Returns
- 0 on success, else 1
◆ script_start()
| bool script_start |
( |
struct t_scripts_state * |
scripts_state, |
|
|
sds |
scriptname, |
|
|
struct t_list * |
arguments, |
|
|
const char * |
partition, |
|
|
bool |
localscript, |
|
|
enum script_start_events |
start_event, |
|
|
unsigned |
request_id, |
|
|
unsigned long |
conn_id, |
|
|
sds * |
error |
|
) |
| |
Executes the script in a new thread.
- Parameters
-
| scripts_state | Pointer to script_state |
| scriptname | Script name to execute |
| arguments | Script arguments |
| partition | MPD Partition |
| localscript | Script is saved locally? |
| start_event | Event starting the script |
| request_id | Jsonrpc ID |
| conn_id | Mongoose request id |
| error | Pointer to already allocated sds string for the error message |
- Returns
- true on success, else false
◆ script_validate()
| bool script_validate |
( |
struct t_config * |
config, |
|
|
sds |
scriptname, |
|
|
sds |
script, |
|
|
sds * |
error |
|
) |
| |
Validates (compiles) a lua script
- Parameters
-
| config | Pointer to config |
| scriptname | name of the script |
| script | the script itself |
| error | already allocated sds string to hold the error message |
- Returns
- true on success, else false