mirror of
https://github.com/minetest/minetest.git
synced 2025-07-05 01:10:22 +02:00
Minor script api fixes/cleanups
This commit is contained in:
@ -298,6 +298,7 @@ AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher,
|
||||
// can't throw from here so we're stuck with this
|
||||
isErrored = true;
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -413,7 +413,7 @@ void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn)
|
||||
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
//infostream<<"scriptapi_add_object_reference: id="<<cobj->getId()<<std::endl;
|
||||
assert(getType() == ScriptingType::Server);
|
||||
|
||||
// Create object on stack
|
||||
ObjectRef::create(L, cobj); // Puts ObjectRef (as userdata) on stack
|
||||
@ -434,7 +434,7 @@ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
|
||||
void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
//infostream<<"scriptapi_rm_object_reference: id="<<cobj->getId()<<std::endl;
|
||||
assert(getType() == ScriptingType::Server);
|
||||
|
||||
// Get core.object_refs table
|
||||
lua_getglobal(L, "core");
|
||||
@ -459,6 +459,7 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
|
||||
void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
|
||||
ServerActiveObject *cobj)
|
||||
{
|
||||
assert(getType() == ScriptingType::Server);
|
||||
if (cobj == NULL || cobj->getId() == 0) {
|
||||
ObjectRef::create(L, cobj);
|
||||
} else {
|
||||
@ -472,6 +473,7 @@ void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
|
||||
|
||||
void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeReason &reason)
|
||||
{
|
||||
assert(getType() == ScriptingType::Server);
|
||||
if (reason.hasLuaReference())
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, reason.lua_reference);
|
||||
else
|
||||
@ -503,8 +505,13 @@ void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeR
|
||||
|
||||
Server* ScriptApiBase::getServer()
|
||||
{
|
||||
// Since the gamedef is the server it's still possible to retrieve it in
|
||||
// e.g. the async environment, but this isn't meant to happen.
|
||||
// TODO: still needs work
|
||||
//assert(getType() == ScriptingType::Server);
|
||||
return dynamic_cast<Server *>(m_gamedef);
|
||||
}
|
||||
|
||||
#ifndef SERVER
|
||||
Client* ScriptApiBase::getClient()
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ extern "C" {
|
||||
setOriginFromTableRaw(index, __FUNCTION__)
|
||||
|
||||
enum class ScriptingType: u8 {
|
||||
Async,
|
||||
Async, // either mainmenu (client) or ingame (server)
|
||||
Client,
|
||||
MainMenu,
|
||||
Server
|
||||
@ -100,9 +100,10 @@ public:
|
||||
void addObjectReference(ServerActiveObject *cobj);
|
||||
void removeObjectReference(ServerActiveObject *cobj);
|
||||
|
||||
ScriptingType getType() { return m_type; }
|
||||
|
||||
IGameDef *getGameDef() { return m_gamedef; }
|
||||
Server* getServer();
|
||||
ScriptingType getType() { return m_type; }
|
||||
#ifndef SERVER
|
||||
Client* getClient();
|
||||
#endif
|
||||
|
@ -59,8 +59,7 @@ bool ScriptApiEntity::luaentity_Add(u16 id, const char *name)
|
||||
// This should be userdata with metatable ObjectRef
|
||||
push_objectRef(L, id);
|
||||
luaL_checktype(L, -1, LUA_TUSERDATA);
|
||||
if (!luaL_checkudata(L, -1, "ObjectRef"))
|
||||
luaL_typerror(L, -1, "ObjectRef");
|
||||
luaL_checkudata(L, -1, "ObjectRef");
|
||||
lua_setfield(L, -2, "object");
|
||||
|
||||
// core.luaentities[id] = object
|
||||
|
Reference in New Issue
Block a user