8 int g_verbose
, g_interactive
;
10 static void writeToStandardError(const char *fmt
, ...)
13 va_start(arglist
, fmt
);
14 vfprintf(stderr
,fmt
,arglist
);
19 #define EEL_STRING_DEBUGOUT writeToStandardError // no parameters, since it takes varargs
21 #ifndef EEL_LICE_WANT_STANDALONE
22 #define EELSCRIPT_NO_LICE
25 #include "eelscript.h"
28 void NSEEL_HOSTSTUB_EnterMutex() { }
29 void NSEEL_HOSTSTUB_LeaveMutex() { }
32 int main(int argc
, char **argv
)
34 bool want_args
= true;
36 const char *scriptfn
= argv
[0];
37 while (argpos
< argc
&& argv
[argpos
][0] == '-' && argv
[argpos
][1])
39 if (!strcmp(argv
[argpos
],"-v")) g_verbose
++;
40 else if (!strcmp(argv
[argpos
],"-i")) g_interactive
++;
41 else if (!strcmp(argv
[argpos
],"--no-args")) want_args
=false;
44 fprintf(stderr
,"Usage: %s [-v] [--no-args] [-i | scriptfile | -]\n",argv
[0]);
49 if (argpos
< argc
&& !g_interactive
)
51 scriptfn
= argv
[argpos
++];
56 if (!g_interactive
&& isatty(0))
63 if (eelScriptInst::init())
65 fprintf(stderr
,"NSEEL_init(): error initializing\n");
70 #ifndef EELSCRIPT_NO_LICE
72 SWELL_InitAutoRelease();
76 WDL_FastString code
,t
;
81 #ifndef EELSCRIPT_DO_DISASSEMBLE
82 const int argv_offs
= 1<<22;
83 code
.SetFormatted(64,"argc=0; argv=%d;\n",argv_offs
);
85 for (x
=argpos
-1;x
<argc
;x
++)
87 code
.AppendFormatted(64,"argv[argc]=%d; argc+=1;\n",
88 inst
.m_string_context
->AddString(new WDL_FastString(x
<argpos
? scriptfn
: argv
[x
])));
90 inst
.runcode(code
.Get(),2,"__cmdline__",true,true,true);
96 #ifndef EELSCRIPT_NO_LICE
97 if (inst
.m_gfx_state
&& inst
.m_gfx_state
->m_gfx_clear
) inst
.m_gfx_state
->m_gfx_clear
[0] = -1;
100 printf("EEL interactive mode, type quit to quit, abort to abort multiline entry\n");
101 EEL_F
*resultVar
= NSEEL_VM_regvar(inst
.m_vm
,"__result");
106 #ifndef EELSCRIPT_NO_LICE
107 _gfx_update(&inst
,NULL
);
109 if (!code
.Get()[0]) printf("EEL> ");
113 fgets(line
,sizeof(line
),stdin
);
117 line
[strlen(line
)-1] == '\r' ||
118 line
[strlen(line
)-1] == '\n' ||
119 line
[strlen(line
)-1] == '\t' ||
120 line
[strlen(line
)-1] == ' '
121 )) line
[strlen(line
)-1]=0;
123 if (!strcmp(line
,"quit")) break;
124 if (!strcmp(line
,"abort")) code
.Set("");
126 #ifndef EELSCRIPT_DO_DISASSEMBLE
127 t
.Set("__result = (");
131 t
.Append(code
.Get());
132 #ifndef EELSCRIPT_DO_DISASSEMBLE
135 int res
=inst
.runcode(t
.Get(),false,"",true,true,true); // allow free, since functions can't be defined locally
138 if (resultVar
) printf("=%g ",*resultVar
);
141 else // try compiling again allowing function definitions (and not allowing free)
142 // but show errors if not continuation
144 res
=inst
.runcode(code
.Get(),true,"(stdin)", false,false,true);
145 if (res
<=0) code
.Set("");
146 // res>0 means need more lines
148 while (inst
.run_deferred());
153 inst
.loadfile(scriptfn
,NULL
,true);
154 while (inst
.run_deferred());
161 INT_PTR
SWELLAppMain(int msg
, INT_PTR parm1
, INT_PTR parm2
)