print("omg lol")
print("minetest dump: "..dump(minetest))
-minetest.register_object("a", "dummy string");
+minetest.register_entity("a", "dummy string");
-local TNT = minetest.new_entity {
+--local TNT = minetest.new_entity {
+local TNT = {
-- Maybe handle gravity and collision this way? dunno
physical = true,
weight = 5,
print("TNT dump: "..dump(TNT))
print("Registering TNT");
-minetest.register_object("TNT", TNT)
+minetest.register_entity("TNT", TNT)
---print("minetest.registered_objects: "..dump(minetest.registered_objects))
-print("minetest.registered_objects:")
-serialize(minetest.registered_objects)
+--print("minetest.registered_entities: "..dump(minetest.registered_entities))
+print("minetest.registered_entities:")
+serialize(minetest.registered_entities)
return "apple.png^[forcesingle";
else if(subname == "apple_iron")
return "apple_iron.png";
+ else if(subname == "testobject1") // test object
+ return "unknown_block.png^[forcesingle";
else
return "cloud.png"; // just something
}
ServerActiveObject *obj = new FireflySAO(env, pos);
return obj;
}
+ else if(subname == "testobject1")
+ {
+ ServerActiveObject *obj = new LuaEntitySAO(env, pos, "TNT", "");
+ return obj;
+ }
return NULL;
}
s16 item_craft_get_drop_count(const std::string &subname)
{
- if(subname == "rat" || subname == "firefly")
+ if(subname == "rat" || subname == "firefly" || subname == "testobject1")
return 1;
return -1;
// name
os<<serializeString(m_init_name);
// state
- std::string state = scriptapi_luaentity_get_state(L, m_id);
- os<<serializeString(state);
+ if(m_registered){
+ lua_State *L = m_env->getLua();
+ scriptapi_luaentity_deregister(L, m_id);
+ std::string state = scriptapi_luaentity_get_state(L, m_id);
+ os<<serializeLongString(state);
+ } else {
+ os<<serializeLongString(m_init_state);
+ }
return os.str();
}
+InventoryItem* LuaEntitySAO::createPickedUpItem()
+{
+ std::istringstream is("CraftItem testobject1 1", std::ios_base::binary);
+ InventoryItem *item = InventoryItem::deSerialize(is);
+ return item;
+}
+
void step(float dtime, bool send_recommended);
std::string getClientInitializationData();
std::string getStaticData();
+ InventoryItem* createPickedUpItem();
private:
std::string m_init_name;
std::string m_init_state;
infostream<<"Loading and running script from "<<path<<std::endl;
int ret = luaL_loadfile(L, path) || lua_pcall(L, 0, 0, 0);
if(ret){
- errorstream<<"Failed to load and run script from "<<path<<": "<<lua_tostring(L, -1)<<std::endl;
+ errorstream<<"Failed to load and run script from "<<path<<":"<<std::endl;
+ errorstream<<"[LUA] "<<lua_tostring(L, -1)<<std::endl;
lua_pop(L, 1); // Pop error message from stack
return false;
}
}
// Register new object prototype (must be based on entity)
-static int l_register_object(lua_State *L)
+static int l_register_entity(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
luaL_checkany(L, 2);
- infostream<<"register_object: "<<name<<std::endl;
+ infostream<<"register_entity: "<<name<<std::endl;
// Get the minetest table
lua_getglobal(L, "minetest");
- // Get field "registered_objects"
- lua_getfield(L, -1, "registered_objects");
+ // Get field "registered_entities"
+ lua_getfield(L, -1, "registered_entities");
luaL_checktype(L, -1, LUA_TTABLE);
int objectstable = lua_gettop(L);
// Object is in param 2
lua_pushvalue(L, 2); // Copy object to top of stack
- lua_setfield(L, objectstable, name); // registered_objects[name] = object
+ lua_setfield(L, objectstable, name); // registered_entities[name] = object
return 0; /* number of results */
}
+#if 0
static int l_new_entity(lua_State *L)
{
/* o = o or {}
// return table
return 1;
}
+#endif
static const struct luaL_Reg minetest_f [] = {
- {"register_object", l_register_object},
- {"new_entity", l_new_entity},
+ {"register_entity", l_register_entity},
+ //{"new_entity", l_new_entity},
{NULL, NULL}
};
// Get the main minetest table
lua_getglobal(L, "minetest");
- // Add registered_objects table in minetest
+ // Add registered_entities table in minetest
lua_newtable(L);
- lua_setfield(L, -2, "registered_objects");
+ lua_setfield(L, -2, "registered_entities");
// Add object_refs table in minetest
lua_newtable(L);
lua_pop(L, 1); // pop object*/
// Set luaentities[id] = nil
- lua_pushnumber(L, cobj->getId()); // Push id
+ lua_pushnumber(L, id); // Push id
lua_pushnil(L);
lua_settable(L, objectstable);
{
realitycheck(L);
assert(lua_checkstack(L, 20));
- infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
+ //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
// Get minetest.luaentities table
lua_getglobal(L, "minetest");
int objectstable = lua_gettop(L);
// Get luaentities[id]
- lua_pushnumber(L, cobj->getId()); // Push id
+ lua_pushnumber(L, id); // Push id
lua_gettable(L, objectstable);
// TODO: Call step function
// Export API
scriptapi_export(m_lua, this);
// Load and run scripts
- script_load(m_lua, (porting::path_data + DIR_DELIM + "scripts"
- + DIR_DELIM + "default.lua").c_str());
+ std::string defaultscript = porting::path_data + DIR_DELIM
+ + "scripts" + DIR_DELIM + "default.lua";
+ bool success = script_load(m_lua, defaultscript.c_str());
+ if(!success){
+ errorstream<<"Server: Failed to load and run "
+ <<defaultscript<<std::endl;
+ assert(0);
+ }
// Initialize Environment