text: #include "ring.h"
  
  #include "stdlib.h"
  
  RING_FUNC(ring_myfunction)
  {
  	printf("Hello, World!\n");
  }
  
  RING_FUNC(ring_sumtwonumbers)
  {
  	double nNum1,nNum2,nSum;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 2) {
  			RING_API_ERROR(RING_API_MISS2PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! (RING_API_ISNUMBER(1) && RING_API_ISNUMBER(2)) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Sum Numbers 
  		nNum1 = RING_API_GETNUMBER(1);
  		nNum2 = RING_API_GETNUMBER(2);
  		nSum  = nNum1 + nNum2 ;
  	// Return Output
  		RING_API_RETNUMBER(nSum);
  }
  
  RING_FUNC(ring_sayhello)
  {
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 1) {
  			RING_API_ERROR(RING_API_MISS1PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! RING_API_ISSTRING(1) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	printf("Hello %s\n",RING_API_GETSTRING(1));
  }
  
  RING_FUNC(ring_sumlist)
  {
  	List *pList;
  	int x,nSum;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 1) {
  			RING_API_ERROR(RING_API_MISS1PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! RING_API_ISPOINTER(1) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Sum List Numbers 
  		nSum = 0;
  		pList = RING_API_GETLIST(1);
  		for(x=1 ; x <= ring_list_getsize(pList) ; x++) {
  			if ( ring_list_isdouble(pList,x) ) {
  				nSum += (int) ring_list_getdouble(pList,x) ;
  			}
  		}
  	// Return Output 
  		RING_API_RETNUMBER(nSum);
  }
  
  RING_FUNC(ring_inclist)
  {
  	List *pList;
  	int x,nSum;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 2) {
  			RING_API_ERROR(RING_API_MISS2PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! ( RING_API_ISPOINTER(1) && RING_API_ISNUMBER(2) ) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Increment List Items
  		nSum = 0;
  		pList = RING_API_GETLIST(1);
  		for(x=1 ; x <= ring_list_getsize(pList) ; x++) {
  			if ( ring_list_isdouble(pList,x) ) {
  				ring_list_setdouble(pList,x,ring_list_getdouble(pList,x)+RING_API_GETNUMBER(2)) ;
  			}
  		}
  	// Return Output
  		RING_API_RETLIST(pList);
  }
  
  RING_FUNC(ring_filterlist)
  {
  	List *pList;
  	int x;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 2) {
  			RING_API_ERROR(RING_API_MISS2PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! ( RING_API_ISPOINTER(1) && RING_API_ISNUMBER(2) ) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Filter List Items
  		pList = RING_API_GETLIST(1);
  		for(x = ring_list_getsize(pList) ; x >= 1 ; x--) 
  			if ( ring_list_isdouble(pList,x) ) 
  				if ( ! (ring_list_getdouble(pList,x) > RING_API_GETNUMBER(2)) )
  					ring_list_deleteitem(pList,x) ;
  	// Return Output
  		RING_API_RETLIST(pList);
  }
  
  RING_FUNC(ring_replicatelist)
  {
  	List *pList;
  	int x,y,nTimes,nSize;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 2) {
  			RING_API_ERROR(RING_API_MISS2PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! ( RING_API_ISPOINTER(1) && RING_API_ISNUMBER(2) ) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Replicate List Items
  		pList = RING_API_GETLIST(1);
  		nSize = ring_list_getsize(pList);
  		nTimes = (int) RING_API_GETNUMBER(2);
  		if (nTimes < 1) {
  			RING_API_ERROR("Error: The second parameter must be >= 1 \n");
  			return;
  		}
  		for(x = 1 ; x <= nTimes ; x++) 
  			for(y = 1 ; y <= nSize ; y++) 
  				if ( ring_list_isdouble(pList,y) ) 
  					ring_list_adddouble(pList,ring_list_getdouble(pList,y));
  	// Return Output
  		RING_API_RETLIST(pList);
  }
  
  RING_FUNC(ring_generatelist)
  {
  	List *pList;
  	int x,nSize;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 1) {
  			RING_API_ERROR(RING_API_MISS1PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! RING_API_ISNUMBER(1) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Create the List
  		pList = RING_API_NEWLIST;
  	// Generate List Items
  		nSize = (int) RING_API_GETNUMBER(1);
  		if (nSize < 1) {
  			RING_API_ERROR("Error: The list size must be >= 1 \n");
  			return;
  		}
  		for(x = 1 ; x <= nSize ; x++) 
  			ring_list_adddouble(pList,(double) x);
  	// Return Output
  		RING_API_RETLIST(pList);
  }
  
  void mylib_displaylist(List *pList);
  
  RING_FUNC(ring_displaylist)
  {
  	List *pList;
  	// Check Parameters Count
  		if (RING_API_PARACOUNT != 1) {
  			RING_API_ERROR(RING_API_MISS1PARA);
  			return;
  		}
  	// Check Parameters Type
  		if ( ! RING_API_ISPOINTER(1) ) {
  			RING_API_ERROR(RING_API_BADPARATYPE);
  			return;
  		}
  	// Get the List
  		pList = RING_API_GETLIST(1);
  	// Display the List Items including Nested Lists
  		mylib_displaylist(pList);
  }
  
  void mylib_displaylist(List *pList) {
  	int x;
  	for (x=1; x <= ring_list_getsize(pList); x++) {
  		if ( ring_list_isdouble(pList,x) ) {
  			printf("Number : %f \n", ring_list_getdouble(pList,x) ) ;
  		} else if ( ring_list_isstring(pList,x) ) {
  			printf("String : %s \n", ring_list_getstring(pList,x) ) ;
  		} else if ( ring_list_islist(pList,x) ) {
  			printf("Sub List..\n");
  			mylib_displaylist( ring_list_getlist(pList,x) );		
  		}
  	}
  }
  
  RING_API void ringlib_init(RingState *pRingState)
  {
  	ring_vm_funcregister("myfunction",ring_myfunction);
  	ring_vm_funcregister("sumtwonumbers",ring_sumtwonumbers);
  	ring_vm_funcregister("sayhello",ring_sayhello);
  	ring_vm_funcregister("sumlist",ring_sumlist);
  	ring_vm_funcregister("inclist",ring_inclist);
  	ring_vm_funcregister("filterlist",ring_filterlist);
  	ring_vm_funcregister("replicatelist",ring_replicatelist);
  	ring_vm_funcregister("generatelist",ring_generatelist);
  	ring_vm_funcregister("displaylist",ring_displaylist);
  }
  