Page 1 of 2 12>
Topic Options
#174008 - 2007-02-17 04:52 PM See if an UDF is loaded?
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
I miss a simple way to check if an UDF is loaded. If you load several external UDF's, they themselves might have dependencies to the same UDF or same UDF name. This results in the same function being declared twice which isn't very good.

If there was a built-in function like "FunctionLoaded(function name)", one can build generic IF-checks into current UDF's and "globally" prevent this from happening.

EDIT
Dammit, posted in the wrong forum, can someone please move it to suggestions?


Edited by masken (2007-02-17 04:54 PM)
_________________________
The tart is out there

Top
#174009 - 2007-02-17 06:17 PM Re: See if an UDF is loaded? [Re: masken]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
This has been discussed before. As a workaround, You can declare global vars and then test with IsDeclared().

I vote for the new function to be called IsDefined() keeping true to the D in UDF.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#174010 - 2007-02-17 07:16 PM Re: See if an UDF is loaded? [Re: Les]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Glenn talks about his Kgen tool being able to do this.

KGen - the KiXtart UDF Resolver
http://innotechcg.com:2080/products/admin/main.asp?BODY=kixdev.htm

Top
#174013 - 2007-02-18 12:29 AM Re: See if an UDF is loaded? [Re: Allen]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Yes, global vars is one way, and that's what I'm using right now. But it feels like more of a workaround than a generic solution, as also an external tool would be. I think that to solve thing long term, some kind of solution built-into the KiX32.exe itself would really be the best way to go.
_________________________
The tart is out there

Top
#174018 - 2007-02-18 09:47 PM Re: See if an UDF is loaded? [Re: masken]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
I think isDeclared() is suitable for that too.
instead of looking for a var, one could look for udf name:

if isDeclared(UDFname)
"udf is declared."
endif
_________________________
!

download KiXnet

Top
#174019 - 2007-02-18 11:33 PM Re: See if an UDF is loaded? [Re: Lonkero]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
That would have been really nice \:\) Just tried it though, and it doesn't work \:\(

Edited by masken (2007-02-18 11:35 PM)
_________________________
The tart is out there

Top
#174023 - 2007-02-19 05:14 AM Re: See if an UDF is loaded? [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Hmmm.. haven't actually tried having multiple udfs with the same name in the library. I think KGen would load only the first one it found, as it would have no way to differentiate between more than one. Keeping all my udfs in one place tends to prevent that from happening.

I haven't completed the temporal auto-cognizance code yet, which would read your mind, determine which duplicate-named UDF you really needed, and would prolly rename the dup udf and all references to that udf in your code while it was at it... ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#174024 - 2007-02-19 06:38 AM Re: See if an UDF is loaded? [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the udf load code changed while back.
now, if you try to load the same udf or at least 2 udf's with same name, you get an error and kixtart exits.
_________________________
!

download KiXnet

Top
#174028 - 2007-02-19 11:54 AM Re: See if an UDF is loaded? [Re: Lonkero]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Yeah, it does like Lonk says.

My situation is this; got a script. From the script I'm calling a couple of external UDF's. Each external UDF might contain references to other external UDF's. An example is ReadFile(). In those UDF's, one could generically just do a check before calling ReadFile(), like IF ISDECLARED("ReadFile") <> 1 CALL "@SCRIPDIR\ReadFile.udf" ENDIF.
_________________________
The tart is out there

Top
#174033 - 2007-02-19 02:09 PM Re: See if an UDF is loaded? [Re: masken]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
But what if each script calls a different version of ReadFile? It might be better to just error out if this happens and restructure the UDF collection so that it is alwasy ensured that only one UDF of the same name is being loaded
_________________________
There are two types of vessels, submarines and targets.

Top
#174035 - 2007-02-19 02:42 PM Re: See if an UDF is loaded? [Re: Sealeopard]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Yes of course, but that is in itself a different problem really. But the suggested solution handles both cases; if you can check if an UDF of a certain name is already loaded, then you can handle this without the script exiting.
_________________________
The tart is out there

Top
#174039 - 2007-02-19 03:47 PM Re: See if an UDF is loaded? [Re: masken]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
although, this case is really rare and when it happens, there is great possibility the UDFs with same name are different in function and thus would cause the script to malfunction anyhow.

but, indeed, isdeclared for udf would be cool.
or better yet, some command, macro that returns all loaded UDFs.
_________________________
!

download KiXnet

Top
#174082 - 2007-02-20 07:28 PM Re: See if an UDF is loaded? [Re: masken]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
I was referring to how KGen would handle a situation where you had two different UDFs with the same name, located in different files with unique names. KGen would load only the first UDF file it found, and your code would break if you were crazy enough to define two different UDFs called with the same name. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#174083 - 2007-02-20 07:31 PM Re: See if an UDF is loaded? [Re: masken]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Again, KGen does that kind of recursive UDF resolution now. I have UDFs that have dependencies on other UDFs, and never give it a second thought.. KGen resolves the dependencies and loads all needed UDFs into the resulting code.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#174087 - 2007-02-20 09:47 PM Re: See if an UDF is loaded? [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
@glenn, that's just plain ignorance.
if one doesn't know what his code does and what it uses...
well, he should figure it out.

