Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
ScriptApiBase Class Reference

#include <s_base.h>

+ Inheritance diagram for ScriptApiBase:
+ Collaboration diagram for ScriptApiBase:

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 ()
 
IGameDefgetGameDef ()
 
ServergetServer ()
 
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)
 
static std::string getCurrentModName (lua_State *L)
 

Protected Member Functions

lua_State * getStack ()
 
void realityCheck ()
 
void scriptError (int result, const char *fxn)
 
void stackDump (std::ostream &o)
 
void setGameDef (IGameDef *gamedef)
 
EnvironmentgetEnv ()
 
void setEnv (Environment *env)
 
EmergeThreadgetEmergeThread ()
 
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
 
bool m_secure = false
 
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
 
IGameDefm_gamedef = nullptr
 
Environmentm_environment = nullptr
 
EmergeThreadm_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.
 

Constructor & Destructor Documentation

◆ ScriptApiBase() [1/2]

ScriptApiBase::ScriptApiBase ( ScriptingType type)

◆ ScriptApiBase() [2/2]

ScriptApiBase::ScriptApiBase ( )
inline

References FATAL_ERROR.

◆ ~ScriptApiBase()

ScriptApiBase::~ScriptApiBase ( )
virtual

References m_luastack.

Member Function Documentation

◆ addObjectReference()

void ScriptApiBase::addObjectReference ( ServerActiveObject * cobj)

References ObjectRef::create(), ActiveObject::getId(), getType(), SCRIPTAPI_PRECHECKHEADER, and Server.

Referenced by ServerEnvironment::addActiveObjectRaw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkSetByBuiltin()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clientOpenLibs()

void ScriptApiBase::clientOpenLibs ( lua_State * L)
inline

Referenced by ScriptApiBase().

+ Here is the caller graph for this function:

◆ DISABLE_CLASS_COPY()

ScriptApiBase::DISABLE_CLASS_COPY ( ScriptApiBase )

◆ getCurrentModName()

std::string ScriptApiBase::getCurrentModName ( lua_State * L)
static

References Async, Emerge, FATAL_ERROR_IF, getCurrentModNameInsecure(), and ModApiBase::getScriptApiBase().

Referenced by ScriptApiSecurity::checkWhitelisted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrentModNameInsecure()

std::string ScriptApiBase::getCurrentModNameInsecure ( lua_State * L)
static

References CUSTOM_RIDX_CURRENT_MOD_NAME, and LuaHelper::readParam().

Referenced by ScriptApiSecurity::checkPath(), 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEmergeThread()

EmergeThread * ScriptApiBase::getEmergeThread ( )
inlineprotected

References m_emerge.

Referenced by ModApiBase::getEmergeThread().

+ Here is the caller graph for this function:

◆ getEnv()

◆ getGameDef()

IGameDef * ScriptApiBase::getGameDef ( )
inline

References m_gamedef.

Referenced by ScriptApiSecurity::checkPath(), and ModApiBase::getGameDef().

+ Here is the caller graph for this function:

◆ getOrigin()

const std::string & ScriptApiBase::getOrigin ( )
inline

References m_last_run_mod.

Referenced by ModApiEnv::l_emerge_area(), and ModApiUtil::l_get_last_run_mod().

+ Here is the caller graph for this function:

◆ getServer()

◆ getStack()

◆ getType()

ScriptingType ScriptApiBase::getType ( )
inline

References m_type.

Referenced by addObjectReference(), checkSetByBuiltin(), objectrefGetOrCreate(), pushPlayerHPChangeReason(), removeObjectReference(), and ScriptApiSecurity::sl_g_loadfile().

+ Here is the caller graph for this function:

◆ loadMod()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadScript()

void ScriptApiBase::loadScript ( const std::string & script_path)

References getStack(), m_secure, PUSH_ERROR_HANDLER, ScriptApiSecurity::safeLoadFile(), and verbosestream.

Referenced by GUIEngine::loadMainMenuScript(), and loadMod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ luaPanic()

int ScriptApiBase::luaPanic ( lua_State * L)
staticprivate

References FATAL_ERROR, and LuaHelper::readParam().

Referenced by ScriptApiBase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ objectrefGetOrCreate()

