diff options
author | Tim Potter <tpot@samba.org> | 2005-05-29 03:25:21 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:17:10 -0500 |
commit | e95c8f19116813dd03cce957c3367254782915fd (patch) | |
tree | 444c9efc05b9a3f8ee52db7a2ba3e2e7262a04f9 /source4/scripting/ejs | |
parent | 10f428b6075698205d282c13bc9b1c21f106e165 (diff) | |
download | samba-e95c8f19116813dd03cce957c3367254782915fd.tar.gz samba-e95c8f19116813dd03cce957c3367254782915fd.tar.bz2 samba-e95c8f19116813dd03cce957c3367254782915fd.zip |
r7063: Do error checking on the ejs functions.
Tridge says there is a bug in defining per-engine CFunction's so move
calls to ejsDefineStringCFunction() above the ejsOpenEngine() call.
Test script now works!
(This used to be commit 5e2458ae6c863ff29b85fff3d093f7f4fa9dc2be)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/smbscript.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index f1c3f0b46d..85064d3b44 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -29,9 +29,6 @@ void http_exception(const char *reason) exit(1); } -extern void ejsDefineStringCFunction(EjsId eid, const char *functionName, - MprStringCFunction fn, void *thisPtr, int flags); - static int writeProc(MprVarHandle userHandle, int argc, char **argv) { int i; @@ -50,13 +47,26 @@ static int writeProc(MprVarHandle userHandle, int argc, char **argv) MprVar result; char *emsg; - ejsOpen(0, 0, 0); - eid = ejsOpenEngine(primary, alternate); - ejsDefineStringCFunction(eid, "write", writeProc, NULL, 0); - ejsEvalScript(0, "write(\"hello\n\");", &result, &emsg); - ejsClose(); + if (ejsOpen(0, 0, 0) != 0) { + fprintf(stderr, "smbscript: ejsOpen(): unable to initialise " + "EJ subsystem\n"); + exit(1); + } - printf("emsg = %s\n", emsg); + ejsDefineStringCFunction(-1, "write", writeProc, NULL, 0); + + if ((eid = ejsOpenEngine(primary, alternate)) == (EjsId)-1) { + fprintf(stderr, "smbscript: ejsOpenEngine(): unable to " + "initialise an EJS engine\n"); + exit(1); + } + + if (ejsEvalScript(0, "write(\"hello\n\");", &result, &emsg) == -1) { + fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg); + exit(1); + } + + ejsClose(); return 0; } |