コード例 #1
0
arc_entity  *arc_create_entity(t_uuid id){
 arc_entity *me;
 me = malloc(sizeof(arc_entity));
 me->previous_bliss_score = 1.000;
 me->id = id;
 me->bliss=vs_createvector(id,2);
 me->internal=vs_createvector(newid(),2);
 me->short_term = arc_create_memory();
 me->long_term = arc_create_memory();
 me->actions = vs_createvector(newid(),0);
 me->perception = arc_create_story();
 me->perception_max_duration = 0;
 
 return me;
}
コード例 #2
0
ファイル: GroupAPI.cpp プロジェクト: SiteView/eccmeteor
SVAPI_API
string  CreatIdcUser(string userindex, string pid, string addr)
{
	string newid("");
	if(userindex.empty()||addr.empty() || pid.empty())
		return newid;

	try{
		S_UINT len=0;
		SVDBQUERY querybuf={0};
		querybuf.len = sizeof(SVDBQUERY);
		querybuf.querytype=QUERY_CREATIDC;
		querybuf.datatype=S_GROUP;
		strcpy(querybuf.idcuser,userindex.c_str());
		strcpy(querybuf.qstr,pid.c_str());
		querybuf.datalen=len;

		char *pdata=NULL;
		QueryData qd;
		if(qd.Query(&querybuf,(void **)&pdata,len,addr))
		{
			if(pdata)
			{
				if(len>0)
				{
					newid= pdata;
					delete [] pdata;
					return newid;
				}
				delete [] pdata;
			}
		}
	}catch(...)
	{
	}
	return newid;
}
コード例 #3
0
ファイル: gr_node.c プロジェクト: hleuwer/luagraph
/*-------------------------------------------------------------------------*\
 * Method: e, tail, head = n.edge(self, node, label, flag)
 * Finds or creates an edge. The given node is the tail of the edge.
 * The created node is the the edge.
 * Label is optional.
 * The optional flag nocreate=true inhibits auto-creation of the edge.
 * Any node given by name is implicitly created and it's userdata returned
 * as additional results - even if nocreate is not set.
 * Example:
 * e, tail, head = n.edge(head, "edge-1", true | false)
 * e, tail, head = e:node("headname", "edge-1", true | false)
\*-------------------------------------------------------------------------*/
static int gr_edge(lua_State *L)
{
  Agedge_t *e;
  gr_edge_t *edge;                 
  int rv;
  char *label;
  char ename[32];
  Agraph_t *g;
  gr_node_t *head;
  gr_node_t *tail = tonode(L, 1, STRICT);

  g = agroot(tail->n);
  
  if (lua_isuserdata(L, 2))
    head = tonode(L, 2, STRICT);
  else {
    lua_pushcfunction(L, gr_create_node);             /* tail, nhead, (label), (nocreate), func */
    get_object(L, agroot(tail->n));                   /* tail, nhead, (label), (nocreate), func, graph */
    lua_pushvalue(L, 2);                              /* ... func, graph, nhead */
    if (lua_isboolean(L, 4))                                  
      lua_pushvalue(L, 4);                            /* ... func, graph, nhead, (nocreate) */
    else
      lua_pushboolean(L, 0);                          /* ... func, graph, nhead, false */
    lua_call(L, 3,  1);                              /* tail, nhead, (label), head */
    if (lua_isnil(L, -1))
      return  2;
    head = tonode(L, -1, STRICT);
    lua_pop(L,1);                                    /* tail, nhead, (label) */
  }
  
  g = agroot(tail->n);
  if (g != agroot(head->n)){
    luaL_error(L, "head/tail not in same graph");
  }
  label = (char *) luaL_optstring(L, 3, NULL);         /* ud, peer, name, (flag) */
  if ((e = agedge(g, tail->n, head->n, label, 0)) != NULL){
    rv = get_object(L, e);                           /* ud, peer, name, (flag), edge */
    if (lua_isnil(L, -rv)){
      /* not yet registered */
      lua_pop(L, rv);                                /* ud, peer, name, (flag) */ 
      edge = lua_newuserdata(L, sizeof(gr_edge_t));  /* ud, peer, name, (flag), edge */
      edge->e = e;
      if (label)
	agset(e, "label", label);
      edge->name = strdup(agnameof(e));
      edge->type = AGEDGE;
      edge->status = ALIVE;
      new_edge(L);
      lua_pushlightuserdata(L, tail);
      lua_pushlightuserdata(L, head);     /* ud, peer, name, (flag), edge, tail, head */
      return 3;
    } else {
      /* Edge already registered */
      lua_pushlightuserdata(L, tail);
      lua_pushlightuserdata(L, head);
      return rv + 2;                 /* ud, peer, name, (flag), edge, tail, head */
    }
  } else {
    /* Edge does not exist */
    if (lua_toboolean(L, 4)){
      lua_pushnil(L);
      lua_pushstring(L, "edge not found");
      return 2;
    }
    edge = lua_newuserdata(L, sizeof(gr_edge_t));
    sprintf(ename, "edge@%u", newid());
    if ((edge->e = agedge(g, tail->n, head->n, ename, 1)) == NULL){
      luaL_error(L, "agedge failed");
      return 0;
    }
    if (label)
      agset(edge->e, "label", label);
    edge->name = strdup(agnameof(edge->e));
    edge->type = AGEDGE;
    edge->status = ALIVE;
    new_edge(L);
    lua_pushlightuserdata(L, tail);
    lua_pushlightuserdata(L, head);
    return 3;
  }
}