Adding new types while running app

BlitzMax Forums/BlitzMax Beginners Area/Adding new types while running app

Hardcoal(Posted 2014) [#1]
Any way of adding new types while app is running?

Same like dll's? when you load library.
I want my Editor to be released as exe but I want to give people option

to add new types or edit existing ones.

For that I must have the types compiled seperatly and be patched to the running app some how.

is it possible somehow.
I may have asked this question before. but maybe i didnt ask it clearly

Thanks


Yasha(Posted 2014) [#2]
Types don't really make sense as a runtime construct. All you really need if you want to pass functionality around in named slots is to use a TMap to store function pointers with strings as key names.

Have you looked into LuaJIT? That's generally considered far and away the best way to extend an app with new code at runtime.


Hardcoal(Posted 2014) [#3]
Ill look at it now Yasha, tnx!

BTW how do I extract a function pointer?


Yasha(Posted 2014) [#4]
You just assign the name like any other value. The receiving variable must either have a function type, or Byte Ptr:

Function foo:Float(x:Int)
    Return x + 1.5
End Function

Local f:Float(_:Int) = foo
Local b:Byte Ptr = foo

Print f(19)    '20.5


Byte Ptr can receive pointers with any return and argument types so it can potentially be handy for handling many different kinds of function. You assign it back to a variable of the right call type when you need to use it. Be warned that because Byte Ptr can receive a pointer of any type and be assigned back to a variable of any type, you need to make sure you don't accidentally assign a Int(Int) to a Float(Float) or something silly like that (there can be legit uses for this, but if you need to ask, don't).

Since pointers aren't a subtype of object, you'll need a simple wrapper to "box" them up for storage in a TMap, if that's what you end up doing (same as if you wanted to store ints or floats in a TMap).