myMPD
Internal API documentation
Loading...
Searching...
No Matches
scripts_lua.c File Reference

Lua script functions. More...

#include "compile_time.h"
#include "src/scripts/scripts_lua.h"
#include "src/lib/config_def.h"
#include "src/lib/log.h"
#include "src/lib/mem.h"
#include "src/lib/msg_queue.h"
#include "src/lib/sds_extras.h"
#include "src/lib/thread.h"
#include "src/lib/utility.h"
#include "src/scripts/interface.h"
#include "src/scripts/interface_caches.h"
#include "src/scripts/interface_http.h"
#include "src/scripts/interface_mympd_api.h"
#include "src/scripts/interface_util.h"
#include "src/scripts/scripts_worker.h"
#include <string.h>
Include dependency graph for scripts_lua.c:

Functions

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)
 

Detailed Description

Lua script functions.

Function Documentation

◆ create_lua_vm()

static bool create_lua_vm ( struct t_script_thread_arg script_arg)
static

Creates the lua instance and opens the standard and myMPD libraries

Parameters
script_arg
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_vmlua state
pchunk to write
szchunk size
uduser 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_vmlua instance
lualiblua library to load
Returns
true on success, else false

◆ populate_lua_global_vars()

static void populate_lua_global_vars ( struct t_scripts_state scripts_state,
struct t_script_thread_arg script_arg,
struct t_list arguments 
)
static

Populate the global vars for script execution

Parameters
scripts_statepointer to scripts_state
script_argpointer to t_script_thread_arg struct
argumentslist of arguments

◆ register_lua_functions()

static void register_lua_functions ( lua_State *  lua_vm)
static

Registers myMPD specific lua functions

Parameters
lua_vmlua instance

◆ save_bytecode()

static int save_bytecode ( lua_State *  lua_vm,
struct t_script_list_data data 
)
static

Saves the lua bytecode

Parameters
lua_vmlua state
datapointer to script_list data
Returns
0 on success

◆ script_load()

static bool script_load ( struct t_script_thread_arg script_arg,
const char *  script 
)
static

Loads the script from a string

Parameters
script_argpointer to t_script_thread_arg struct
scriptscript to load
Returns
0 on success, else 1

◆ script_load_bytecode()

static bool script_load_bytecode ( struct t_script_thread_arg script_arg,
sds  bytecode 
)
static

Loads the cached bytecode This should be faster than compiling the script on each execution.

Parameters
script_argpointer to t_script_thread_arg struct
bytecodecompiled lua script
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_statePointer to script_state
scriptnameScript name to execute
argumentsScript arguments
partitionMPD Partition
localscriptScript is saved locally?
start_eventEvent starting the script
request_idJsonrpc ID
conn_idMongoose request id
errorPointer 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
configPointer to config
scriptnamename of the script
scriptthe script itself
erroralready allocated sds string to hold the error message
Returns
true on success, else false