Monday, December 28, 2009

Import and Lua Classes

New in 0.9.0.0, which will be released any day now, will include the new Import() function. Import() loads a script into the global space. I know what you're thinking: we already have LoadScript() and the "exec" prefix why on Earth do we need yet another way to load and execute scripts? Well I'll tell you why Jimmy: when you use LoadScript() or "exec" you change the internal script name into the script that was just loaded or executed. That's a good thing if you want to shift focus away from your script to another one but it's a bad thing if you do not. This is where Import() comes in, it does not change the internal script name so Get and SetScriptOption() behave as though your script made the call and not as the loaded script, which is a game changer. Adding Import() will also future proof us in the event that other such functions are added.

After adding this new function I went looking for some info on Lua Classes. Unfortunately I'm not the smartest bulb in tackle box and it all went straight over my head. But I did manage to come up with a simple Lua Class which can be seen by downloading libSearch. Hopefully others can find it useful as I'll be using it exclusively from now on when I add search.

No comments:

Post a Comment