bool scriptapi_item_on_place(lua_State *L, ItemStack &item,
		ServerActiveObject *placer, const PointedThing &pointed)
{
actionstream<<"DebugTracePlaceEnteredLua scriptapi_item Line 250 "<<std::endl;
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);
actionstream<<"DebugTracePlacePassedStackCheck scriptapi_item Line 254 "<<std::endl;
	// Push callback function on stack
	if(!get_item_callback(L, item.name.c_str(), "on_place"))
actionstream<<"DebugTracePlaceLuaReturningFalse scriptapi_item Line 257 "<<std::endl;
		return false;

	// Call function
	LuaItemStack::create(L, item);
	objectref_get_or_create(L, placer);
	push_pointed_thing(L, pointed);
actionstream<<"DebugTracePlaceClearToRunLua scriptapi_item Line 263 "<<std::endl;
	if(lua_pcall(L, 3, 1, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	if(!lua_isnil(L, -1))
actionstream<<"DebugTracePlaceItemReturned scriptapi_item Line 267 "<<std::endl;
		item = read_item(L, -1);
actionstream<<"DebugTracePlaceLuaReturningTrue scriptapi_item Line 270 "<<std::endl;
	return true;
}
Ejemplo n.º 2
0
bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &pointed)
{
	SCRIPTAPI_PRECHECKHEADER

	// Get core.registered_on_item_use
	lua_getglobal(L, "core");
	lua_getfield(L, -1, "registered_on_item_use");

	// Push data
	LuaItemStack::create(L, item);
	push_pointed_thing(L, pointed);

	// Call functions
	runCallbacks(2, RUN_CALLBACKS_MODE_OR);
	return lua_toboolean(L, -1);
}
Ejemplo n.º 3
0
bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefinition &item)
{
	SCRIPTAPI_PRECHECKHEADER

	// Get core.registered_on_placenode
	lua_getglobal(L, "core");
	lua_getfield(L, -1, "registered_on_placenode");

	// Push data
	push_pointed_thing(L, pointed);
	push_item_definition(L, item);

	// Call functions
	runCallbacks(2, RUN_CALLBACKS_MODE_OR);
	return lua_toboolean(L, -1);
}
bool scriptapi_item_on_use(lua_State *L, ItemStack &item,
		ServerActiveObject *user, const PointedThing &pointed)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	// Push callback function on stack
	if(!get_item_callback(L, item.name.c_str(), "on_use"))
		return false;

	// Call function
	LuaItemStack::create(L, item);
	objectref_get_or_create(L, user);
	push_pointed_thing(L, pointed);
	if(lua_pcall(L, 3, 1, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	if(!lua_isnil(L, -1))
		item = read_item(L, -1);
	return true;
}