32 #include "tolua_game_gen.h"
33 #include "tolua_signal_gen.h"
39 #include "tolua_server_gen.h"
67 const char *format, ...)
84 save_caller =
fcl->caller;
85 save_output_fct =
fcl->output_fct;
92 fcl->caller = save_caller;
93 fcl->output_fct = save_output_fct;
127 if (ffile !=
nullptr) {
130 buffer =
new char[
stats.st_size + 1];
131 len = fread(buffer, 1,
stats.st_size, ffile);
152 const char *filename)
160 save_caller =
fcl->caller;
161 save_output_fct =
fcl->output_fct;
163 fcl->caller = caller;
168 fcl->caller = save_caller;
169 fcl->output_fct = save_output_fct;
187 const char *filename)
256 const char *
section =
"script.code";
383 va_start(args, signal_name);
405 API_TYPE_TILE, API_TYPE_TILE);
411 API_TYPE_INT, API_TYPE_STRING);
423 API_TYPE_BUILDING_TYPE, API_TYPE_CITY);
431 API_TYPE_UNIT_TYPE, API_TYPE_CITY,
434 API_TYPE_BUILDING_TYPE, API_TYPE_CITY,
443 API_TYPE_BUILDING_TYPE, API_TYPE_STRING,
449 API_TYPE_PLAYER, API_TYPE_STRING);
453 API_TYPE_PLAYER, API_TYPE_PLAYER);
457 API_TYPE_PLAYER, API_TYPE_PLAYER, API_TYPE_STRING);
462 API_TYPE_PLAYER, API_TYPE_PLAYER);
471 API_TYPE_PLAYER, API_TYPE_STRING);
474 API_TYPE_DISASTER, API_TYPE_CITY, API_TYPE_BOOL);
486 API_TYPE_ACHIEVEMENT, API_TYPE_PLAYER,
494 API_TYPE_ACTION, API_TYPE_UNIT, API_TYPE_UNIT);
497 API_TYPE_ACTION, API_TYPE_UNIT, API_TYPE_TILE);
500 API_TYPE_ACTION, API_TYPE_UNIT, API_TYPE_CITY);
503 API_TYPE_ACTION, API_TYPE_UNIT, API_TYPE_TILE);
506 API_TYPE_ACTION, API_TYPE_UNIT);
530 va_start(args, func_name);
541 const char *format, ...)
547 va_start(args, format);
int api_specenum_open(lua_State *L)
Define the __index function for each exported specenum type.
constexpr auto LOG_VERBOSE
constexpr auto LOG_NORMAL
#define fc_assert_ret_val(condition, val)
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 'Nonexisten...
int luascript_do_string(struct fc_lua *fcl, const char *str, const char *name)
lua_dostring replacement with error message showing on errors.
int luascript_do_file(struct fc_lua *fcl, const char *filename)
Parse and execute the script at filename.
void luascript_vars_load(struct fc_lua *fcl, struct section_file *file, const char *section)
Load lua variables from file.
void luascript_common_z(lua_State *L)
Runs tolua_common_z.lua.
struct fc_lua * luascript_new(luascript_log_func_t output_fct, bool secured_environment)
Initialize the scripting state.
void luascript_vars_save(struct fc_lua *fcl, struct section_file *file, const char *section)
Save lua variables to file.
void luascript_common_a(lua_State *L)
Runs tolua_common_a.lua.
void luascript_destroy(struct fc_lua *fcl)
Free the scripting data.
void(* luascript_log_func_t)(struct fc_lua *fcl, QtMsgType level, const char *format,...) fc__attribute((__format__(__printf__
bool luascript_func_call_valist(struct fc_lua *fcl, const char *func_name, va_list args)
Call a lua function; return value is TRUE if no errors occurred, otherwise FALSE.
void luascript_func_init(struct fc_lua *fcl)
Initialize the structures needed to save functions definitions.
void luascript_func_add(struct fc_lua *fcl, const char *func_name, bool required, int nargs, int nreturns,...)
Add a lua function.
void luascript_signal_init(struct fc_lua *fcl)
Initialize script signals and callbacks.
signal_deprecator * luascript_signal_create(struct fc_lua *fcl, const char *signal_name, int nargs,...)
Create a new signal type.
void deprecate_signal(signal_deprecator *deprecator, const char *signal_name, const char *replacement, const char *deprecated_since)
Mark signal deprecated.
void luascript_signal_emit_valist(struct fc_lua *fcl, const char *signal_name, va_list args)
Invoke all the callback functions attached to a given signal.
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
Lookup a string value in the secfile.
#define secfile_insert_str_noescape(secfile, string, path,...)
static void static sol::state * fcl
Lua virtual machine state.
static bool script_server_do_file_shared(struct fc_lua *fcl, struct connection *caller, const char *filename)
Parse and execute the script at filename in the context of the specified instance.
static void script_server_vars_init()
Initialize the game script variables.
bool script_server_unsafe_do_string(struct connection *caller, const char *str)
Parse and execute the script in str in an unsafe instance.
static void script_server_code_free()
Free the optional game script code (useful for scenarios).
static char * script_server_code
Optional game script code (useful for scenarios).
static void script_server_vars_free()
Free the game script variables.
static void static bool script_server_do_string_shared(struct fc_lua *fcl, struct connection *caller, const char *str)
Parse and execute the script in str in the context of the specified instance.
void script_server_signal_emit(const char *signal_name,...)
Invoke all the callback functions attached to a given signal.
bool script_server_init()
Initialize the scripting state.
bool script_server_do_string(struct connection *caller, const char *str)
Parse and execute the script in str in the same instance as the ruleset.
static void script_server_vars_load(struct section_file *file)
Load the game script variables in file.
static void script_server_code_init()
Initialize the optional game script code (useful for scenarios).
static struct fc_lua * fcl_main
Lua virtual machine states.
bool script_server_call(const char *func_name,...)
Call a lua function.
static void script_server_code_save(struct section_file *file)
Save the optional game script code to file (useful for scenarios).
void script_server_state_save(struct section_file *file)
Save the scripting state to file.
static void script_server_vars_save(struct section_file *file)
Save the game script variables to file.
void script_server_free()
Free the scripting data.
void script_server_state_load(struct section_file *file)
Load the scripting state from file.
void script_server_remove_exported_object(void *object)
Mark any, if exported, full userdata representing 'object' in the current script state as 'Nonexisten...
static struct fc_lua * fcl_unsafe
static void script_server_functions_define()
Add server callback functions; these must be defined in the lua script '[rulesetdir]/script....
static void script_server_signals_create()
Declare any new signal types you need here.
static void script_server_cmd_reply(struct fc_lua *fcl, QtMsgType level, const char *format,...) fc__attribute((__format__(__printf__
Send the message via cmd_reply().
static void script_server_code_load(struct section_file *file)
Load the optional game script code from file (useful for scenarios).
bool script_server_unsafe_do_file(struct connection *caller, const char *filename)
Parse and execute the script at filename in an unsafe instance.
bool script_server_load_file(const char *filename, char **buf)
Load script to a buffer.
bool script_server_do_file(struct connection *caller, const char *filename)
Parse and execute the script at filename in the same instance as the ruleset.
struct setting_list * level[OLEVELS_NUM]
void cmd_reply(enum command_id cmd, struct connection *caller, enum rfc_status rfc_status, const char *format,...)
var-args version as above, no prefix
struct connection * caller
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
int fc_stat(const char *filename, struct stat *buf)
Wrapper function for stat() with filename conversion to local encoding on Windows.
FILE * fc_fopen(const char *filename, const char *opentype)
Wrapper function for fopen() with filename conversion to local encoding on Windows.
int fc__attribute((nonnull(1, 3)))