#include <s_base.h>
Public Member Functions | |
ScriptApiBase (ScriptingType type) | |
ScriptApiBase () | |
virtual | ~ScriptApiBase () |
DISABLE_CLASS_COPY (ScriptApiBase) | |
void | loadMod (const std::string &script_path, const std::string &mod_name) |
void | loadScript (const std::string &script_path) |
void | runCallbacksRaw (int nargs, RunCallbacksMode mode, const char *fxn) |
void | addObjectReference (ServerActiveObject *cobj) |
void | removeObjectReference (ServerActiveObject *cobj) |
ScriptingType | getType () |
IGameDef * | getGameDef () |
Server * | getServer () |
const std::string & | getOrigin () |
void | setOriginDirect (const char *origin) |
void | setOriginFromTableRaw (int index, const char *fxn) |
void | clientOpenLibs (lua_State *L) |
void | checkSetByBuiltin () |
Static Public Member Functions | |
static std::string | getCurrentModNameInsecure (lua_State *L) |
Returns the currently running mod, only during init time. | |
Protected Member Functions | |
lua_State * | getStack () |
void | realityCheck () |
void | scriptError (int result, const char *fxn) |
void | stackDump (std::ostream &o) |
void | setGameDef (IGameDef *gamedef) |
Environment * | getEnv () |
void | setEnv (Environment *env) |
EmergeThread * | getEmergeThread () |
void | setEmergeThread (EmergeThread *emerge) |
void | objectrefGetOrCreate (lua_State *L, ServerActiveObject *cobj) |
void | pushPlayerHPChangeReason (lua_State *L, const PlayerHPChangeReason &reason) |
Protected Member Functions inherited from LuaHelper | |
template<> | |
bool | readParam (lua_State *L, int index) |
template<> | |
s16 | readParam (lua_State *L, int index) |
template<> | |
int | readParam (lua_State *L, int index) |
template<> | |
float | readParam (lua_State *L, int index) |
template<> | |
v2s16 | readParam (lua_State *L, int index) |
template<> | |
v2f | readParam (lua_State *L, int index) |
template<> | |
v3f | readParam (lua_State *L, int index) |
template<> | |
std::string_view | readParam (lua_State *L, int index) |
template<> | |
std::string | readParam (lua_State *L, int index) |
template<> | |
std::string_view | readParam (lua_State *L, int index) |
Read a string from Lua state L at index without copying it. | |
Protected Attributes | |
std::recursive_mutex | m_luastackmutex |
std::string | m_last_run_mod |
int | m_lock_recursion_count {} |
std::thread::id | m_owning_thread |
Static Private Member Functions | |
static int | luaPanic (lua_State *L) |
Private Attributes | |
lua_State * | m_luastack = nullptr |
IGameDef * | m_gamedef = nullptr |
Environment * | m_environment = nullptr |
EmergeThread * | m_emerge = nullptr |
ScriptingType | m_type |
Friends | |
class | LuaABM |
class | LuaLBM |
class | InvRef |
class | ObjectRef |
class | NodeMetaRef |
class | ModApiBase |
class | ModApiEnv |
class | LuaVoxelManip |
class | TestMoveAction |
Additional Inherited Members | |
Static Protected Member Functions inherited from LuaHelper | |
template<typename T > | |
static T | readParam (lua_State *L, int index) |
Read a value using a template type T from Lua state L at index. | |
template<typename T > | |
static T | readParam (lua_State *L, int index, const T &default_value) |
Read a value using a template type T from Lua state L at index. | |
ScriptApiBase::ScriptApiBase | ( | ScriptingType | type | ) |
References Client, clientOpenLibs(), CUSTOM_RIDX_ERROR_HANDLER, CUSTOM_RIDX_PUSH_MOVERESULT1, CUSTOM_RIDX_PUSH_NODE, CUSTOM_RIDX_PUSH_VECTOR, CUSTOM_RIDX_READ_NODE, CUSTOM_RIDX_READ_VECTOR, CUSTOM_RIDX_SCRIPTAPI, DIR_DELIM, FATAL_ERROR_IF, porting::getPlatformName(), luaPanic(), m_lock_recursion_count, m_luastack, m_type, script_error_handler(), and script_exception_wrapper().
|
inline |
References FATAL_ERROR.
|
virtual |
References m_luastack.
void ScriptApiBase::addObjectReference | ( | ServerActiveObject * | cobj | ) |
References ObjectRef::create(), ActiveObject::getId(), getType(), SCRIPTAPI_PRECHECKHEADER, and Server.
Referenced by ServerEnvironment::addActiveObjectRaw().
void ScriptApiBase::checkSetByBuiltin | ( | ) |
References CHECK, CUSTOM_RIDX_PUSH_MOVERESULT1, CUSTOM_RIDX_PUSH_NODE, CUSTOM_RIDX_PUSH_VECTOR, CUSTOM_RIDX_READ_NODE, CUSTOM_RIDX_READ_VECTOR, getStack(), getType(), m_gamedef, and Server.
Referenced by EmergeThread::initScripting(), ServerScripting::loadBuiltin(), GUIEngine::loadMainMenuScript(), and Client::loadMods().
|
inline |
ScriptApiBase::DISABLE_CLASS_COPY | ( | ScriptApiBase | ) |
|
static |
Returns the currently running mod, only during init time.
The reason this is insecure is that mods can mess with each others code, so the boundary of who is responsible is fuzzy.
References CUSTOM_RIDX_CURRENT_MOD_NAME, and LuaHelper::readParam().
Referenced by ScriptApiSecurity::checkPathWithGamedef(), ScriptApiSecurity::getCurrentModName(), ModApiBase::getCurrentModPath(), ModApiClient::l_get_current_modname(), ModApiServer::l_get_current_modname(), ModApiUtil::l_get_last_run_mod(), ModApiServer::l_get_mod_data_path(), ModApiServer::l_register_async_dofile(), and ModApiServer::l_register_mapgen_script().
|
inlineprotected |
References m_emerge.
Referenced by ModApiBase::getEmergeThread().
|
inlineprotected |
References m_environment.
Referenced by ModApiBase::getEnv(), ScriptApiNode::node_on_receive_fields(), ScriptApiNodemeta::nodemeta_inventory_AllowMove(), ScriptApiNodemeta::nodemeta_inventory_AllowPut(), ScriptApiNodemeta::nodemeta_inventory_AllowTake(), ScriptApiNodemeta::nodemeta_inventory_OnMove(), ScriptApiNodemeta::nodemeta_inventory_OnPut(), ScriptApiNodemeta::nodemeta_inventory_OnTake(), ScriptApiEnv::readABMs(), and ScriptApiEnv::readLBMs().
|
inline |
References m_gamedef.
Referenced by ModApiBase::getGameDef().
|
inline |
References m_last_run_mod.
Referenced by ModApiEnv::l_emerge_area(), and ModApiUtil::l_get_last_run_mod().
Server * ScriptApiBase::getServer | ( | ) |
References m_gamedef.
Referenced by ModApiBase::getServer(), ModApiBase::getServerInventoryMgr(), ScriptApiItem::item_CraftPredict(), ScriptApiItem::item_OnCraft(), ScriptApiItem::item_OnDrop(), ScriptApiItem::item_OnPlace(), ScriptApiItem::item_OnSecondaryUse(), ScriptApiItem::item_OnUse(), LuaEmergeAreaCallback(), ScriptApiEntity::luaentity_GetProperties(), ScriptApiNode::node_after_destruct(), ScriptApiNode::node_on_construct(), ScriptApiNode::node_on_destruct(), ScriptApiNode::node_on_dig(), ScriptApiNode::node_on_flood(), ScriptApiNode::node_on_punch(), ScriptApiNode::node_on_receive_fields(), ScriptApiNode::node_on_timer(), ScriptApiNodemeta::nodemeta_inventory_AllowMove(), ScriptApiNodemeta::nodemeta_inventory_AllowPut(), ScriptApiNodemeta::nodemeta_inventory_AllowTake(), ScriptApiNodemeta::nodemeta_inventory_OnMove(), ScriptApiNodemeta::nodemeta_inventory_OnPut(), ScriptApiNodemeta::nodemeta_inventory_OnTake(), ScriptApiEnv::on_emerge_area_completion(), and ServerScripting::saveGlobals().
|
inlineprotected |
References m_luastack.
Referenced by AsyncWorkerThread::AsyncWorkerThread(), AsyncWorkerThread::checkPathInternal(), EmergeScripting::checkPathInternal(), ServerScripting::checkPathInternal(), checkSetByBuiltin(), ScriptApiServer::getAuthHandler(), ScriptApiDetached::getDetachedInventoryCallback(), ScriptApiItem::getItemCallback(), ScriptApiSecurity::initializeSecurity(), loadMod(), loadScript(), ClientScripting::on_camera_ready(), ClientScripting::on_client_ready(), ClientScripting::on_minimap_ready(), ScriptApiPlayer::pushMoveArguments(), ScriptApiItem::pushPointedThing(), ScriptApiPlayer::pushPutTakeArguments(), ScriptApiServer::readPrivileges(), AsyncWorkerThread::run(), runCallbacksRaw(), scriptError(), setOriginFromTableRaw(), MainMenuScripting::step(), and ServerScripting::stepAsync().
|
inline |
References m_type.
Referenced by addObjectReference(), checkSetByBuiltin(), objectrefGetOrCreate(), pushPlayerHPChangeReason(), removeObjectReference(), and ScriptApiSecurity::sl_g_loadfile().
void ScriptApiBase::loadMod | ( | const std::string & | script_path, |
const std::string & | mod_name ) |
References getStack(), and loadScript().
Referenced by EmergeThread::initScripting(), ServerScripting::loadBuiltin(), and ServerModManager::loadMods().
void ScriptApiBase::loadScript | ( | const std::string & | script_path | ) |
References getStack(), ScriptApiSecurity::isSecure(), PUSH_ERROR_HANDLER, ScriptApiSecurity::safeLoadFile(), and verbosestream.
Referenced by GUIEngine::loadMainMenuScript(), and loadMod().
|
staticprivate |
References FATAL_ERROR, and LuaHelper::readParam().
Referenced by ScriptApiBase().
|
protected |
References ObjectRef::create(), errorstream, ActiveObject::getId(), getType(), ServerActiveObject::isGone(), push_objectRef(), Server, and warningstream.
Referenced by ScriptApiDetached::detached_inventory_AllowMove(), ScriptApiDetached::detached_inventory_AllowPut(), ScriptApiDetached::detached_inventory_AllowTake(), ScriptApiDetached::detached_inventory_OnMove(), ScriptApiDetached::detached_inventory_OnPut(), ScriptApiDetached::detached_inventory_OnTake(), ScriptApiItem::item_CraftPredict(), ScriptApiItem::item_OnCraft(), ScriptApiItem::item_OnDrop(), ScriptApiItem::item_OnPlace(), ScriptApiItem::item_OnSecondaryUse(), ScriptApiItem::item_OnUse(), ModApiEnv::l_add_entity(), ObjectRef::l_get_attach(), ObjectRef::l_get_children(), ModApiEnv::l_get_connected_players(), ModApiEnv::l_get_objects_in_area(), ModApiEnv::l_get_objects_inside_radius(), ModApiEnv::l_get_player_by_name(), ScriptApiEntity::luaentity_Punch(), ScriptApiEntity::luaentity_run_simple_callback(), ScriptApiNode::node_on_dig(), ScriptApiNode::node_on_punch(), ScriptApiNode::node_on_receive_fields(), ScriptApiNodemeta::nodemeta_inventory_AllowMove(), ScriptApiNodemeta::nodemeta_inventory_AllowPut(), ScriptApiNodemeta::nodemeta_inventory_AllowTake(), ScriptApiNodemeta::nodemeta_inventory_OnMove(), ScriptApiNodemeta::nodemeta_inventory_OnPut(), ScriptApiNodemeta::nodemeta_inventory_OnTake(), ScriptApiPlayer::on_cheat(), ScriptApiPlayer::on_dieplayer(), ScriptApiPlayer::on_joinplayer(), ScriptApiPlayer::on_leaveplayer(), ScriptApiPlayer::on_newplayer(), ScriptApiPlayer::on_player_hpchange(), ScriptApiPlayer::on_playerReceiveFields(), ScriptApiPlayer::on_punchplayer(), ScriptApiPlayer::on_respawnplayer(), ScriptApiPlayer::on_rightclickplayer(), ScriptApiEnv::player_event(), ScriptApiPlayer::pushMoveArguments(), pushPlayerHPChangeReason(), and ScriptApiPlayer::pushPutTakeArguments().
|
protected |
References PlayerHPChangeReason::from_mod, getType(), PlayerHPChangeReason::getTypeAsString(), PlayerHPChangeReason::hasLuaReference(), PlayerHPChangeReason::lua_reference, PlayerHPChangeReason::node, PlayerHPChangeReason::node_pos, PlayerHPChangeReason::object, objectrefGetOrCreate(), push_v3s16(), and Server.
Referenced by ScriptApiPlayer::on_dieplayer(), and ScriptApiPlayer::on_player_hpchange().
|
protected |
References dstream, m_luastack, script_get_backtrace(), and stackDump().
void ScriptApiBase::removeObjectReference | ( | ServerActiveObject * | cobj | ) |
References ActiveObject::getId(), getType(), SCRIPTAPI_PRECHECKHEADER, Server, and ObjectRef::set_null().
Referenced by ServerEnvironment::processActiveObjectRemove().
void ScriptApiBase::runCallbacksRaw | ( | int | nargs, |
RunCallbacksMode | mode, | ||
const char * | fxn ) |
References Client, FATAL_ERROR_IF, getStack(), m_lock_recursion_count, m_type, PUSH_ERROR_HANDLER, and scriptError().
|
protected |
References getStack(), m_last_run_mod, and script_error().
Referenced by AsyncWorkerThread::run(), runCallbacksRaw(), ScriptApiEnv::triggerABM(), and ScriptApiEnv::triggerLBM().
|
inlineprotected |
References m_emerge.
Referenced by EmergeScripting::EmergeScripting().
|
inlineprotected |
References m_environment.
Referenced by ScriptApiEnv::initializeEnvironment(), Client::loadMods(), and ScriptApiClient::setEnv().
|
inlineprotected |
References m_gamedef.
Referenced by AsyncWorkerThread::AsyncWorkerThread(), ClientScripting::ClientScripting(), EmergeScripting::EmergeScripting(), and ServerScripting::ServerScripting().
void ScriptApiBase::setOriginDirect | ( | const char * | origin | ) |
References m_last_run_mod.
Referenced by ModApiUtil::l_set_last_run_mod(), ScriptApiEnv::on_emerge_area_completion(), AsyncWorkerThread::run(), and AsyncEngine::stepJobResults().
void ScriptApiBase::setOriginFromTableRaw | ( | int | index, |
const char * | fxn ) |
References getStack(), getstringfield_default(), and m_last_run_mod.
|
protected |
References m_luastack, porting::mt_snprintf(), and LuaHelper::readParam().
Referenced by realityCheck().
|
friend |
|
friend |
Referenced by ScriptApiEnv::readABMs().
|
friend |
Referenced by ScriptApiEnv::readLBMs().
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
Referenced by getEmergeThread(), and setEmergeThread().
|
private |
|
private |
Referenced by checkSetByBuiltin(), getGameDef(), getServer(), and setGameDef().
|
protected |
Referenced by getOrigin(), scriptError(), setOriginDirect(), and setOriginFromTableRaw().
|
protected |
Referenced by ScriptApiBase(), and runCallbacksRaw().
|
private |
Referenced by ScriptApiBase(), ~ScriptApiBase(), getStack(), realityCheck(), and stackDump().
|
protected |
|
protected |
|
private |
Referenced by ScriptApiBase(), getType(), and runCallbacksRaw().