Ejemplo n.º 1
0
DllExport int call_conv change_char(CTXTdecl)
{
   char	*str_in; 
   int	pos;
   char *c, *str_out;

	str_in = (char *) extern_ptoc_string(1);
	str_out = (char *) calloc(strlen(str_in)+1, sizeof(char));
	strcpy(str_out, str_in);
	pos = extern_ptoc_int(2);
	c = (char *) extern_ptoc_string(3);
	str_out[pos-1] = c[0];

	/* Now that we have constructed a new symbol, we must ensure that it
	   appears in the symbol table.  This can be done using function
	   string_find() that searches the symbol table for the symbol, and
	   if the symbol does not appear there, it inserts it.  If we are 
	   sure that the symbol already appeared in the symbol table there
	   is no need to use string_find(). 
	 */

	extern_ctop_string(CTXTc 4, str_out);
	free(str_out);
	// extern_ctop_string(4, (char *) string_find(str_out,4));

	return TRUE;
}
Ejemplo n.º 2
0
int return_to_prolog(PyObject *pValue)
{
	if(pValue == Py_None){
		return 1;
	}
	if(PyInt_Check(pValue))
	{
		int result = PyInt_AS_LONG(pValue);
		extern_ctop_int(3, result);
		return 1;
	}
	else if(PyFloat_Check(pValue))
	{
		float result = PyFloat_AS_DOUBLE(pValue);
		extern_ctop_float(3, result);
		return 1;
	}else if(PyString_Check(pValue))
	{
		char *result = PyString_AS_STRING(pValue);
		extern_ctop_string(3, result);
		return 1;
	}else if(PyList_Check(pValue))
	{
		size_t size = PyList_Size(pValue);
		size_t i = 0;
		prolog_term head, tail;
		prolog_term P = p2p_new();
		tail = P;
		
		for(i = 0; i < size; i++)
		{
			c2p_list(CTXTc tail);
			head = p2p_car(CTXTc tail);
			PyObject *pyObj = PyList_GetItem(pValue, i);
			int temp = PyInt_AS_LONG(pyObj);
			c2p_int(temp, head);
			//convert_pyObj_prObj(pyObj, &head);				
			tail = p2p_cdr(tail);
		}
		c2p_nil(CTXTc tail);
		p2p_unify(P, reg_term(CTXTc 3));
		return 1;
	}else
	{
		//returns an object refernce to prolog side.
		pyobj_ref_node *node = 	add_pyobj_ref_list(pValue);
		//printf("node : %p", node);	
	char str[30];
		sprintf(str, "%p", node);
		//extern_ctop_string(3,str);
	  prolog_term ref = p2p_new();
		c2p_functor("pyObject", 1, ref);
		prolog_term ref_inner = p2p_arg(ref, 1);
    c2p_string(str, ref_inner);		
		p2p_unify(ref, reg_term(CTXTc 3));	
		return 1;
	}
	return 0;
}