示例#1
0
PUBLIC gboolean objectstore_read(FILE *f, ObjectStore *db) {
    ObjectStoreItem *item;
    ObjectStoreDatum *datum;
    char magic[5];

    setlocale( LC_NUMERIC, "C" );


    fread(magic, sizeof(char), 4, f);
    magic[4] = '\0';
    if (strcmp(magic, "Mjik")) {
	setlocale( LC_NUMERIC, "" );
	return FALSE;
    }

    item = read_item(f);

    if (strcmp(item->tag, "ObjectStore") ||
	    item->key != 0) {
	objectstore_kill_objectstoreitem(NULL, item, NULL);
	setlocale( LC_NUMERIC, "" );
	return FALSE;
    }

    datum = objectstore_item_get(item, "version");
    if (datum == NULL ||
	    datum->kind != OSI_KIND_INT ||
	    datum->d.integer != OBJECTSTORE_CURRENT_VERSION) {
	objectstore_kill_objectstoreitem(NULL, item, NULL);
	setlocale( LC_NUMERIC, "" );
	return FALSE;
    }

    datum = objectstore_item_get(item, "rootkey");
    if (datum == NULL ||
	    datum->kind != OSI_KIND_INT) {
	setlocale( LC_NUMERIC, "");
	return FALSE;
    }
    db->rootkey = datum->d.integer;

    objectstore_kill_objectstoreitem(NULL, item, NULL);

    while (!feof(f)) {
	item = read_item(f);
	if (item != NULL) {
	    g_hash_table_insert(db->object_table, (gpointer) item->key, item);
	    item->db = db;
	    db->nextkey = MAX(db->nextkey, item->key + 1);
	}
    }

    setlocale( LC_NUMERIC, "" );
    return TRUE;
}
示例#2
0
// add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
	GET_ENV_PTR;

	// pos
	//v3f pos = checkFloatPos(L, 1);
	// item
	ItemStack item = read_item(L, 2,getServer(L));
	if(item.empty() || !item.isKnown(getServer(L)->idef()))
		return 0;

	lua_pushcfunction(L, script_error_handler);
	int errorhandler = lua_gettop(L);

	// Use spawn_item to spawn a __builtin:item
	lua_getglobal(L, "core");
	lua_getfield(L, -1, "spawn_item");
	lua_remove(L, -2); // Remove core
	if(lua_isnil(L, -1))
		return 0;
	lua_pushvalue(L, 1);
	lua_pushstring(L, item.getItemString().c_str());

	PCALL_RESL(L, lua_pcall(L, 2, 1, errorhandler));

	lua_remove(L, errorhandler); // Remove error handler
	return 1;
}
示例#3
0
文件: s_item.cpp 项目: 00c/minetest
bool ScriptApiItem::item_OnUse(ItemStack &item,
		ServerActiveObject *user, const PointedThing &pointed)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

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

	// Call function
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(L, user);
	pushPointedThing(pointed);
	PCALL_RES(lua_pcall(L, 3, 1, error_handler));
	if(!lua_isnil(L, -1)) {
		try {
			item = read_item(L,-1, getServer());
		} catch (LuaError &e) {
			throw LuaError(std::string(e.what()) + ". item=" + item.name);
		}
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}
示例#4
0
 int load() {
     getc();
     while (!_files.empty()) {
         ll_failed_return(read_item());
     }
     return ok;
 }
示例#5
0
bool ScriptApiItem::item_OnDrop(ItemStack &item,
		ServerActiveObject *dropper, v3f pos)
{
	SCRIPTAPI_PRECHECKHEADER

	lua_pushcfunction(L, script_error_handler);
	int errorhandler = lua_gettop(L);

	// Push callback function on stack
	if(!getItemCallback(item.name.c_str(), "on_drop"))
		return false;

	// Call function
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(dropper);
	pushFloatPos(L, pos);
	if(lua_pcall(L, 3, 1, errorhandler))
		scriptError();
	if(!lua_isnil(L, -1)) {
		try {
			item = read_item(L,-1, getServer());
		} catch (LuaError &e) {
			throw LuaError(std::string(e.what()) + ". item=" + item.name);
		}
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}
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;
}
示例#7
0
/*
 * nagp_iio_provider_read_items:
 *
 * Note that whatever be the version of the read action, it will be
 * stored as a #NAObjectAction and its set of #NAObjectProfile of the same,
 * latest, version of these classes.
 */
