summaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_async.cpp29
-rw-r--r--src/script/cpp_api/s_async.h6
-rw-r--r--src/script/cpp_api/s_entity.cpp26
-rw-r--r--src/script/cpp_api/s_entity.h1
-rw-r--r--src/script/cpp_api/s_node.cpp19
-rw-r--r--src/script/cpp_api/s_node.h1
-rw-r--r--src/script/cpp_api/s_player.cpp13
-rw-r--r--src/script/cpp_api/s_player.h1
-rw-r--r--src/script/cpp_api/s_security.cpp11
9 files changed, 65 insertions, 42 deletions
diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp
index 5f1f9297e..0619b32c0 100644
--- a/src/script/cpp_api/s_async.cpp
+++ b/src/script/cpp_api/s_async.cpp
@@ -158,35 +158,6 @@ void AsyncEngine::step(lua_State *L)
}
/******************************************************************************/
-void AsyncEngine::pushFinishedJobs(lua_State* L) {
- // Result Table
- MutexAutoLock l(resultQueueMutex);
-
- unsigned int index = 1;
- lua_createtable(L, resultQueue.size(), 0);
- int top = lua_gettop(L);
-
- while (!resultQueue.empty()) {
- LuaJobInfo jobDone = resultQueue.front();
- resultQueue.pop_front();
-
- lua_createtable(L, 0, 2); // Pre-allocate space for two map fields
- int top_lvl2 = lua_gettop(L);
-
- lua_pushstring(L, "jobid");
- lua_pushnumber(L, jobDone.id);
- lua_settable(L, top_lvl2);
-
- lua_pushstring(L, "retval");
- lua_pushlstring(L, jobDone.serializedResult.data(),
- jobDone.serializedResult.size());
- lua_settable(L, top_lvl2);
-
- lua_rawseti(L, top, index++);
- }
-}
-
-/******************************************************************************/
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
{
for (StateInitializer &stateInitializer : stateInitializers) {
diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h
index b1f4bf45f..99a4f891c 100644
--- a/src/script/cpp_api/s_async.h
+++ b/src/script/cpp_api/s_async.h
@@ -98,12 +98,6 @@ public:
*/
void step(lua_State *L);
- /**
- * Push a list of finished jobs onto the stack
- * @param L The Lua stack
- */
- void pushFinishedJobs(lua_State *L);
-
protected:
/**
* Get a Job from queue to be processed
diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp
index ea9320051..746f7013e 100644
--- a/src/script/cpp_api/s_entity.cpp
+++ b/src/script/cpp_api/s_entity.cpp
@@ -103,6 +103,32 @@ void ScriptApiEntity::luaentity_Activate(u16 id,
lua_pop(L, 2); // Pop object and error handler
}
+void ScriptApiEntity::luaentity_Deactivate(u16 id)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ verbosestream << "scriptapi_luaentity_deactivate: id=" << id << std::endl;
+
+ int error_handler = PUSH_ERROR_HANDLER(L);
+
+ // Get the entity
+ luaentity_get(L, id);
+ int object = lua_gettop(L);
+
+ // Get on_deactivate
+ lua_getfield(L, -1, "on_deactivate");
+ if (!lua_isnil(L, -1)) {
+ luaL_checktype(L, -1, LUA_TFUNCTION);
+ lua_pushvalue(L, object);
+
+ setOriginFromTable(object);
+ PCALL_RES(lua_pcall(L, 1, 0, error_handler));
+ } else {
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 2); // Pop object and error handler
+}
+
void ScriptApiEntity::luaentity_Remove(u16 id)
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_entity.h b/src/script/cpp_api/s_entity.h
index b5f7a6586..b52f6e447 100644
--- a/src/script/cpp_api/s_entity.h
+++ b/src/script/cpp_api/s_entity.h
@@ -33,6 +33,7 @@ public:
bool luaentity_Add(u16 id, const char *name);
void luaentity_Activate(u16 id,
const std::string &staticdata, u32 dtime_s);
+ void luaentity_Deactivate(u16 id);
void luaentity_Remove(u16 id);
std::string luaentity_GetStaticdata(u16 id);
void luaentity_GetProperties(u16 id,
diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp
index e0f9bcd78..f23fbfbde 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -93,6 +93,14 @@ struct EnumString ScriptApiNode::es_NodeBoxType[] =
{0, NULL},
};
+struct EnumString ScriptApiNode::es_TextureAlphaMode[] =
+ {
+ {ALPHAMODE_OPAQUE, "opaque"},
+ {ALPHAMODE_CLIP, "clip"},
+ {ALPHAMODE_BLEND, "blend"},
+ {0, NULL},
+ };
+
bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node,
ServerActiveObject *puncher, const PointedThing &pointed)
{
@@ -133,9 +141,14 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node,
push_v3s16(L, p);
pushnode(L, node, ndef);
objectrefGetOrCreate(L, digger);
- PCALL_RES(lua_pcall(L, 3, 0, error_handler));
- lua_pop(L, 1); // Pop error handler
- return true;
+ PCALL_RES(lua_pcall(L, 3, 1, error_handler));
+
+ // nil is treated as true for backwards compat
+ bool result = lua_isnil(L, -1) || lua_toboolean(L, -1);
+
+ lua_pop(L, 2); // Pop error handler and result
+
+ return result;
}
void ScriptApiNode::node_on_construct(v3s16 p, MapNode node)
diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h
index 81b44f0f0..3f771c838 100644
--- a/src/script/cpp_api/s_node.h
+++ b/src/script/cpp_api/s_node.h
@@ -54,4 +54,5 @@ public:
static struct EnumString es_ContentParamType2[];
static struct EnumString es_LiquidType[];
static struct EnumString es_NodeBoxType[];
+ static struct EnumString es_TextureAlphaMode[];
};
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp
index 712120c61..d3e6138dc 100644
--- a/src/script/cpp_api/s_player.cpp
+++ b/src/script/cpp_api/s_player.cpp
@@ -77,6 +77,19 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
return readParam<bool>(L, -1);
}
+void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
+ ServerActiveObject *clicker)
+{
+ SCRIPTAPI_PRECHECKHEADER
+ // Get core.registered_on_rightclickplayers
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_rightclickplayers");
+ // Call callbacks
+ objectrefGetOrCreate(L, player);
+ objectrefGetOrCreate(L, clicker);
+ runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}
+
s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
s32 hp_change, const PlayerHPChangeReason &reason)
{
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index a337f975b..c0f141862 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -47,6 +47,7 @@ public:
bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
float time_from_last_punch, const ToolCapabilities *toolcap,
v3f dir, s16 damage);
+ void on_rightclickplayer(ServerActiveObject *player, ServerActiveObject *clicker);
s32 on_player_hpchange(ServerActiveObject *player, s32 hp_change,
const PlayerHPChangeReason &reason);
void on_playerReceiveFields(ServerActiveObject *player,
diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp
index 2afa3a191..63058d7c3 100644
--- a/src/script/cpp_api/s_security.cpp
+++ b/src/script/cpp_api/s_security.cpp
@@ -398,10 +398,9 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path, const char
lua_pushfstring(L, "%s: %s", path, strerror(errno));
return false;
}
- chunk_name = new char[strlen(display_name) + 2];
- chunk_name[0] = '@';
- chunk_name[1] = '\0';
- strcat(chunk_name, display_name);
+ size_t len = strlen(display_name) + 2;
+ chunk_name = new char[len];
+ snprintf(chunk_name, len, "@%s", display_name);
}
size_t start = 0;
@@ -629,7 +628,11 @@ int ScriptApiSecurity::sl_g_loadfile(lua_State *L)
{
#ifndef SERVER
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI);
+#if INDIRECT_SCRIPTAPI_RIDX
+ ScriptApiBase *script = (ScriptApiBase *) *(void**)(lua_touserdata(L, -1));
+#else
ScriptApiBase *script = (ScriptApiBase *) lua_touserdata(L, -1);
+#endif
lua_pop(L, 1);
// Client implementation