ns-eel.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. Nullsoft Expression Evaluator Library (NS-EEL)
  3. Copyright (C) 1999-2003 Nullsoft, Inc.
  4. ns-eel.h: main application interface header
  5. This software is provided 'as-is', without any express or implied
  6. warranty. In no event will the authors be held liable for any damages
  7. arising from the use of this software.
  8. Permission is granted to anyone to use this software for any purpose,
  9. including commercial applications, and to alter it and redistribute it
  10. freely, subject to the following restrictions:
  11. 1. The origin of this software must not be misrepresented; you must not
  12. claim that you wrote the original software. If you use this software
  13. in a product, an acknowledgment in the product documentation would be
  14. appreciated but is not required.
  15. 2. Altered source versions must be plainly marked as such, and must not be
  16. misrepresented as being the original software.
  17. 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #ifndef __NS_EEL_H__
  20. #define __NS_EEL_H__
  21. // put standard includes here
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #ifdef _MSC_VER
  25. #define strcasecmp stricmp
  26. #define strncasecmp _strnicmp
  27. #endif
  28. #ifndef EEL_F_SIZE
  29. #define EEL_F_SIZE 8
  30. #endif
  31. #if EEL_F_SIZE == 4
  32. typedef float EEL_F;
  33. #else
  34. typedef double EEL_F;
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. // host should implement these (can be empty stub functions if no VM will execute code in multiple threads at once)
  40. // implement if you will be running the code in same VM from multiple threads,
  41. // or VMs that have the same GRAM pointer from different threads, or multiple
  42. // VMs that have a NULL GRAM pointer from multiple threads.
  43. // if you give each VM it's own unique GRAM and only run each VM in one thread, then you can leave it blank.
  44. // or if you're daring....
  45. void NSEEL_HOSTSTUB_EnterMutex();
  46. void NSEEL_HOSTSTUB_LeaveMutex();
  47. int NSEEL_init(); // returns 0 on success. clears any added functions as well
  48. #define NSEEL_addfunction(name,nparms,code,len) NSEEL_addfunctionex((name),(nparms),(code),(len),0,0)
  49. #define NSEEL_addfunctionex(name,nparms,code,len,pproc,fptr) NSEEL_addfunctionex2((name),(nparms),(code),(len),(pproc),(fptr),0)
  50. void NSEEL_addfunctionex2(const char *name, int nparms, char *code_startaddr, int code_len, void *pproc, void *fptr, void *fptr2);
  51. void NSEEL_quit();
  52. int *NSEEL_getstats(); // returns a pointer to 5 ints... source bytes, static code bytes, call code bytes, data bytes, number of code handles
  53. EEL_F *NSEEL_getglobalregs();
  54. typedef void *NSEEL_VMCTX;
  55. typedef void *NSEEL_CODEHANDLE;
  56. NSEEL_VMCTX NSEEL_VM_alloc(); // return a handle
  57. void NSEEL_VM_free(NSEEL_VMCTX ctx); // free when done with a VM and ALL of its code have been freed, as well
  58. void NSEEL_VM_enumallvars(NSEEL_VMCTX ctx, int (*func)(const char *name, EEL_F *val, void *ctx), void *userctx); // return false from func to stop
  59. void NSEEL_VM_resetvars(NSEEL_VMCTX ctx); // clears all vars to 0.0.
  60. EEL_F *NSEEL_VM_regvar(NSEEL_VMCTX ctx, const char *name); // register a variable (before compilation)
  61. void NSEEL_VM_freeRAM(NSEEL_VMCTX ctx); // clears and frees all (VM) RAM used
  62. void NSEEL_VM_freeRAMIfCodeRequested(NSEEL_VMCTX); // call after code to free the script-requested memory
  63. int NSEEL_VM_wantfreeRAM(NSEEL_VMCTX ctx); // want NSEEL_VM_freeRAMIfCodeRequested?
  64. // if you set this, it uses a local GMEM context.
  65. // Must be set before compilation.
  66. // void *p=NULL;
  67. // NSEEL_VM_SetGRAM(ctx,&p);
  68. // .. do stuff
  69. // NSEEL_VM_FreeGRAM(&p);
  70. void NSEEL_VM_SetGRAM(NSEEL_VMCTX ctx, void **gram);
  71. void NSEEL_VM_FreeGRAM(void **ufd); // frees a gmem context.
  72. void NSEEL_VM_SetCustomFuncThis(NSEEL_VMCTX ctx, void *thisptr);
  73. // note that you shouldnt pass a C string directly, since it may need to
  74. // fudge with the string during the compilation (it will always restore it to the
  75. // original value though).
  76. #ifdef __cplusplus
  77. NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX ctx, char *code, int lineoffs=0);
  78. #else
  79. NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX ctx, char *code, int lineoffs);
  80. #endif
  81. char *NSEEL_code_getcodeerror(NSEEL_VMCTX ctx);
  82. void NSEEL_code_execute(NSEEL_CODEHANDLE code);
  83. void NSEEL_code_free(NSEEL_CODEHANDLE code);
  84. int *NSEEL_code_getstats(NSEEL_CODEHANDLE code); // 4 ints...source bytes, static code bytes, call code bytes, data bytes
  85. // global memory control/view
  86. extern unsigned int NSEEL_RAM_limitmem; // if nonzero, memory limit for user data, in bytes
  87. extern unsigned int NSEEL_RAM_memused;
  88. extern int NSEEL_RAM_memused_errors;
  89. // configuration:
  90. #define NSEEL_MAX_VARIABLE_NAMELEN 16
  91. // define this to override the max variable length (default is 16 bytes)
  92. //#define NSEEL_MAX_TEMPSPACE_ENTRIES 2048
  93. // define this to override the maximum working space in 8 byte units.
  94. // 2048 is the default, and is way more than enough for most applications
  95. // but in theory you might be able to come up with an expression big enough? maybe?
  96. // maximum loop length
  97. #define NSEEL_LOOPFUNC_SUPPORT_MAXLEN 1048576 // scary, we can do a million entries. probably will never want to, though.
  98. #define NSEEL_LOOPFUNC_SUPPORT_MAXLEN_STR "1048576"
  99. // when a VM ctx doesn't have a GRAM context set, make the global one this big
  100. #define NSEEL_SHARED_GRAM_SIZE (1<<20)
  101. // 128*65536 = ~8million entries. (64MB RAM used)
  102. #define NSEEL_RAM_BLOCKS 128
  103. #define NSEEL_RAM_ITEMSPERBLOCK 65536
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif//__NS_EEL_H__