PDA

View Full Version : Autoload functionality?


JHN
01-14-2008, 01:40 PM
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

dutch_delight
01-14-2008, 01:52 PM
try (function())
catch(messagebox("not found"))

Is the only thing i can think of.

JHN
01-14-2008, 02:19 PM
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

Gravey
01-15-2008, 09:22 AM
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:Because include is a compile-time construct, the current MAXScript scope is maintained within the included file. This is opposed to the fileIn() method described in Running Scripts, whose script file content is compiled in a global scope context.

RustyKnight
01-15-2008, 09:53 PM
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

JHN
01-16-2008, 08:25 AM
(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... :)

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

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

RustyKnight
01-16-2008, 11:53 PM
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!
-JohanI 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 lessonsActually, I was just asleep when I read the post the first time...

JHN
01-17-2008, 08:44 AM
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

CGTalk Moderation
01-17-2008, 08:44 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.