//cdeclParameter 结构化参数
namespace raw;

class cdeclParameter{
	ctor(tableParameter){
		this.tableParameter = tableParameter : {};  
		this._cdcel_functions_cache = {}; 
	};
	pointer _getType = ..raw.tocdecl( _getType,"string(string name)",this );
	pointer _getFunction = ..raw.tocdecl( _getFunction,"pointer(string funcName,string proto)",this );
	pointer _setFunction = ..raw.tocdecl( _setFunction,"pointer(string funcName,string proto,pointer addr)",this );	
	pointer _getBinary = ..raw.tocdecl( _getBinary,"pointer(string name,int &size)",this );	
	pointer _setBinary = ..raw.tocdecl( _setBinary,"void(string name,pointer value,int size)",this);
	pointer _getString = ..raw.tocdecl( _get,"string(string name)",this );	
	pointer _setString = ..raw.tocdecl( _set,"void(string name,string value)",this);
 	pointer _getNumber = ..raw.tocdecl( _get,"int(string name)" ,this);	
	pointer _setNumber = ..raw.tocdecl( _set,"void(string name,double value)",this); 
	pointer _getPointer = ..raw.tocdecl( _get,"pointer(string name)",this );	
	pointer _setPointer = ..raw.tocdecl( _set,"void(string name,pointer value)",this); 
	pointer _callString = ..raw.tocdecl( _call,"int(string name,string arg)",this);
	pointer _callNumber = ..raw.tocdecl( _call,"int(string name,double arg)",this);
	pointer _call = ..raw.tocdecl( _call,"int(string name)",this);  
	pointer _len = ..raw.tocdecl( _len,"INT(string name)",this);
	set = function(tableParameter){
		this.tableParameter = tableParameter : {}; 
	};
	get = function(){
		return this.tableParameter;
	};
}

namespace cdeclParameter{

	_exe = ..raw.loadDll(); 
	_getFunction  = function(funcName,proto){
		var obj,parent = ..table.getByNamespace(funcName,owner.tableParameter)
		if(type(obj)==type.function){  
			if(!owner._cdcel_functions_cache[funcName])
				owner._cdcel_functions_cache[funcName] = {};
			if( ! owner._cdcel_functions_cache[funcName][proto] )
				owner._cdcel_functions_cache[funcName][proto] = ..raw.tocdecl( obj,proto,parent);  
				 
			return owner._cdcel_functions_cache[funcName][proto];
		}
	};
	_setFunction  = function(funcName,proto,addr){ 
		..table.setByNamespace(funcName,_exe.api(addr,proto,"cdecl" ),owner.tableParameter) 
	};
	
	_get = function(name){
		return ..table.getByNamespace(name,owner.tableParameter);
	};
		
	_set = function(name,value){
		..table.setByNamespace(name,value,owner.tableParameter); 
	};
	
	_getBinary = function(name,size){ 
		var s = ..table.getByNamespace(name,owner.tableParameter);
		if( type(s) == type.string ){
			return s,#s;
		}
	};
		
	_setBinary = function(name,value,size){ 
		..table.setByNamespace(name,..raw.tostring(value,1,size),owner.tableParameter); 
	};
	
	_call = function(name,...){
		var func,tab = ..table.getByNamespace(name,owner.tableParameter);
		if(func){
			return invoke( func,tab,...);
		};
	};
	
	_len = function(name,...){
		return # ..table.getByNamespace(name,owner.tableParameter); 
	};
	 
	_getType = function(name){
		var t = ..table.getByNamespace(name,owner.tableParameter);
		if(  null !== t ){
			return type(t);
		}
	};
}


/**intellisense()
raw.cdeclParameter = 结构化参数,仅适用于创建C/C++函数参数
raw.cdeclParameter(绑定参数表) = 用于将AAuto中的普通表对象转换为\n调用C/C++函数时可以用到的结构化参数.\n在API参数类型中相应参数应声明为struct类型
raw.cdeclParameter() = !raw_cdeclParameter. 
!raw_cdeclParameter.get() = 获取绑定的参数表.\nC函数所有读写字段的操作将作用到绑定参数表
!raw_cdeclParameter.set() = 设置绑定的参数表.\n参数如果为空则创建空表作为参数表\nC函数所有读写字段的操作将作用到绑定参数表
end intellisense**/

/* 
//在C语言中定义 raw.cdeclParameter
typedef struct{ 
	const char *(*getType) (const char * name);
	void * (*getFunction) (const char * name,const char *proto);
	void (*setFunction) (const char * name,const char *proto,void * addr); 
	const char *(*getBinary) (const char * name,unsigned int *size);
	void (*setBinary) (const char * name,char * value,unsigned int size);
	const char *(*getString) (const char * name);
	void (*setString) (const char * name,const char * value);
	int (*getNumber) (const char * name);
	void (*setNumber) (const char * name,double value);
	void * (*getPointer) (const char * name);
	void (*setPointer) (const char * name,void * value);
	int (*callString) (const char * name,const char * arg);
	int (*callNumber) (const char * name,double arg);
	int (*call) (const char * name);
	unsigned int(*len)(const char * name);
} cdeclParameter;
*/
