Overriding built-in functions

BlitzMax Forums/BlitzMax Programming/Overriding built-in functions

Brucey(Posted 2007) [#1]
Is it possible to override any built-in function so that one can implement their own code in its place?

For example in GLMax2D, UploadTex resizes pixmaps to create the different mipmap levels.
However, Exr images can store all levels of Mipmap images in a single file, which could then be applied to each GL mipmap level instead of having the "biggest" pixmap resized.

Or might it require writing my own image->tex stuff altogether? *sigh*


H&K(Posted 2007) [#2]
You can if they are a method or function of a type, and have not been declared "Final"

You also can even if they dont meet those requirements, by ...... Editing the Moduals


Azathoth(Posted 2007) [#3]
I posted some code awhile back that override functions, it should work on all functions. You can even have the new function call the original if you UnHook it first.

http://blitzbasic.com/codearcs/codearcs.php?code=1810


Brucey(Posted 2007) [#4]
Editing the Moduals

But that kind of defeats the purpose...

I guess I need to play around with it a bit then... see what I can break ;-)

On the subject of EXR still, it also supports both cube and spherical environment maps. Is that the same as a lightmap?
Would it be particularly useful to extract these into something other than a "normal" pixmap?
For example, there are built-in functions for translating 3d coords to 2d map coords, and back... not sure if anyone would benefit from having that exposed in Max...

Too much choice, me thinks.


Brucey(Posted 2007) [#5]
Thanks Azathoth... will have a look into that.


Azathoth(Posted 2007) [#6]
Its abit "hackish" as it alters the code at runtime and if you're not careful will crash your program but if used propery it allows you to direct function calls.


DJWoodgate(Posted 2007) [#7]
I have been messing about doing some global rotation stuff which overrides various draw functions in Max2d. Further these overriden functions do not have to have the same parameter list. You can still call the normal function by making it an absolute reference such as BRL.GLMAX2D.UPLOADTEX, or if say your function is in a type by prepending with a period. I have not tried making a module or an import with an overriden function that is not in a type though. Not sure what would happen in that case, which would get called, what problems there might be.
This hooking stuff looks interesting though, if you are feeling adventurous.


H&K(Posted 2007) [#8]
Editing the Moduals


But that kind of defeats the purpose
Err, no. If the given command doesnt do what you want it to do, then change it.
This is why ppl moan about sync mods overwriting their changes, because the Lang as you have it, isnt ness the best one for you. Apart from the sync problem BMax seems desgined to be edited.


Azathoth(Posted 2007) [#9]
This is perhaps a better example and demonstrates overriding 'Print'
Global PrintHook:AzHook=New AzHook

PrintHook.Hook(Print, MyPrint)	' Calls to Print gets redirected to MyPrint

Print "Hello"
Print "Bye"
Print
End

Function MyPrint(str:String)
	str:+"..."
	PrintHook.UnHook()	' Print restored back to original
	Print Str
	PrintHook.ReHook()	' Print redirected back to MyPrint
EndFunction