GList *
nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages )
{
	static const gchar *thisfn = "nagp_reader_nagp_iio_provider_read_items";
	NagpGConfProvider *self;
	GList *items_list = NULL;
	GSList *listpath, *ip;
	NAObjectItem *item;

	g_debug( "%s: provider=%p, messages=%p", thisfn, ( void * ) provider, ( void * ) messages );

	g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL );
	g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider ), NULL );
	self = NAGP_GCONF_PROVIDER( provider );

	if( !self->private->dispose_has_run ){

		listpath = na_gconf_utils_get_subdirs( self->private->gconf, NAGP_CONFIGURATIONS_PATH );

		for( ip = listpath ; ip ; ip = ip->next ){

			item = read_item( self, ( const gchar * ) ip->data, messages );
			if( item ){
				items_list = g_list_prepend( items_list, item );
				na_object_dump( item );
			}
		}

		na_gconf_utils_free_subdirs( listpath );
	}

	g_debug( "%s: count=%d", thisfn, g_list_length( items_list ));
	return( items_list );
}
示例#8
0
文件: s_item.cpp 项目: 00c/minetest
bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
		const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	lua_getglobal(L, "core");
	lua_getfield(L, -1, "craft_predict");
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(L, user);

	//Push inventory list
	std::vector<ItemStack> items;
	for (u32 i = 0; i < old_craft_grid->getSize(); i++) {
		items.push_back(old_craft_grid->getItem(i));
	}
	push_items(L, items);

	InvRef::create(L, craft_inv);
	PCALL_RES(lua_pcall(L, 4, 1, error_handler));
	if (!lua_isnil(L, -1)) {
		try {
			item = read_item(L,-1, getServer());
		} catch (LuaError &e) {
			throw LuaError(std::string(e.what()) + ". item=" + item.name);
		}
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}
示例#9
0
文件: prss.c 项目: bsdplus/fluxbsd
static inline void read_element(PRSS *res, xmlNodePtr n)
{
	xmlNodePtr child;

	if (n->type != XML_ELEMENT_NODE) {
		return;
	}
	child = n->children;

	if (!child) {
		return;
	}

#define ASSIGN(a) if (strcasecmp((const char*)n->name, #a) == EQUAL) { \
		if (res->a) free(res->a); \
		res->a = strdup((const char*)child->content); \
		return; \
	}
	ASSIGN(title);
	ASSIGN(link);
	ASSIGN(description);
	ASSIGN(language);
	ASSIGN(pubDate);
	ASSIGN(lastBuildDate);
	ASSIGN(generator);
	ASSIGN(docs);
	ASSIGN(managingEditor);
	ASSIGN(webMaster);
	ASSIGN(copyright);
	ASSIGN(ttl);
