Developers Jos Posted October 1, 2018 Developers Share Posted October 1, 2018 Made another upload available adding Json_ObjGetItems(), Tidied source and fixed au3check warnings. Also updated json-test.au3 a bit. Thanks,Jos argumentum 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
DerPensionist Posted October 28, 2018 Share Posted October 28, 2018 Please provide changes in JSON(2018.10.01b).zip Member JSON.au3 Line 512 old: Quote Local $sObjPath = $ObjPath Line 512 new Quote Local §Value, $sObjPath = $ObjPath or add "Local" to Line 515 to avoid Message: Quote C:\Program Files (x86)\AutoIt3\Include_User\JSON.au3" (515) : ==> Variable used without being declared.: ======================================== Member Json_Test.au3 . to prettify Lines 29 & 30 are part of "Test2", change "Test3" to "Test2" thx Link to comment Share on other sites More sharing options...
Developers Jos Posted October 28, 2018 Developers Share Posted October 28, 2018 (edited) 1 hour ago, DerPensionist said: Quote Local §Value, $sObjPath = $ObjPath I guess you mean an $ sign there in stead of the § Will add that for avoiding the au3check warning and update the zipfile. Thanks,Jos Edited October 28, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 (edited) hi guys, It's a been a long time since i use to pass json as parameter to my functions, really cool to add new parameter without changing code that much. Each time i use the same variable $jsonfunc, so in many function i do: If Json_IsObject($jsonfunc) Then Json_ObjClear($jsonfunc) Else $jsonfunc = Json_ObjCreate() EndIf and next, i add parameter and all is ok, i call my functions with $jsonfunc as parameter And this is ok. Today i encounter a really simple problem, that you can reproduce with the code below: I just pass a json (jsonfunc) as a parameter to myfunc(), in the function, the parameter is $jsonparam. But if i do Json_ObjClear($jsonfunc) My $jsonparam is cleared. why ?? #include <Json.au3> local $jsonfunc Func myfunc($jsonparam) ConsoleWrite("we're in myfunc" & @CRLF) If Not Json_IsObject($jsonparam) Then ConsoleWrite("$jsonparam is not an object, leaving." & @CRLF) Return Else ConsoleWrite("$jsonparam is an object OK." & @CRLF) EndIf If Json_IsObject($jsonfunc) Then ConsoleWrite("$jsonparam, before clear the $jsonfunc:" & @CRLF & Json_Encode($jsonparam, $Json_PRETTY_PRINT) & @CRLF & @CRLF) Json_ObjClear($jsonfunc) ConsoleWrite("$jsonparam, after clear the $jsonfunc:" & @CRLF & Json_Encode($jsonparam, $Json_PRETTY_PRINT) & @CRLF) Else $jsonfunc = Json_ObjCreate() EndIf EndFunc If Json_IsObject($jsonfunc) Then Json_ObjClear($jsonfunc) Else $jsonfunc = Json_ObjCreate() EndIf Json_ObjPut($jsonfunc, "TRI", "1_Niveau_") Json_ObjPut($jsonfunc, "JSON_ORIGINEL", 1) ConsoleWrite("we call function with a json ($jsonfunc) as parameter" & @CRLF) myfunc($jsonfunc) Spoiler Output: we call function with a json ($jsonfunc) as parameter we're in myfunc $jsonparam is an object OK. $jsonparam, before clear the $jsonfunc: { "TRI": "1_Niveau_", "JSON_ORIGINEL": 1 } $jsonparam, after clear the $jsonfunc: {} any idea ? thanks. Nicolas. Edit: it is the same with last version of Json from 2018/10/28 and one from more than a year. Edited October 29, 2018 by satanico64 Link to comment Share on other sites More sharing options...
TheXman Posted October 29, 2018 Share Posted October 29, 2018 (edited) @satanico64 You appear to have a problem with the scope of the $jsonfunc variable. What happens when you run the snippet below? It works for me. All I did was change the "Local" to "Global" #include <myincludes\json\Json.au3> global $jsonfunc Func myfunc($jsonparam) ConsoleWrite("we're in myfunc" & @CRLF) If Not Json_IsObject($jsonparam) Then ConsoleWrite("$jsonparam is not an object, leaving." & @CRLF) Return Else ConsoleWrite("$jsonparam is an object OK." & @CRLF) EndIf If Json_IsObject($jsonfunc) Then ConsoleWrite("$jsonparam, before clear the $jsonfunc:" & @CRLF & Json_Encode($jsonparam, $Json_PRETTY_PRINT) & @CRLF & @CRLF) Json_ObjClear($jsonfunc) ConsoleWrite("$jsonparam, after clear the $jsonfunc:" & @CRLF & Json_Encode($jsonparam, $Json_PRETTY_PRINT) & @CRLF) Else $jsonfunc = Json_ObjCreate() EndIf EndFunc If Json_IsObject($jsonfunc) Then Json_ObjClear($jsonfunc) Else $jsonfunc = Json_ObjCreate() EndIf Json_ObjPut($jsonfunc, "TRI", "1_Niveau_") Json_ObjPut($jsonfunc, "JSON_ORIGINEL", 1) ConsoleWrite("we call function with a json ($jsonfunc) as parameter" & @CRLF) myfunc($jsonfunc) Result: we call function with a json ($jsonfunc) as parameter we're in myfunc $jsonparam is an object OK. $jsonparam, before clear the $jsonfunc: { "TRI": "1_Niveau_", "JSON_ORIGINEL": 1 } $jsonparam, after clear the $jsonfunc: {} Edited October 29, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 I thought about the scope too, and tried that before, it does'not change anything. Sames conclusions for you ? Meanwhile, there is none reason to reset my function parameter, without calling it explicitely Link to comment Share on other sites More sharing options...
TheXman Posted October 29, 2018 Share Posted October 29, 2018 I added my result to my post. As I said, it worked for me. Did you run the exact snippet or some other code? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 in your result, the json is cleared too after the objclear Quote $jsonparam, after clear the $jsonfunc: {} Link to comment Share on other sites More sharing options...
TheXman Posted October 29, 2018 Share Posted October 29, 2018 What result are you expecting after the json_objclear()? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 I clear a json which name is $jsonfunc, because i want to use it later. I clearly do not expect that my other json $jsonparam to be cleared. Link to comment Share on other sites More sharing options...
TheXman Posted October 29, 2018 Share Posted October 29, 2018 Oh, okay, I see what you are saying now. Let me take a closer look. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
TheXman Posted October 29, 2018 Share Posted October 29, 2018 I'm not exactly sure how AutoIt works in this regard without testing it, but in other languages, objects are passed ByRef. Therefore, if the same holds true you aren't using a copy of the $jsonfunc object in myfunc(), you are using/manipulating the object itself. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Developers Jos Posted October 29, 2018 Developers Share Posted October 29, 2018 Pretty sure you are passing a PTR so both variables are using the same pointer hence use the same memory space. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 i thought about that too, it would mean that a variable passed as a parameter would be a by ref ? no, i don't think so ! In a function, the scope of a parameter is local scope. But i agree that the problem is something like that, Pretty sure it's a PTR problem, but what should i do with that ? except using another name ... Link to comment Share on other sites More sharing options...
TheXman Posted October 29, 2018 Share Posted October 29, 2018 (edited) Passing something ByRef means that you are passing a pointer. Edited October 29, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Developers Jos Posted October 29, 2018 Developers Share Posted October 29, 2018 Byref is a mute point as it passes a pointer. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 hmmmm I understand pointer, but i do not use byref .... Link to comment Share on other sites More sharing options...
Developers Jos Posted October 29, 2018 Developers Share Posted October 29, 2018 (edited) Again it is not about Byref but rather the $jsonfunc being a pointer already in the Main part of the script which is passed to the Func. It is similar to what happens in this demo script: Global $jsonfunc = DllStructCreate("char txt[128]") DllStructSetData($jsonfunc, "txt", "aaa") Func myfunc($jsonparam) ConsoleWrite('+Before $jsonfunc txt = ' & DllStructGetData($jsonfunc, 1) & @CRLF ) ;### Debug Console ConsoleWrite(' Before $jsonparam txt = ' & DllStructGetData($jsonparam, 1) & @CRLF ) ;### Debug Console DllStructSetData($jsonfunc, "txt", "bbb") ConsoleWrite('-After $jsonfunc txt = ' & DllStructGetData($jsonfunc, 1) & @CRLF ) ;### Debug Console ConsoleWrite(' After $jsonparam txt = ' & DllStructGetData($jsonparam, 1) & @CRLF ) ;### Debug Console EndFunc ;==>myfunc myfunc($jsonfunc) Does that make sense? Jos Edited October 29, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
satanico64 Posted October 29, 2018 Share Posted October 29, 2018 (edited) thanks for your answer in fact, not really clear for me, why my $jsonparam would be a pointer, function parameters must be in local scope, they should'nt point to the variable used when we call a function. In fact with string variables, scope is local, with json, we can't be in local scope and use json as parameter this is what i understand Your script only with numbers do as i expect: Global $jsonfunc = DllStructCreate("char txt[128]") DllStructSetData($jsonfunc, "txt", "aaa") Func myfunc($jsonparam) ConsoleWrite('+Before $jsonfunc txt = ' & DllStructGetData($jsonfunc, 1) & @CRLF ) ;### Debug Console ConsoleWrite(' Before $jsonparam txt = ' & DllStructGetData($jsonparam, 1) & @CRLF ) ;### Debug Console DllStructSetData($jsonfunc, "txt", "bbb") ConsoleWrite('-After $jsonfunc txt = ' & DllStructGetData($jsonfunc, 1) & @CRLF ) ;### Debug Console ConsoleWrite(' After $jsonparam txt = ' & DllStructGetData($jsonparam, 1) & @CRLF ) ;### Debug Console EndFunc ;==>myfunc myfunc($jsonfunc) Global $varfunc = 10 Func myfunc2($varparam) ConsoleWrite('+Before $varfunc txt = ' & $varfunc & @CRLF ) ;### Debug Console ConsoleWrite(' Before $varparam txt = ' & $varparam & @CRLF ) ;### Debug Console $varfunc = 5 ConsoleWrite('+Before $varfunc txt = ' & $varfunc & @CRLF ) ;### Debug Console ConsoleWrite(' Before $varparam txt = ' & $varparam & @CRLF ) ;### Debug Console EndFunc ;==>myfunc myfunc2($varfunc) Output: +Before $jsonfunc txt = aaa Before $jsonparam txt = aaa -After $jsonfunc txt = bbb After $jsonparam txt = bbb +Before $jsonfunc txt = 10 Before $jsonparam txt = 10 +Before $jsonfunc txt = 5 Before $jsonparam txt = 10 [edit: variables names corrected in code] Edited October 29, 2018 by satanico64 Link to comment Share on other sites More sharing options...
Developers Jos Posted October 29, 2018 Developers Share Posted October 29, 2018 (edited) As I mentioned: 35 minutes ago, Jos said: it is not about Byref but rather the $jsonfunc being a pointer already So $jsonfunc is a pointer to the memory location of the structure ( in your case the Object). The pointer (hex value) is passed on to Myfunc() via the parameter, but is is still the same value for the pointer, so $jsonparam will then point to the exact same memory location. That is why, when one changes the other changes as well since they both use the same memory location. Making more sense now? Jos Edited October 29, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now