Calling functions or methods from a debug menu?

BlitzMax Forums/BlitzMax Programming/Calling functions or methods from a debug menu?

chimaera(Posted 2016) [#1]
Hi all,

I am thinking about implementing a debug-menu for my different Bmax projects. Through a menu choice I would be able to call a function or an object's method.

For example I would like to be able to call a function from a menu item, without having to code each and every unique menu item.

Does anyone know how to do this? Is there any commands to do this or is it rather a way of dev methodology that I can use?

Sorry if the request is a bit vague. But I expect other developers here to have implemented something similar.

Thanks in advance for any help or hints-


Derron(Posted 2016) [#2]
Do a forum search for "Reflection".

Basically you are able to do this with reflection:
- create new instances of objects defined by "name"-string
- run methods by "name"-string
- access properties by "name"-string
...

So what you might want to do is something like:

Local objTypeID:TTypeId = TTypeId.ForObject( yourObject )
Local mth:TMethod = objTypeID.FindMethod("theDynamicCalledMethodName")

If mth then mth.Invoke(yourObject, [param1, param2])


You might see some more code examples there:
https://en.wikibooks.org/wiki/BlitzMax/Modules/BASIC/Reflection


bye
Ron


Kryzon(Posted 2016) [#3]
I think a sane way to do what you're after is to develop your entire software framework around a scripting language that is evaluated in real time.

Examples of this are Blender and 3ds max, two 3D applications have that "console" windows. You can type script commands and expressions and they are evaluated instantly. You can call API commands from those software, like modelling commands usually accessible from the GUI controls, and modify the scene.

- https://www.blender.org/manual/editors/python_console.html
- https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/3DSMax/files/GUID-C8019A8A-207F-48A0-985E-18D47FAD8F36-htm.html

The script language is also the base for making plugin tools for these applications.

I'm not really sure of the state of the module, but there seems to be some Lua support in BMax:
https://en.wikibooks.org/wiki/BlitzMax/Modules/System/Lua_scripting

So you have a "core" set of classes and functionality (like the business API) that is written in BlitzMax and the rest is all done through script files and script console.
This could include invoking menu items or individual script files like you want.


chimaera(Posted 2016) [#4]
Thanks guys for such quick responses!

I'll start checking out Reflection, and take it from there.