Notifications
Clear all

[Closed] Autoload functionality?

 JHN

Is there any way to catch an error on a not found function or struct and try load it with a custom function?

In php you have something like:


 function __autoload($class_name){
 	require_once 'class.' . $class_name . '.php';
 }
 

-Johan

7 Replies

try (function())
catch(messagebox(“not found”))

Is the only thing i can think of.

 JHN

Hey DD, I know about try catch… but what I mean/want is lower level. It’s more like an eventhandler for function/structs calls.

Then I wouldn’t manually add try catches around function calls, it would catch all errors and try to load a file with the functions/structs.

One for the wishlist I guess

-Johan

I’m not sure it’s quite what you’re looking for but you could use the include function at the begining of your scripts to load in your function libraries and in theory avoid this problem in the first place.

Some info from the reference:

I think I understand…think is the key word here…

You could try something like:


  if myDynamicFunction == undefined then (
	MyFancyAutoLoadingDynamicFunctionsFunction()
  )

  myDynamicFunction()

Bascially, what I’ve done in the past is to assign function calls to variables, like a kinda callback setup…This might also be able to tell if a function is out of scope or not so you can decide how to deal with it.

Even if the function has parameters, so long as you leave the parameters and brackets off I believe it should return a result of undefined or the function name…

I hope this is on track (cause the first time I read the post, I had no idea what you were talking about)

Shane

1 Reply
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

(cause the first time I read the post, I had no idea what you were talking about)

Roflol, I thought I was quite clear… but communications is something i’m working on for years…

Yeah this is closest to the sort of thing I’m looking for, the autoload function in php simply catches all failed object calls and lets you work further on it. This is the “manual autoload” solution (cause we still need to tell the autoload with which function we want to work) but this is I think probably the best solution!

Thanx!
-Johan

*makes notes to take some english communications lessons

I was thinking, a rather rare thing now days, if you were really committed, you could write your own function that would check to see if the function you wanted was loaded and if it wasn’t could search through a list of sources till it was?? This of course would present the added hassel of having a whole bunch of scripts been loaded that you might not need, or otherwise writing a parser to parse each source script for the offending function and then load the script that contains it…

I think I’ve had to much caffine…

*makes notes to take some english communications lessons
Actually, I was just asleep when I read the post the first time…

 JHN

oh yeah caffeine gets the job done… I’ll think I just stick to good old fileIn practices, and leave the fancy stuff for know… the purpose of an autoload function is to reduce the amount of code you write not to increase it

-Johan