Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Jim_EvalSource() to replace Jim_Eval_Named()

Since the line number should correspond to the first
line of the script, it is easier to use with __LINE__
if the filename and line number are before the script.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
commit 1669335e1c8aa6a2374cc3796c6d9d471becae82 1 parent 3a8ccfd
Steve Bennett authored
Showing with 11 additions and 10 deletions.
  1. +3 −4 jim.c
  2. +5 −2 jim.h
  3. +2 −3 make-bootstrap-jim
  4. +1 −1  make-c-ext.tcl
7 jim.c
View
@@ -9886,7 +9886,7 @@ int Jim_EvalObj(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
/* If the object is of type "list", we can call
* a specialized version of Jim_EvalObj() */
if (Jim_IsList(scriptObjPtr)) {
- return JimEvalObjList(interp, scriptObjPtr, NULL, 0);
+ return JimEvalObjList(interp, scriptObjPtr, interp->emptyObj, 1);
}
Jim_IncrRefCount(scriptObjPtr); /* Make sure it's shared. */
@@ -10306,7 +10306,7 @@ static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, Jim_Obj *fileNameO
return retcode;
}
-int Jim_Eval_Named(Jim_Interp *interp, const char *script, const char *filename, int lineno)
+int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script)
{
int retval;
Jim_Obj *scriptObjPtr;
@@ -10314,7 +10314,6 @@ int Jim_Eval_Named(Jim_Interp *interp, const char *script, const char *filename,
scriptObjPtr = Jim_NewStringObj(interp, script, -1);
Jim_IncrRefCount(scriptObjPtr);
-
if (filename) {
Jim_Obj *prevScriptObj;
@@ -10336,7 +10335,7 @@ int Jim_Eval_Named(Jim_Interp *interp, const char *script, const char *filename,
int Jim_Eval(Jim_Interp *interp, const char *script)
{
- return Jim_Eval_Named(interp, script, NULL, 0);
+ return Jim_EvalObj(interp, Jim_NewStringObj(interp, script, -1));
}
/* Execute script in the scope of the global level */
7 jim.h
View
@@ -636,8 +636,11 @@ JIM_EXPORT void Jim_SetEnviron(char **env);
/* evaluation */
JIM_EXPORT int Jim_Eval(Jim_Interp *interp, const char *script);
/* in C code, you can do this and get better error messages */
-/* Jim_Eval_Named( interp, "some tcl commands", __FILE__, __LINE__ ); */
-JIM_EXPORT int Jim_Eval_Named(Jim_Interp *interp, const char *script,const char *filename, int lineno);
+/* Jim_EvalSource( interp, __FILE__, __LINE__ , "some tcl commands"); */
+JIM_EXPORT int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script);
+/* Backwards compatibility */
+#define Jim_Eval_Named(I, S, F, L) Jim_EvalSource((I), (F), (L), (S))
+
JIM_EXPORT int Jim_EvalGlobal(Jim_Interp *interp, const char *script);
JIM_EXPORT int Jim_EvalFile(Jim_Interp *interp, const char *filename);
JIM_EXPORT int Jim_EvalFileGlobal(Jim_Interp *interp, const char *filename);
5 make-bootstrap-jim
View
@@ -14,14 +14,13 @@ int Jim_${basename}Init(Jim_Interp *interp)
if (Jim_PackageProvide(interp, "$basename", "1.0", JIM_ERRMSG))
return JIM_ERR;
- return Jim_Eval_Named(interp,
+ return Jim_EvalSource(interp, \"$source\", 1,
EOF
# Note: Keep newlines so that line numbers match in error messages
sed -e 's/^[ ]*#.*//' -e 's@\\@\\\\@g' -e 's@"@\\"@g' -e 's@^\(.*\)$@"\1\\n"@' $source
-#sed -e 's@^\(.*\)$@"\1\\n"@' $source
-echo ",\"$source\", 1);"
+echo ");"
echo "}"
}
2  make-c-ext.tcl
View
@@ -32,7 +32,7 @@ set pkgname [file rootname $basename]
lappend lines "int Jim_${pkgname}Init(Jim_Interp *interp)"
lappend lines "\{"
lappend lines "\tif (Jim_PackageProvide(interp, \"$pkgname\", \"1.0\", JIM_ERRMSG)) return JIM_ERR;"
-lappend lines "\treturn Jim_Eval_Named(interp, [join $sourcelines \n], \"$basename\", 1);"
+lappend lines "\treturn Jim_EvalSource(interp, \"$basename\", 1, [join $sourcelines \n]);"
lappend lines "\}"
puts [join $lines \n]
Please sign in to comment.
Something went wrong with that request. Please try again.