What about a feature which allows you to selectively ignore certain calls totally when compiling a script?
This would allow construction of an assert-function, for example. So that it could be decided on runtime if the script is being compiled as a "debug" build (with asserts) or as a "release" build without any extra code like this.
In API this could be as simple as allowing registration of NULL as method or function pointer. Inside script build code any calls to functions or objects would be just ignored if their handler is NULL. Then application could register NULL handlers instead of the true handlers when it wants to leave the additional debugging code out which is written into the scripts.
Alternatively the API could have an option to flag certain functions or methods to be conditional for usage, and on a call to script build it would be told if the conditional stuff should be ignored or compiled normally.
Disclaimer: I haven't tried if it would already work this way, although I doubt that would be the case. :-)