@all, FYI:
Some versions back kixtart did load the dublicate UDFs and it caused some trouble:
- kixtart consumed a lot of memory on faulty code (reloaded the same udf zillion times)
- ppl could blame kixtart functioning wrong when in fact they had 2 UDFs loaded with different code and they assumed they didn't

@masken,
I must say it again in another words. reconstruct your scripts. There is no UDF that loads it's dependencies on it's own. it's the script that does the loading. if you load, it's no trouble at all to keep track of what you have loaded.

conclusion, I still think it would be cool to have a tracker macro.
maybe not just one that has only the name but the whole definition (name+args).
_________________________
!

download KiXnet

Top
#174088 - 2007-02-20 10:10 PM Re: See if an UDF is loaded? [Re: Lonkero]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
\:\)

Well for me it's become clear when I've started working with KiXforms.

I know it might be bad structure to call UDF's from within UDF's, but that is what I have today. I want to keep my UDF's as standalone UDF's and that they work when called (ie, call their own dependencies), but that becomes hard when you're calling several of them from a form for example, and they have the same dependencies.

Reconstructing them so that the main script calls all dependencies is of course doable, but then one would still lack a good way to know why an UDF failed. If you could check within the UDF if a dependency is loaded or not, you could return a relevant errorcode and message saying this too \:\)

I really like the idea of a function that reports loaded functions. Perhaps IsDeclared() could work so that if IsDeclared() is called without a name, it returns an array with all loaded vars and functions, and if called with a name, returns if loaded or not, like:

Syntax: IsDeclared("string", type)

Parameters:

string (optional)
The variable or function you want to know the status of. If left out, all declared variables and/or functions are returned.

type (optional)
1 = variable
2 = function

?


Edited by masken (2007-02-20 10:12 PM)
_________________________
The tart is out there

Top
#174089 - 2007-02-20 10:15 PM Re: See if an UDF is loaded? [Re: masken]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
so, the first point of improvement would be to make the parser tell where is the dublicate defined.
hmm, so, you load the UDF's on the fly with call lines?
I mean, included udf's can't be scripted away.
_________________________
!

download KiXnet

Top
#174095 - 2007-02-21 11:03 AM Re: See if an UDF is loaded? [Re: masken]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Originally Posted By: masken
I really like the idea of a function that reports loaded functions. Perhaps IsDeclared() could work so that if IsDeclared() is called without a name, it returns an array with all loaded vars and functions, and if called with a name, returns if loaded or not


There have been a few occassions when I'm doing something a bit tricky and I've wished that Ruud exposed the internal structures of KiXtart through automation objects, even if they were read only. Some of these have been addressed now with built-ins, but even so, I'd love to be able to code like:
 Code:
$oKix=GetObject("KiXtart.Interpreter")
 
If Not $oKix.Features("IsDeclared()")
   "Sorry, this script requires IsDeclared() to work correctly"+@CRLF
   Exit 1
EndIf
 
For Each $oVariable in $oKix.Globals
   "Global variable "+$oVariable.Name+" = '"$oVariable.Value+@CRLF
Next
 
For Each $oVariable in $oKix.Locals
   "Local variable "+$oVariable.Name+" = '"$oVariable.Value+@CRLF
Next
 
For Each $oUDF in $oKix.UDF
   "Defined UDFs "+$oUDF.Name+@CRLF
   For Each $oParameter in $oUDF.Parameters
      ; Note, parameter will only have a value when inside the actual UDF.
      "Parameter: "+$oParameter.Name+" value='"+$oParameter.Value+"' "+IIf($oParameter.Optional,"(optional)","(mandatory)")+@CRLF
   Next
Next
 
For Each $oFD in $oKix.FileDescriptors
   "File descriptor "+$oFD.Name+" is "
   If $oFD.mode>=0
      "in use, mode is "+$oFD.mode+" file path is '"+$oFD.Path
   Else
      "not in use."
   EndIf
   @CRLF
Next
 
"Currently executing line # "+$oKix.CurrentLine+@CRLF
 
myFunction()
 
Function myFunction()
   Debug("Testing return stack enumeration")
EndFunction
 
Function Debug($s)
   "DEBUG: "+$s"+@CRLF
   "   Return Stack:"+@CRLF
   For Each $oReturn in $oKix.ReturnStack
      "   Calling entity: "+$oReturnStack.name+", line #"+$oReturnStack.line"+@CRLF
   Next
EndFunction

Top
#174706 - 2007-03-15 11:07 PM Re: See if an UDF is loaded? [Re: Richard H.]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
I'd like a ruudimentary comment on this ;\)
_________________________
The tart is out there

Top
#174707 - 2007-03-15 11:58 PM Re: See if an UDF is loaded? [Re: masken]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Looks to me you gotten more than just rudimentary comments. ;\)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 2 12>


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (mole) and 643 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.079 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org