void ScriptApiBase::objectrefGetOrCreate ( lua_State * L,
ServerActiveObject * cobj )
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pushPlayerHPChangeReason()

void ScriptApiBase::pushPlayerHPChangeReason ( lua_State * L,
const PlayerHPChangeReason & reason )
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ realityCheck()

void ScriptApiBase::realityCheck ( )
protected

References dstream, m_luastack, script_get_backtrace(), and stackDump().

+ Here is the call graph for this function:

◆ removeObjectReference()

void ScriptApiBase::removeObjectReference ( ServerActiveObject * cobj)

References ActiveObject::getId(), getType(), SCRIPTAPI_PRECHECKHEADER, Server, and ObjectRef::set_null().

Referenced by ServerEnvironment::processActiveObjectRemove().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runCallbacksRaw()

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().

+ Here is the call graph for this function:

◆ scriptError()

void ScriptApiBase::scriptError ( int result,
const char * fxn )
protected

References getStack(), m_last_run_mod, and script_error().

Referenced by AsyncWorkerThread::run(), runCallbacksRaw(), ScriptApiEnv::triggerABM(), and ScriptApiEnv::triggerLBM().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setEmergeThread()

void ScriptApiBase::setEmergeThread ( EmergeThread * emerge)
inlineprotected

References m_emerge.

Referenced by EmergeScripting::EmergeScripting().

+ Here is the caller graph for this function:

◆ setEnv()

void ScriptApiBase::setEnv ( Environment * env)
inlineprotected

References m_environment.

Referenced by ScriptApiEnv::initializeEnvironment(), Client::loadMods(), and ScriptApiClient::setEnv().

+ Here is the caller graph for this function:

◆ setGameDef()

void ScriptApiBase::setGameDef ( IGameDef * gamedef)
inlineprotected

References m_gamedef.

Referenced by AsyncWorkerThread::AsyncWorkerThread(), ClientScripting::ClientScripting(), EmergeScripting::EmergeScripting(), and ServerScripting::ServerScripting().

+ Here is the caller graph for this function:

◆ setOriginDirect()

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().

+ Here is the caller graph for this function:

◆ setOriginFromTableRaw()

void ScriptApiBase::setOriginFromTableRaw ( int index,
const char * fxn )

References getStack(), getstringfield_default(), and m_last_run_mod.

+ Here is the call graph for this function:

◆ stackDump()

void ScriptApiBase::stackDump ( std::ostream & o)
protected

References m_luastack, porting::mt_snprintf(), and LuaHelper::readParam().

Referenced by realityCheck().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ InvRef

friend class InvRef
friend

◆ LuaABM

friend class LuaABM
friend

Referenced by ScriptApiEnv::readABMs().

◆ LuaLBM

friend class LuaLBM
friend

Referenced by ScriptApiEnv::readLBMs().

◆ LuaVoxelManip

friend class LuaVoxelManip
friend

◆ ModApiBase

friend class ModApiBase
friend

◆ ModApiEnv

friend class ModApiEnv
friend

◆ NodeMetaRef

friend class NodeMetaRef
friend

◆ ObjectRef

friend class ObjectRef
friend

◆ TestMoveAction

friend class TestMoveAction
friend

Member Data Documentation

◆ m_emerge

EmergeThread* ScriptApiBase::m_emerge = nullptr
private

Referenced by getEmergeThread(), and setEmergeThread().

◆ m_environment

Environment* ScriptApiBase::m_environment = nullptr
private

Referenced by getEnv(), and setEnv().

◆ m_gamedef

IGameDef* ScriptApiBase::m_gamedef = nullptr
private

◆ m_last_run_mod

std::string ScriptApiBase::m_last_run_mod
protected

◆ m_lock_recursion_count

int ScriptApiBase::m_lock_recursion_count {}
protected

Referenced by ScriptApiBase(), and runCallbacksRaw().

◆ m_luastack

lua_State* ScriptApiBase::m_luastack = nullptr
private

◆ m_luastackmutex

std::recursive_mutex ScriptApiBase::m_luastackmutex
protected

◆ m_owning_thread

std::thread::id ScriptApiBase::m_owning_thread
protected

◆ m_secure

bool ScriptApiBase::m_secure = false
protected

◆ m_type

ScriptingType ScriptApiBase::m_type
private

The documentation for this class was generated from the following files: