Freeciv-3.1
|
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include "lua.h"
#include "lualib.h"
#include "astring.h"
#include "log.h"
#include "registry.h"
#include "map.h"
#include "luascript_func.h"
#include "luascript_signal.h"
#include "luascript.h"
Go to the source code of this file.
Macros | |
#define | LUASCRIPT_MAX_EXECUTION_TIME_SEC 5.0 |
#define | LUASCRIPT_CHECKINTERVAL 10000 |
#define | LUASCRIPT_GLOBAL_VAR_NAME "__fcl" |
#define | LUASCRIPT_SECURE_LUA_VERSION1 503 |
#define | LUASCRIPT_SECURE_LUA_VERSION2 504 |
Functions | |
static int | luascript_report (struct fc_lua *fcl, int status, const char *code) |
static void | luascript_traceback_func_save (lua_State *L) |
static void | luascript_traceback_func_push (lua_State *L) |
static void | luascript_exec_check (lua_State *L, lua_Debug *ar) |
static void | luascript_hook_start (lua_State *L) |
static void | luascript_hook_end (lua_State *L) |
static void | luascript_openlibs (lua_State *L, const luaL_Reg *llib) |
static void | luascript_blacklist (lua_State *L, const char *lsymbols[]) |
int | luascript_error (lua_State *L, const char *format,...) |
int | luascript_error_vargs (lua_State *L, const char *format, va_list vargs) |
int | luascript_arg_error (lua_State *L, int narg, const char *msg) |
struct fc_lua * | luascript_new (luascript_log_func_t output_fct, bool secured_environment) |
struct fc_lua * | luascript_get_fcl (lua_State *L) |
void | luascript_destroy (struct fc_lua *fcl) |
void | luascript_log (struct fc_lua *fcl, enum log_level level, const char *format,...) |
void | luascript_log_vargs (struct fc_lua *fcl, enum log_level level, const char *format, va_list args) |
void | luascript_pop_returns (struct fc_lua *fcl, const char *func_name, int nreturns, enum api_types *preturn_types, va_list args) |
void | luascript_push_args (struct fc_lua *fcl, int nargs, enum api_types *parg_types, va_list args) |
bool | luascript_check_function (struct fc_lua *fcl, const char *funcname) |
int | luascript_call (struct fc_lua *fcl, int narg, int nret, const char *code) |
int | luascript_do_string (struct fc_lua *fcl, const char *str, const char *name) |
int | luascript_do_file (struct fc_lua *fcl, const char *filename) |
bool | luascript_callback_invoke (struct fc_lua *fcl, const char *callback_name, int nargs, enum api_types *parg_types, va_list args) |
void | luascript_remove_exported_object (struct fc_lua *fcl, void *object) |
void | luascript_vars_save (struct fc_lua *fcl, struct section_file *file, const char *section) |
void | luascript_vars_load (struct fc_lua *fcl, struct section_file *file, const char *section) |
const Direction * | luascript_dir (enum direction8 dir) |
Variables | |
static const char * | luascript_unsafe_symbols_secure [] |
static const char * | luascript_unsafe_symbols_permissive [] |
#define LUASCRIPT_CHECKINTERVAL 10000 |
Definition at line 45 of file luascript.c.
#define LUASCRIPT_GLOBAL_VAR_NAME "__fcl" |
Definition at line 48 of file luascript.c.
#define LUASCRIPT_MAX_EXECUTION_TIME_SEC 5.0 |
Definition at line 44 of file luascript.c.
#define LUASCRIPT_SECURE_LUA_VERSION1 503 |
Definition at line 65 of file luascript.c.
#define LUASCRIPT_SECURE_LUA_VERSION2 504 |
Definition at line 66 of file luascript.c.
int luascript_arg_error | ( | lua_State * | L, |
int | narg, | ||
const char * | msg | ||
) |
Like script_error, but using a prefix identifying the called lua function: bad argument narg to '[func]': msg
Definition at line 324 of file luascript.c.
|
static |
Remove global symbols from lua state L
Definition at line 278 of file luascript.c.
Referenced by luascript_new().
int luascript_call | ( | struct fc_lua * | fcl, |
int | narg, | ||
int | nret, | ||
const char * | code | ||
) |
Evaluate a Lua function call or loaded script on the stack. Return nonzero if an error occurred.
If available pass the source code string as code, else NULL.
Will pop function and arguments (1 + narg values) from the stack. Will push nret return values to the stack.
On error, print an error message with traceback. Nothing is pushed to the stack.
Definition at line 578 of file luascript.c.
Referenced by luascript_callback_invoke(), luascript_do_file(), luascript_do_string(), luascript_func_call_valist(), and luascript_vars_save().
bool luascript_callback_invoke | ( | struct fc_lua * | fcl, |
const char * | callback_name, | ||
int | nargs, | ||
enum api_types * | parg_types, | ||
va_list | args | ||
) |
Invoke the 'callback_name' Lua function.
Definition at line 657 of file luascript.c.
Referenced by luascript_signal_emit_valist(), and script_client_callback_invoke().
Return if the function 'funcname' is define in the lua state 'fcl->state'.
Definition at line 552 of file luascript.c.
Referenced by luascript_func_check().
void luascript_destroy | ( | struct fc_lua * | fcl | ) |
Free the scripting data.
Definition at line 386 of file luascript.c.
Referenced by script_client_free(), script_client_init(), script_fcdb_free(), script_server_free(), and script_server_init().
const Direction * luascript_dir | ( | enum direction8 | dir | ) |
Definition at line 789 of file luascript.c.
Referenced by api_find_direction(), api_methods_unit_orientation_get(), api_utilities_dir_ccw(), api_utilities_dir_cw(), api_utilities_opposite_dir(), and api_utilities_str2dir().
int luascript_do_file | ( | struct fc_lua * | fcl, |
const char * | filename | ||
) |
Parse and execute the script at filename.
Definition at line 637 of file luascript.c.
Referenced by script_client_do_file(), script_fcdb_init(), and script_server_do_file_shared().
int luascript_do_string | ( | struct fc_lua * | fcl, |
const char * | str, | ||
const char * | name | ||
) |
lua_dostring replacement with error message showing on errors.
Definition at line 617 of file luascript.c.
Referenced by luascript_vars_load(), script_client_code_load(), script_client_do_string(), script_fcdb_do_string(), script_server_code_load(), and script_server_do_string_shared().
int luascript_error | ( | lua_State * | L, |
const char * | format, | ||
... | |||
) |
Internal api error function - varg version.
Definition at line 291 of file luascript.c.
Referenced by api_methods_unit_type_has_flag(), api_methods_unit_type_has_role(), and luascript_signal_callback().
int luascript_error_vargs | ( | lua_State * | L, |
const char * | format, | ||
va_list | vargs | ||
) |
Internal api error function. Invoking this will cause Lua to stop executing the current context and throw an exception, so to speak.
Definition at line 308 of file luascript.c.
Referenced by luascript_error().
|
static |
Check currently executing lua function for execution time limit
Definition at line 227 of file luascript.c.
Referenced by luascript_hook_end(), and luascript_hook_start().
struct fc_lua * luascript_get_fcl | ( | lua_State * | L | ) |
Get the freeciv lua struct from a lua state.
Definition at line 366 of file luascript.c.
Referenced by api_edit_create_player(), api_edit_create_unit_full(), api_signal_by_index(), api_signal_callback_by_index(), api_signal_connect(), api_signal_defined(), api_signal_remove(), and api_utilities_log_base().
|
static |
Clear function execution guard
Definition at line 256 of file luascript.c.
Referenced by luascript_call().
|
static |
Setup function execution guard
Definition at line 243 of file luascript.c.
Referenced by luascript_call().
Print a message to the selected output handle.
Definition at line 409 of file luascript.c.
Referenced by api_edit_create_player(), api_edit_create_unit_full(), api_utilities_log_base(), luascript_callback_invoke(), luascript_func_add_valist(), luascript_func_call_valist(), luascript_func_is_required(), luascript_report(), luascript_signal_create_valist(), luascript_signal_emit_valist(), and luascript_vars_save().
void luascript_log_vargs | ( | struct fc_lua * | fcl, |
enum log_level | level, | ||
const char * | format, | ||
va_list | args | ||
) |
Print a message to the selected output handle.
Definition at line 422 of file luascript.c.
Referenced by luascript_log().
struct fc_lua * luascript_new | ( | luascript_log_func_t | output_fct, |
bool | secured_environment | ||
) |
Initialize the scripting state.
Definition at line 332 of file luascript.c.
Referenced by script_client_init(), script_fcdb_init(), and script_server_init().
|
static |
Open lua libraries in the array of library definitions in llib.
Definition at line 266 of file luascript.c.
Referenced by luascript_new().
void luascript_pop_returns | ( | struct fc_lua * | fcl, |
const char * | func_name, | ||
int | nreturns, | ||
enum api_types * | preturn_types, | ||
va_list | args | ||
) |
Pop return values from the Lua stack.
Definition at line 442 of file luascript.c.
Referenced by luascript_func_call_valist().
void luascript_push_args | ( | struct fc_lua * | fcl, |
int | nargs, | ||
enum api_types * | parg_types, | ||
va_list | args | ||
) |
Push arguments into the Lua stack.
Definition at line 501 of file luascript.c.
Referenced by luascript_callback_invoke(), and luascript_func_call_valist().
void luascript_remove_exported_object | ( | struct fc_lua * | fcl, |
void * | object | ||
) |
Mark any, if exported, full userdata representing 'object' in the current script state as 'Nonexistent'. This changes the type of the lua variable.
Definition at line 700 of file luascript.c.
Referenced by script_client_remove_exported_object(), and script_server_remove_exported_object().
|
static |
Report a lua error.
Definition at line 132 of file luascript.c.
Referenced by luascript_call(), luascript_do_file(), and luascript_do_string().
|
static |
Push the traceback function to the stack
Definition at line 219 of file luascript.c.
Referenced by luascript_call().
|
static |
Find the debug.traceback function and store in the registry
Definition at line 205 of file luascript.c.
Referenced by luascript_new().
void luascript_vars_load | ( | struct fc_lua * | fcl, |
struct section_file * | file, | ||
const char * | section | ||
) |
Load lua variables from file.
Definition at line 763 of file luascript.c.
Referenced by script_client_vars_load(), and script_server_vars_load().
void luascript_vars_save | ( | struct fc_lua * | fcl, |
struct section_file * | file, | ||
const char * | section | ||
) |
Save lua variables to file.
Definition at line 737 of file luascript.c.
Referenced by script_client_vars_save(), and script_server_vars_save().
|
static |
Definition at line 75 of file luascript.c.
Referenced by luascript_new().
|
static |
Definition at line 68 of file luascript.c.
Referenced by luascript_new().