#undef ASSIGN
	if (!strcasecmp((const char*)n->name, "item")) {
		read_item(&res->items[res->item_count++], n->children);
	}
}
// replace(self, itemstack or itemstring or table or nil) -> true
int LuaItemStack::l_replace(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	o->m_stack = read_item(L, 2);
	lua_pushboolean(L, true);
	return 1;
}
示例#11
0
bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
		const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
{
	SCRIPTAPI_PRECHECKHEADER

	lua_pushcfunction(L, script_error_handler);
	int errorhandler = lua_gettop(L);

	lua_getglobal(L, "minetest");
	lua_getfield(L, -1, "on_craft");
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(user);
	
	//Push inventory list
	std::vector<ItemStack> items;
	for(u32 i=0; i<old_craft_grid->getSize(); i++)
		items.push_back(old_craft_grid->getItem(i));
	push_items(L, items);

	InvRef::create(L, craft_inv);
	if(lua_pcall(L, 4, 1, errorhandler))
		scriptError();
	if(!lua_isnil(L, -1)) {
		try {
			item = read_item(L,-1, getServer());
		} catch (LuaError &e) {
			throw LuaError(std::string(e.what()) + ". item=" + item.name);
		}
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}
示例#12
0
 QString read_item( IDispatchPtr dispatch, const QByteArray &record )
 {
     Q_ASSERT( dispatch );
     Outlook::_AppointmentItemPtr item( dispatch );
     QXmlStreamReader reader(record);
     return read_item( item, reader, false );
 }
示例#13
0
// minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
	GET_ENV_PTR;

	// pos
	//v3f pos = checkFloatPos(L, 1);
	// item
	ItemStack item = read_item(L, 2,getServer(L));
	if(item.empty() || !item.isKnown(getServer(L)->idef()))
		return 0;
	// Use minetest.spawn_item to spawn a __builtin:item
	lua_getglobal(L, "minetest");
	lua_getfield(L, -1, "spawn_item");
	if(lua_isnil(L, -1))
		return 0;
	lua_pushvalue(L, 1);
	lua_pushstring(L, item.getItemString().c_str());
	if(lua_pcall(L, 2, 1, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	return 1;
	/*lua_pushvalue(L, 1);
	lua_pushstring(L, "__builtin:item");
	lua_pushstring(L, item.getItemString().c_str());
	return l_add_entity(L);*/
	/*// Do it
	ServerActiveObject *obj = createItemSAO(env, pos, item.getItemString());
	int objectid = env->addActiveObject(obj);
	// If failed to add, return nothing (reads as nil)
	if(objectid == 0)
		return 0;
	// Return ObjectRef
	objectrefGetOrCreate(L, obj);
	return 1;*/
}
示例#14
0
// replace(self, itemstack or itemstring or table or nil) -> true
int LuaItemStack::l_replace(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	LuaItemStack *o = checkobject(L, 1);
	o->m_stack = read_item(L,2,getServer(L));
	lua_pushboolean(L, true);
	return 1;
}
示例#15
0
文件: misc.c 项目: Jalakas/navit
void
process_binfile(FILE *in, FILE *out)
{
	struct item_bin *ib;
	while ((ib=read_item(in))) {
		fwrite(ib, (ib->len+1)*4, 1, out);
	}
}
示例#16
0
文件: misc.c 项目: Jalakas/navit
void
dump(FILE *in)
{
	struct item_bin *ib;
	while ((ib=read_item(in))) {
		dump_itembin(ib);
	}
}
示例#17
0
文件: ch.c 项目: PDXostc/navit
static void
ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg)
{
	GHashTable *hash=coord_hash_new();
	struct item_bin *ib;
	int nodes=0,edges=0;

	while ((ib=read_item(in))) {
		int ccount=ib->clen/2;
                struct coord *c=(struct coord *)(ib+1);
		if (road_speed(ib->type)) {
			add_node_to_hash(idx, hash, &c[0], &nodes);
			add_node_to_hash(idx, hash, &c[ccount-1], &nodes);
			edges++;
		}
	}
	edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free);
	fseek(in, 0, SEEK_SET);
	fprintf(ddsg,"d\n");
	fprintf(ddsg,"%d %d\n", nodes, edges);
	while ((ib=read_item(in))) {
		int i,ccount=ib->clen/2;
                struct coord *c=(struct coord *)(ib+1);
		int n1,n2,speed=road_speed(ib->type);
		struct item_id road_id;
		double l;
		fread(&road_id, sizeof(road_id), 1, ref);
		if (speed) {
			struct edge_hash_item *hi=g_slice_new(struct edge_hash_item);
			struct item_id *id=g_slice_new(struct item_id);
			*id=road_id;
			dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0);
			dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0);
			l=0;
			for (i = 0 ; i < ccount-1 ; i++) {
				l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y));
			}
			fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed));
			hi->first=n1-1;
			hi->last=n2-1;
			g_hash_table_insert(edge_hash, hi, id);
		}
	}
	g_hash_table_destroy(hash);
}
// LuaItemStack(itemstack or itemstring or table or nil)
// Creates an LuaItemStack and leaves it on top of stack
int LuaItemStack::create_object(lua_State *L)
{
	ItemStack item = read_item(L, 1);
	LuaItemStack *o = new LuaItemStack(item);
	*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
	luaL_getmetatable(L, className);
	lua_setmetatable(L, -2);
	return 1;
}
// add_item(self, itemstack or itemstring or table or nil) -> itemstack
// Returns leftover item stack
int LuaItemStack::l_add_item(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	ItemStack newitem = read_item(L, 2);
	ItemStack leftover = item.addItem(newitem, get_server(L)->idef());
	create(L, leftover);
	return 1;
}
示例#20
0
// LuaItemStack(itemstack or itemstring or table or nil)
// Creates an LuaItemStack and leaves it on top of stack
int LuaItemStack::create_object(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ItemStack item = read_item(L, 1, getServer(L));
	LuaItemStack *o = new LuaItemStack(item);
	*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
	luaL_getmetatable(L, className);
	lua_setmetatable(L, -2);
	return 1;
}
示例#21
0
// add_item(self, itemstack or itemstring or table or nil) -> itemstack
// Returns leftover item stack
int LuaItemStack::l_add_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	ItemStack newitem = read_item(L,-1, getServer(L));
	ItemStack leftover = item.addItem(newitem, getServer(L)->idef());
	create(L, leftover);
	return 1;
}
示例#22
0
文件: p105.c 项目: mchalek/euler
void read_items(char buf[], int *nitems, int items[]) {
    int start = 0;
    int stop = strlen(buf);
    *nitems = 0;

    do {
        int item = read_item(&start, stop, buf);
        items[*nitems] = item;
        (*nitems)++;
    } while(start < stop);
}
// item_fits(self, itemstack or itemstring or table or nil) -> true/false, itemstack
// First return value is true iff the new item fits fully into the stack
// Second return value is the would-be-left-over item stack
int LuaItemStack::l_item_fits(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	ItemStack newitem = read_item(L, 2);
	ItemStack restitem;
	bool fits = item.itemFits(newitem, &restitem, get_server(L)->idef());
	lua_pushboolean(L, fits);  // first return value
	create(L, restitem);       // second return value
	return 2;
}
示例#24
0
struct item_bin *
read_item_range(FILE *in, int *min, int *max)
{
	struct range r;

	if (fread(&r, sizeof(r), 1, in) != 1)
		return NULL;
	*min=r.min;
	*max=r.max;
	return read_item(in);
}
示例#25
0
static int read_boolean(struct chunk *chunk)
{
	struct item item;

	if (!read_item(chunk, &item))
		return -1;
	if (item.len != 1)
		return 0;

	return item.data[0] == '1';
}
示例#26
0
// set_wielded_item(self, itemstack or itemstring or table or nil)
int ObjectRef::l_set_wielded_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *co = getobject(ref);
	if(co == NULL) return 0;
	// Do it
	ItemStack item = read_item(L, 2, getServer(L));
	bool success = co->setWieldedItem(item);
	lua_pushboolean(L, success);
	return 1;
}
示例#27
0
static char *read_plain_string(struct chunk *chunk)
{
	struct item item;

	if (!read_item(chunk, &item))
		return NULL;

	if (item.len == 0)
		return xstrdup("");

	return xstrndup(item.data, item.len);
}
示例#28
0
void item_list::do_read(item_t* item)
{
  int index = get_entry(item).c - 'a';

  if (read_item(item, &player))
  {
    item->stacksize--;
    if (item->stacksize == 0)
    {
      nullify_item_at(index);
    }
  }
}
示例#29
0
// contains_item(self, listname, itemstack or itemstring or table or nil) -> true/false
// Returns true if the list contains the given count of the given item name
int InvRef::l_contains_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);
	ItemStack item = read_item(L, 3, getServer(L)->idef());
	InventoryList *list = getlist(L, ref, listname);
	if(list){
		lua_pushboolean(L, list->containsItem(item));
	} else {
		lua_pushboolean(L, false);
	}
	return 1;
}
示例#30
0
// room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false
// Returns true if the item completely fits into the list
int InvRef::l_room_for_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);
	ItemStack item = read_item(L, 3,STACK_TO_SERVER(L));
	InventoryList *list = getlist(L, ref, listname);
	if(list){
		lua_pushboolean(L, list->roomForItem(item));
	} else {
		lua_pushboolean(L, false);
	}
	return 1;
}