#include "content_nodemeta.h"
#include "utility.h"
#include "tool.h"
+#include "daynightratio.h"
static void stackDump(lua_State *L, std::ostream &o)
{
}
}
+/*
+ SimpleSoundSpec
+*/
+
+static void read_soundspec(lua_State *L, int index, SimpleSoundSpec &spec)
+{
+ if(index < 0)
+ index = lua_gettop(L) + 1 + index;
+ if(lua_isnil(L, index)){
+ } else if(lua_istable(L, index)){
+ getstringfield(L, index, "name", spec.name);
+ getfloatfield(L, index, "gain", spec.gain);
+ } else if(lua_isstring(L, index)){
+ spec.name = lua_tostring(L, index);
+ }
+}
+
/*
ItemDefinition
*/
getboolfield(L, index, "legacy_facedir_simple", f.legacy_facedir_simple);
// Set to true if wall_mounted used to be set to true
getboolfield(L, index, "legacy_wallmounted", f.legacy_wallmounted);
+
+ // Sound table
+ lua_getfield(L, index, "sounds");
+ if(lua_istable(L, -1)){
+ lua_getfield(L, -1, "footstep");
+ read_soundspec(L, -1, f.sound_footstep);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "dig");
+ read_soundspec(L, -1, f.sound_dig);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "dug");
+ read_soundspec(L, -1, f.sound_dug);
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
return f;
}
static const char className[];
static const luaL_reg methods[];
-
+public:
static ObjectRef *checkobject(lua_State *L, int narg)
{
luaL_checktype(L, narg, LUA_TUSERDATA);
ServerActiveObject *co = ref->m_object;
return co;
}
-
+private:
static LuaEntitySAO* getluaobject(ObjectRef *ref)
{
ServerActiveObject *obj = getobject(ref);
ObjectRef *ref = checkobject(L, 1);
ServerActiveObject *co = getobject(ref);
if(co == NULL) return 0;
- infostream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl;
+ verbosestream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl;
co->m_removed = true;
return 0;
}
ServerActiveObject *co = getobject(ref);
if(co == NULL) return 0;
int hp = lua_tonumber(L, 2);
- infostream<<"ObjectRef::l_set_hp(): id="<<co->getId()
- <<" hp="<<hp<<std::endl;
+ /*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId()
+ <<" hp="<<hp<<std::endl;*/
// Do it
co->setHP(hp);
// Return
ServerActiveObject *co = getobject(ref);
if(co == NULL) return 0;
int hp = co->getHP();
- infostream<<"ObjectRef::l_get_hp(): id="<<co->getId()
- <<" hp="<<hp<<std::endl;
+ /*infostream<<"ObjectRef::l_get_hp(): id="<<co->getId()
+ <<" hp="<<hp<<std::endl;*/
// Return
lua_pushnumber(L, hp);
return 1;
EnvRef(ServerEnvironment *env):
m_env(env)
{
- infostream<<"EnvRef created"<<std::endl;
+ //infostream<<"EnvRef created"<<std::endl;
}
~EnvRef()
{
- infostream<<"EnvRef destructing"<<std::endl;
+ //infostream<<"EnvRef destructing"<<std::endl;
}
// Creates an EnvRef and leaves it on top of stack
{0,0}
};
-/*
- Global functions
-*/
-
class LuaABM : public ActiveBlockModifier
{
private:
}
};
+/*
+ ServerSoundParams
+*/
+
+static void read_server_sound_params(lua_State *L, int index,
+ ServerSoundParams ¶ms)
+{
+ if(index < 0)
+ index = lua_gettop(L) + 1 + index;
+ // Clear
+ params = ServerSoundParams();
+ if(lua_istable(L, index)){
+ getfloatfield(L, index, "gain", params.gain);
+ getstringfield(L, index, "to_player", params.to_player);
+ lua_getfield(L, index, "pos");
+ if(!lua_isnil(L, -1)){
+ v3f p = read_v3f(L, -1)*BS;
+ params.pos = p;
+ params.type = ServerSoundParams::SSP_POSITIONAL;
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, index, "object");
+ if(!lua_isnil(L, -1)){
+ ObjectRef *ref = ObjectRef::checkobject(L, -1);
+ ServerActiveObject *sao = ObjectRef::getobject(ref);
+ if(sao){
+ params.object = sao->getId();
+ params.type = ServerSoundParams::SSP_OBJECT;
+ }
+ }
+ lua_pop(L, 1);
+ params.max_hear_distance = BS*getfloatfield_default(L, index,
+ "max_hear_distance", params.max_hear_distance/BS);
+ getboolfield(L, index, "loop", params.loop);
+ }
+}
+
+/*
+ Global functions
+*/
+
// debug(text)
// Writes a line to dstream
static int l_debug(lua_State *L)
lua_getfield(L, table, "name");
if(lua_isstring(L, -1)){
std::string name = lua_tostring(L, -1);
- infostream<<"register_item_raw: "<<name<<std::endl;
+ verbosestream<<"register_item_raw: "<<name<<std::endl;
} else {
throw LuaError(L, "register_item_raw: name is not defined or not a string");
}
// Do it
lua_newtable(L);
int table = lua_gettop(L);
- u64 privs_i = server->getPlayerAuthPrivs(name);
- // Special case for the "name" setting (local player / server owner)
- if(name == g_settings->get("name"))
- privs_i = PRIV_ALL;
+ u64 privs_i = server->getPlayerEffectivePrivs(name);
std::set<std::string> privs_s = privsToSet(privs_i);
for(std::set<std::string>::const_iterator
i = privs_s.begin(); i != privs_s.end(); i++){
return 1;
}
+// sound_play(spec, parameters)
+static int l_sound_play(lua_State *L)
+{
+ SimpleSoundSpec spec;
+ read_soundspec(L, 1, spec);
+ ServerSoundParams params;
+ read_server_sound_params(L, 2, params);
+ s32 handle = get_server(L)->playSound(spec, params);
+ lua_pushinteger(L, handle);
+ return 1;
+}
+
+// sound_stop(handle)
+static int l_sound_stop(lua_State *L)
+{
+ int handle = luaL_checkinteger(L, 1);
+ get_server(L)->stopSound(handle);
+ return 0;
+}
+
static const struct luaL_Reg minetest_f [] = {
{"debug", l_debug},
{"log", l_log},
{"get_current_modname", l_get_current_modname},
{"get_modpath", l_get_modpath},
{"get_worldpath", l_get_worldpath},
+ {"sound_play", l_sound_play},
+ {"sound_stop", l_sound_stop},
{NULL, NULL}
};
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_export"<<std::endl;
+ verbosestream<<"scriptapi_export()"<<std::endl;
StackUnroller stack_unroller(L);
// Store server as light userdata in registry
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_add_environment"<<std::endl;
+ verbosestream<<"scriptapi_add_environment"<<std::endl;
StackUnroller stack_unroller(L);
// Create EnvRef on stack
luaentity
*/
-bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
- const std::string &staticdata)
+bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_luaentity_add: id="<<id<<" name=\""
+ verbosestream<<"scriptapi_luaentity_add: id="<<id<<" name=\""
<<name<<"\""<<std::endl;
StackUnroller stack_unroller(L);
lua_pushvalue(L, object); // Copy object to top of stack
lua_settable(L, -3);
+ return true;
+}
+
+void scriptapi_luaentity_activate(lua_State *L, u16 id,
+ const std::string &staticdata)
+{
+ realitycheck(L);
+ assert(lua_checkstack(L, 20));
+ verbosestream<<"scriptapi_luaentity_activate: id="<<id<<std::endl;
+ StackUnroller stack_unroller(L);
+
+ // Get minetest.luaentities[id]
+ luaentity_get(L, id);
+ int object = lua_gettop(L);
+
// Get on_activate function
lua_pushvalue(L, object);
lua_getfield(L, -1, "on_activate");
lua_pushlstring(L, staticdata.c_str(), staticdata.size());
// Call with 2 arguments, 0 results
if(lua_pcall(L, 2, 0, 0))
- script_error(L, "error running function %s:on_activate: %s\n",
- name, lua_tostring(L, -1));
+ script_error(L, "error running function on_activate: %s\n",
+ lua_tostring(L, -1));
}
-
- return true;
}
void scriptapi_luaentity_rm(lua_State *L, u16 id)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_luaentity_rm: id="<<id<<std::endl;
+ verbosestream<<"scriptapi_luaentity_rm: id="<<id<<std::endl;
// Get minetest.luaentities table
lua_getglobal(L, "minetest");
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl;
+ //infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl;
StackUnroller stack_unroller(L);
// Get minetest.luaentities[id]
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl;
+ //infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl;
StackUnroller stack_unroller(L);
// Get minetest.luaentities[id]