aboutsummaryrefslogtreecommitdiff
path: root/jim-array.c
diff options
context:
space:
mode:
authorEvan Hunter <evan@ozhiker.com>2016-10-06 22:19:26 +0100
committerSteve Bennett <steveb@workware.net.au>2016-10-12 09:26:58 +1000
commit80032e22c35eb24d2df11843a723caa7c7160d29 (patch)
treef813e53f67fb094ae43b8be64331e9a35ed523a0 /jim-array.c
parent73176c908b681a9500af84abfa2f7f6234f3f913 (diff)
downloadjimtcl-80032e22c35eb24d2df11843a723caa7c7160d29.zip
jimtcl-80032e22c35eb24d2df11843a723caa7c7160d29.tar.gz
jimtcl-80032e22c35eb24d2df11843a723caa7c7160d29.tar.bz2
Array fixes and tests
Changed 'array exists' to actually check if the variable is an array (matches tclsh) Fix Jim_DictInfo to avoid using printf() and make output match tclsh Added some more tests for array command - checked these work with tclsh
Diffstat (limited to 'jim-array.c')
-rw-r--r--jim-array.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/jim-array.c b/jim-array.c
index 39cd168..cd3e784 100644
--- a/jim-array.c
+++ b/jim-array.c
@@ -54,7 +54,8 @@
static int array_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
/* Just a regular [info exists] */
- Jim_SetResultInt(interp, Jim_GetVariable(interp, argv[0], 0) != 0);
+ Jim_Obj *dictObj = Jim_GetVariable(interp, argv[0], JIM_UNSHARED);
+ Jim_SetResultInt(interp, dictObj && Jim_DictSize(interp, dictObj) != -1);
return JIM_OK;
}
@@ -115,7 +116,9 @@ static int array_cmd_unset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
if (Jim_DictPairs(interp, objPtr, &dictValuesObj, &len) != JIM_OK) {
- return JIM_ERR;
+ /* Variable is not an array - tclsh ignores this and returns nothing - be compatible */
+ Jim_SetResultString(interp, "", -1);
+ return JIM_OK;
}
/* Create a new object with the values which don't match */
@@ -142,7 +145,9 @@ static int array_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (objPtr) {
len = Jim_DictSize(interp, objPtr);
if (len < 0) {
- return JIM_ERR;
+ /* Variable is not an array - tclsh ignores this and returns 0 - be compatible */
+ Jim_SetResultInt(interp, 0);
+ return JIM_OK;
}
}