3 #ifndef EELSCRIPT_NO_LICE
17#ifndef EELSCRIPT_MAX_FILE_HANDLES
18#define EELSCRIPT_MAX_FILE_HANDLES 512
20#ifndef EELSCRIPT_FILE_HANDLE_INDEX_BASE
21#define EELSCRIPT_FILE_HANDLE_INDEX_BASE 1000000
23#ifndef EEL_STRING_MAXUSERSTRING_LENGTH_HINT
24#define EEL_STRING_MAXUSERSTRING_LENGTH_HINT (1<<16)
26#ifndef EEL_STRING_MAX_USER_STRINGS
27#define EEL_STRING_MAX_USER_STRINGS 32768
29#ifndef EEL_STRING_LITERAL_BASE
30#define EEL_STRING_LITERAL_BASE 2000000
32#ifndef EELSCRIPT_LICE_MAX_IMAGES
33#define EELSCRIPT_LICE_MAX_IMAGES 1024
36#ifndef EELSCRIPT_LICE_MAX_FONTS
37#define EELSCRIPT_LICE_MAX_FONTS 128
40#ifndef EELSCRIPT_NET_MAXCON
41#define EELSCRIPT_NET_MAXCON 4096
44#ifndef EELSCRIPT_LICE_CLASSNAME
45#define EELSCRIPT_LICE_CLASSNAME "eelscript_gfx"
57#ifndef EELSCRIPT_NO_NET
60#ifndef EELSCRIPT_NO_LICE
73 int runcode(
const char *
code,
int showerr,
const char *showerrfn,
bool canfree,
bool ignoreEndOfInputChk,
bool doExec);
74 int loadfile(
const char *
fn,
const char *callerfn,
bool allowstdin);
80#ifndef EELSCRIPT_NO_FILE
84 if (!*
fn || !*
mode)
return 0.0;
85#ifndef EELSCRIPT_NO_STDIO
86 if (!strcmp(
fn,
"stdin"))
return 1;
87 if (!strcmp(
fn,
"stdout"))
return 2;
88 if (!strcmp(
fn,
"stderr"))
return 3;
91 WDL_FastString fnstr(
fn);
116#ifndef EELSCRIPT_NO_STDIO
117 if (fp_idx==1)
return stdin;
118 if (fp_idx==2)
return stdout;
119 if (fp_idx==3)
return stderr;
133#ifndef EELSCRIPT_NO_NET
136#ifndef EELSCRIPT_NO_LICE
140#ifndef EELSCRIPT_NO_EVAL
168#define EEL_STRING_GET_CONTEXT_POINTER(opaque) (((eelScriptInst *)opaque)->m_string_context)
169#ifndef EEL_STRING_STDOUT_WRITE
170 #ifndef EELSCRIPT_NO_STDIO
171 #define EEL_STRING_STDOUT_WRITE(x,len) { fwrite(x,len,1,stdout); fflush(stdout); }
179#ifndef EELSCRIPT_NO_FILE
180 #define EEL_FILE_OPEN(fn,mode) ((eelScriptInst*)opaque)->OpenFile(fn,mode)
181 #define EEL_FILE_GETFP(fp) ((eelScriptInst*)opaque)->GetFileFP(fp)
182 #define EEL_FILE_CLOSE(fpindex) ((eelScriptInst*)opaque)->CloseFile(fpindex)
187#ifndef EELSCRIPT_NO_FFT
191#ifndef EELSCRIPT_NO_MDCT
195#ifndef EELSCRIPT_NO_NET
196 #define EEL_NET_GET_CONTEXT(opaque) (((eelScriptInst *)opaque)->m_net_state)
200#ifndef EELSCRIPT_NO_LICE
201 #ifndef EEL_LICE_WANT_STANDALONE
202 #define EEL_LICE_WANT_STANDALONE
204 #ifndef EELSCRIPT_LICE_NOUPDATE
205 #define EEL_LICE_WANT_STANDALONE_UPDATE
208 #define EEL_LICE_GET_FILENAME_FOR_STRING(idx, fs, p) (((eelScriptInst*)opaque)->GetFilenameForParameter(idx,fs,p))
209 #define EEL_LICE_GET_CONTEXT(opaque) ((opaque) ? (((eelScriptInst *)opaque)->m_gfx_state) : NULL)
213#ifndef EELSCRIPT_NO_EVAL
214 #define EEL_EVAL_GET_CACHED(str, ch) ((eelScriptInst *)opaque)->evalCacheGet(str,&(ch))
215 #define EEL_EVAL_SET_CACHED(str, ch) ((eelScriptInst *)opaque)->evalCacheDispose(str,ch)
216 #define EEL_EVAL_GET_VMCTX(opaque) (((eelScriptInst *)opaque)->m_vm)
217 #define EEL_EVAL_SCOPE_ENTER (((eelScriptInst *)opaque)->m_eval_depth < 3 ? \
218 ++((eelScriptInst *)opaque)->m_eval_depth : 0)
219 #define EEL_EVAL_SCOPE_LEAVE ((eelScriptInst *)opaque)->m_eval_depth--;
234#ifdef EEL_STRING_DEBUGOUT
235 EEL_STRING_DEBUGOUT(
"defer(): too much defer() code already added, ignoring");
238#ifdef EEL_STRING_DEBUGOUT
241 EEL_STRING_DEBUGOUT(
"defer(): invalid string identifier specified %f",*
s);
245 EEL_STRING_DEBUGOUT(
"defer(): user string identifier %f specified but not allowed",*
s);
262#ifdef EEL_STRING_DEBUGOUT
263 EEL_STRING_DEBUGOUT(
"atexit(): too much atexit() code already added, ignoring");
266#ifdef EEL_STRING_DEBUGOUT
269 EEL_STRING_DEBUGOUT(
"atexit(): invalid string identifier specified %f",*
s);
273 EEL_STRING_DEBUGOUT(
"atexit(): user string identifier %f specified but not allowed",*
s);
281#define opaque ((void *)this)
285#ifndef EELSCRIPT_NO_FILE
289#ifdef EEL_STRING_DEBUGOUT
290 if (!
m_vm) EEL_STRING_DEBUGOUT(
"NSEEL_VM_alloc(): failed");
293#ifdef NSEEL_ADDFUNC_DESTINATION
299#ifndef EELSCRIPT_NO_NET
302#ifndef EELSCRIPT_NO_LICE
307#ifndef EELSCRIPT_NO_EVAL
314#ifndef EELSCRIPT_NO_EVAL
319#ifndef EELSCRIPT_NO_EVAL
329#ifndef EELSCRIPT_NO_FILE
337#ifndef EELSCRIPT_NO_NET
340#ifndef EELSCRIPT_NO_LICE
348 if (!
fmt)
return false;
357 *err =
"EEL VM not initialized";
371int eelScriptInst::runcode(
const char *codeptr,
int showerr,
const char *showerrfn,
bool canfree,
bool ignoreEndOfInputChk,
bool doExec)
384#ifdef EEL_STRING_DEBUGOUT
401#ifdef EELSCRIPT_DO_DISASSEMBLE
408 lstrcatn(buf,
"jsfx-out",
sizeof(buf));
415 fwrite(
p->code,1,
p->code_size,fp);
419 snprintf(buf2,
sizeof(buf2),
"disasm \"%s\"",buf);
422 snprintf(buf2,
sizeof(buf2),
"objdump -D -b binary -maarch64 \"%s\"",buf);
423 #elif defined(__arm__)
424 snprintf(buf2,
sizeof(buf2),
"objdump -D -b binary -m arm \"%s\"",buf);
425 #elif defined(__LP64__)
427 snprintf(buf2,
sizeof(buf2),
"distorm3 --b64 \"%s\"",buf);
429 snprintf(buf2,
sizeof(buf2),
"objdump -D -b binary -m i386:x86-64 \"%s\"",buf);
432 snprintf(buf2,
sizeof(buf2),
"distorm3 --b32 \"%s\"",buf);
458 if (!
x && ((
fn[0] ==
'\\' &&
fn[1] ==
'\\') || (
fn[0] &&
fn[1] ==
':')))
460 if (!
x &&
fn[0] ==
'/')
468 const char *fnu =
fn;
472 while (fnu >=
fn && *fnu !=
'\\' && *fnu !=
'/') fnu--;
478 int l=usefn.GetLength();
479 while (
l > 0 && usefn.Get()[
l-1] !=
'\\' && usefn.Get()[
l-1] !=
'/')
l--;
489 int last_slash_pos=-1;
490 for (
l = 0;
l < usefn.GetLength();
l ++)
492 if (usefn.Get()[
l] ==
'/' || usefn.Get()[
l] ==
'\\')
494 if (usefn.Get()[
l+1] ==
'.' && usefn.Get()[
l+2] ==
'.' &&
495 (usefn.Get()[
l+3] ==
'/' || usefn.Get()[
l+3] ==
'\\'))
497 if (last_slash_pos >= 0)
498 usefn.DeleteSub(last_slash_pos,
l+3-last_slash_pos);
500 usefn.DeleteSub(0,
l+3+1);
514 if (had_abs) usefn.Set(
fn);
520 WDL_FastString usefn;
526#ifdef EEL_STRING_DEBUGOUT
527 EEL_STRING_DEBUGOUT(
"@import: can't import \"-\" (stdin)");
559#ifdef EEL_STRING_DEBUGOUT
561 EEL_STRING_DEBUGOUT(
"Warning: @import could not open '%s'",
fn);
563 EEL_STRING_DEBUGOUT(
"Error opening %s",
fn);
573 fgets(line,
sizeof(line),fp);
575 if (!
strnicmp(line,
"@import",7) && isspace((
unsigned char)line[7]))
578 while (isspace((
unsigned char)*
p))
p++;
582 while (ep>
p && isspace((
unsigned char)ep[-1])) ep--;
592 if (fp != stdin) fclose(fp);
594 return runcode(
code.Get(),callerfn ? 2 : 1,
fn,
false,
true,!callerfn);
632#ifndef EELSCRIPT_NO_FILE
635#ifndef EELSCRIPT_NO_FFT
638#ifndef EELSCRIPT_NO_MDCT
642#ifndef EELSCRIPT_NO_EVAL
648#ifndef EELSCRIPT_NO_NET
651#ifndef EELSCRIPT_NO_LICE
664#ifndef EELSCRIPT_NO_EVAL
671#ifndef EELSCRIPT_NO_EVAL
674 const int endptr =
q->Available();
676 while (offs < endptr)
678 if (
q->Available() < endptr)
break;
680 const char *ptr = (
const char *)
q->Get() + offs;
681 offs += strlen(ptr)+1;
686 if (!sv) sv=strdup(ptr);
691#ifdef EEL_STRING_DEBUGOUT
693 if (err) EEL_STRING_DEBUGOUT(
"%s: error in code: %s",callername,err);
708#ifndef EELSCRIPT_NO_EVAL
719#ifdef EEL_WANT_DOCUMENTATION
725 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
726 p = eel_strings_function_reference;
727 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
728 p = eel_misc_function_reference;
729 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
730#ifndef EELSCRIPT_NO_EVAL
731 fs->
Add(
"atexit\t\"code\"\t"
732#ifndef EELSCRIPT_HELP_NO_DEFER_DESC
733 "Adds code to be executed when the script finishes."
736 fs->
Add(
"defer\t\"code\"\t"
737#ifndef EELSCRIPT_HELP_NO_DEFER_DESC
738 "Adds code which will be executed some small amount of time after the current code finishes. Identical to runloop()"
741 fs->
Add(
"runloop\t\"code\"\t"
742#ifndef EELSCRIPT_HELP_NO_DEFER_DESC
743 "Adds code which will be executed some small amount of time after the current code finishes. Identical to defer()"
747 p = eel_eval_function_reference;
748 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
750#ifndef EELSCRIPT_NO_NET
751 p = eel_net_function_reference;
752 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
754#ifndef EELSCRIPT_NO_FFT
755 p = eel_fft_function_reference;
756 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
758#ifndef EELSCRIPT_NO_FILE
759 p = eel_file_function_reference;
760 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
762#ifndef EELSCRIPT_NO_MDCT
763 p = eel_mdct_function_reference;
764 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
766#ifndef EELSCRIPT_NO_LICE
767 p = eel_lice_function_reference;
768 while (*
p) { fs->
Add(
p);
p += strlen(
p) + 1; }
PTRTYPE * Add(PTRTYPE *item)
Definition ptrlist.h:82
void * Add(const void *buf, int len)
Definition queue.h:52
int Available() const
Definition queue.h:96
Definition assocarray.h:376
Definition eel_lice.h:190
Definition eel_strings.h:122
Definition eelscript.h:64
WDL_Queue m_atexit_eval
Definition eelscript.h:149
NSEEL_CODEHANDLE compile_code(const char *code, const char **err)
Definition eelscript.h:353
FILE * m_handles[EELSCRIPT_MAX_FILE_HANDLES]
Definition eelscript.h:81
virtual void evalCacheDispose(char *key, NSEEL_CODEHANDLE ch)
Definition eelscript.h:614
void runCodeQ(WDL_Queue *q, const char *fname)
Definition eelscript.h:672
eelScriptInst()
Definition eelscript.h:283
WDL_PtrList< void > m_code_freelist
Definition eelscript.h:78
WDL_TypedBuf< evalCacheEnt > m_eval_cache
Definition eelscript.h:146
virtual EEL_F CloseFile(int fp_idx)
Definition eelscript.h:103
virtual bool translateFilename(WDL_FastString *fs, const char *mode)
Definition eelscript.h:128
virtual EEL_F OpenFile(const char *fn, const char *mode)
Definition eelscript.h:82
virtual char * evalCacheGet(const char *str, NSEEL_CODEHANDLE *ch)
Definition eelscript.h:597
virtual bool GetFilenameForParameter(EEL_F idx, WDL_FastString *fs, int iswrite)
Definition eelscript.h:345
eel_lice_state * m_gfx_state
Definition eelscript.h:137
virtual FILE * GetFileFP(int fp_idx)
Definition eelscript.h:114
WDL_Queue m_defer_eval
Definition eelscript.h:149
virtual bool run_deferred()
Definition eelscript.h:706
WDL_StringKeyedArray< bool > m_loaded_fnlist
Definition eelscript.h:161
int runcode(const char *code, int showerr, const char *showerrfn, bool canfree, bool ignoreEndOfInputChk, bool doExec)
Definition eelscript.h:371
eel_net_state * m_net_state
Definition eelscript.h:134
virtual ~eelScriptInst()
Definition eelscript.h:312
int m_eval_depth
Definition eelscript.h:145
virtual bool has_deferred()
Definition eelscript.h:662
eel_string_context_state * m_string_context
Definition eelscript.h:132
void runAtExitCode()
Definition eelscript.h:151
int loadfile(const char *fn, const char *callerfn, bool allowstdin)
Definition eelscript.h:518
NSEEL_VMCTX m_vm
Definition eelscript.h:76
static int init()
Definition eelscript.h:629
int * l
Definition inflate.c:1579
unsigned s
Definition inflate.c:1555
unsigned x[BMAX+1]
Definition inflate.c:1586
void EEL_eval_register()
Definition eel_eval.h:70
void EEL_fft_register()
Definition eel_fft.h:359
void EEL_file_register()
Definition eel_files.h:227
void(* NSEEL_VM_free)(NSEEL_VMCTX ctx)
Definition eel_import.h:11
NSEEL_CODEHANDLE(* NSEEL_code_compile_ex)(NSEEL_VMCTX ctx, const char *code, int lineoffs, int flags)
Definition eel_import.h:16
void(* NSEEL_code_free)(NSEEL_CODEHANDLE code)
Definition eel_import.h:20
void(* NSEEL_code_execute)(NSEEL_CODEHANDLE code)
Definition eel_import.h:19
#define NSEEL_addfunc_retval(name, np, pproc, fptr)
Definition eel_import.h:51
#define NSEEL_ADDFUNC_DESTINATION
Definition eel_import.h:47
NSEEL_VMCTX(* NSEEL_VM_alloc)()
Definition eel_import.h:9
char *(* NSEEL_code_getcodeerror)(NSEEL_VMCTX ctx)
Definition eel_import.h:18
void *(* NSEEL_PProc_THIS)(void *data, int data_size, struct _compileContext *ctx)
Definition eel_import.h:40
void(* NSEEL_VM_SetFunctionTable)(NSEEL_VMCTX, eel_function_table *tab)
Definition eel_import.h:12
void(* NSEEL_VM_SetCustomFuncThis)(NSEEL_VMCTX ctx, void *thisptr)
Definition eel_import.h:15
void eel_lice_register()
Definition eel_lice.h:1913
void EEL_mdct_register()
Definition eel_mdct.h:768
void EEL_misc_register()
Definition eel_misc.h:55
void EEL_tcp_register()
Definition eel_net.h:539
void EEL_string_register()
Definition eel_strings.h:1540
void eel_string_initvm(NSEEL_VMCTX vm)
Definition eel_strings.h:1573
#define EEL_STRING_GET_FOR_INDEX(x, wr)
Definition eel_strings.h:96
#define EEL_STRING_MAX_USER_STRINGS
Definition eel_strings.h:66
#define EEL_STRING_MUTEXLOCK_SCOPE
Definition eel_strings.h:90
static EEL_F NSEEL_CGEN_CALL _eel_defer(void *opaque, EEL_F *s)
Definition eelscript.h:222
#define opaque
Definition eelscript.h:281
#define EELSCRIPT_LICE_CLASSNAME
Definition eelscript.h:45
#define EELSCRIPT_FILE_HANDLE_INDEX_BASE
Definition eelscript.h:21
#define EELSCRIPT_NET_MAXCON
Definition eelscript.h:41
#define EELSCRIPT_MAX_FILE_HANDLES
Definition eelscript.h:18
FILE * eelscript_resolvePath(WDL_FastString &usefn, const char *fn, const char *callerfn)
Definition eelscript.h:450
static EEL_F NSEEL_CGEN_CALL _eel_atexit(void *opaque, EEL_F *s)
Definition eelscript.h:250
#define EELSCRIPT_LICE_MAX_IMAGES
Definition eelscript.h:33
#define EELSCRIPT_LICE_MAX_FONTS
Definition eelscript.h:37
const char * nseel_builtin_function_reference
Definition ns-eel-func-ref.h:8
#define NSEEL_CGEN_CALL
Definition ns-eel.h:44
int NSEEL_code_geterror_flag(NSEEL_VMCTX ctx)
Definition nseel-compiler.c:5218
void * NSEEL_VMCTX
Definition ns-eel.h:117
void * NSEEL_CODEHANDLE
Definition ns-eel.h:118
NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX ctx, const char *code, int lineoffs)
Definition nseel-compiler.c:4514
#define NSEEL_CODE_COMPILE_FLAG_COMMONFUNCS
Definition ns-eel.h:174
#define false
Definition ordinals.h:83
png_structrp int mode
Definition png.h:1139
Definition ns-eel-int.h:146
Definition eelscript.h:141
NSEEL_CODEHANDLE ch
Definition eelscript.h:143
char * str
Definition eelscript.h:142
const char const char const char const char char * fn
Definition swell-functions.h:168
#define strnicmp(x, y, z)
Definition swell-types.h:71
void GetTempPath(int bufsz, char *buf)
Definition swell.cpp:1063
uch * p
Definition crypt.c:594
ZCONST char * key
Definition crypt.c:587
fmt[0]
Definition fileio.c:2503
register uch * q
Definition fileio.c:817
_WDL_CSTRING_PREFIX const char * WDL_get_filepart(const char *str)
Definition wdlcstring.h:148
_WDL_CSTRING_PREFIX void lstrcpyn_safe(char *o, const char *in, INT_PTR count)
Definition wdlcstring.h:129
_WDL_CSTRING_PREFIX void lstrcatn(char *o, const char *in, INT_PTR count)
Definition wdlcstring.h:138
#define fopenUTF8
Definition win32_utf8.h:280
#define EEL_STRING_MAXUSERSTRING_LENGTH_HINT
Definition ysfx_api_eel.cpp:35