Skip to content

Commit

Permalink
ReaScript function export: added test, updated "doc"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff0S committed Apr 1, 2015
1 parent 7d1b201 commit ce4b560
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ReaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@
#endif


// Important, keep APIFUNC() as it is defined:
// both scripts reascript_vararg.php and reascript_python.pl parse g_apidefs (see below) to
// generate variable argument wrappers for EEL and Lua (reascript_vararg.h, generated by hand
// at the moment), as well as python wrappers (sws_python.py, automatically generated at compile-time).
// Important, keep APIFUNC() as it is defined: both scripts reascript_vararg.php
// and reascript_python.pl parse g_apidefs to generate variable argument wrappers
// for EEL and Lua (reascript_vararg.h, automatically generated at compilation time
// on OSX), as well as python wrappers (sws_python.py, automatically generated at
// compilation time both on Win & OSX).

#define APIFUNC(x) (void*)x,#x,(void*)__vararg_ ## x,"APIvararg_" #x "","API_" #x "","APIdef_" #x ""

Expand Down Expand Up @@ -100,6 +101,7 @@ APIdef g_apidefs[] =
{ APIFUNC(SNM_test5), "void", "const char*", "a", "", },
{ APIFUNC(SNM_test6), "const char*", "char*", "a", "", }, // not an "Out" parm
{ APIFUNC(SNM_test7), "double", "int,int*,double*,bool*,char*,const char*", "i,aOut,bInOptional,cOutOptional,sOutOptional,csInOptional", "", },
{ APIFUNC(SNM_test8), "const char*", "char*,int,const char*,int,int,char*,int,int*", "buf1,buf1_sz,buf2,buf2_sz,i,buf3,buf3_sz,iOutOptional", "", },
#endif
{ APIFUNC(SNM_CreateFastString), "WDL_FastString*", "const char*", "str", "[S&M] Instantiates a new \"fast string\". You must delete this string, see SNM_DeleteFastString.", },
{ APIFUNC(SNM_DeleteFastString), "void", "WDL_FastString*", "str", "[S&M] Deletes a \"fast string\" instance.", },
Expand Down
20 changes: 20 additions & 0 deletions reascript_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ double SNM_test7(int i, int* a, double* b, bool* c, char* s, const char* cs)
char buf[128]="";
sprintf(buf, "---> %d\r\n", i);
ShowConsoleMsg(buf);
sprintf(buf, "-------------> a = %d\r\n", a?*a:-1);
ShowConsoleMsg(buf);
if (a) *a *= 2;
if (b) *b *= 2.0;
if (c) *c= !(*c);
Expand All @@ -50,3 +52,21 @@ double SNM_test7(int i, int* a, double* b, bool* c, char* s, const char* cs)
ShowConsoleMsg(buf);
return 666.777;
}
const char* SNM_test8(char* buf1, int buf1_sz, const char* buf2, int buf2_sz, int i, char* buf3, int buf3_sz, int* iOptionalOut)
{
char buf[128]="";
sprintf(buf, "---> %s\r\n", buf1);
ShowConsoleMsg(buf);
sprintf(buf, "---> %s\r\n", buf2);
ShowConsoleMsg(buf);
sprintf(buf, "---> %s\r\n", buf3);
ShowConsoleMsg(buf);
sprintf(buf, "---> %d\r\n", i);
ShowConsoleMsg(buf);
if (iOptionalOut) { sprintf(buf, "---> *iOptionalOut = %d\r\n", *iOptionalOut); *iOptionalOut=123456789; }
else strcpy(buf, "---> null iOptionalOut\r\n");
ShowConsoleMsg(buf);
if (buf1) lstrcpyn(buf1,"SNM_test8 new parm val for buf1",buf1_sz);
if (buf3) lstrcpyn(buf3,"SNM_test8 new parm val for buf3",buf3_sz);
return "SNM_test8";
}
5 changes: 5 additions & 0 deletions reascript_vararg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ static void* __vararg_SNM_test7(void** arglist, int numparms)
return p;
}

static void* __vararg_SNM_test8(void** arglist, int numparms)
{
return (void*)(INT_PTR)SNM_test8((char*)arglist[0], (int)(INT_PTR)arglist[1], (const char*)arglist[2], (int)(INT_PTR)arglist[3], (int)(INT_PTR)arglist[4], (char*)arglist[5], (int)(INT_PTR)arglist[6], (int*)arglist[7]);
}

static void* __vararg_SNM_CreateFastString(void** arglist, int numparms)
{
return (void*)(INT_PTR)SNM_CreateFastString((const char*)arglist[0]);
Expand Down

0 comments on commit ce4b560

Please sign in to comment.