Noob Alert: How To Access Compiled Code/Functions?

BlitzMax Forums/BlitzMax Beginners Area/Noob Alert: How To Access Compiled Code/Functions?

MGE(Posted 2007) [#1]
I'll make this short and sweet:

Strict
Function Add:Int(a:Int,b:Int)
Return a + b
End Function

How would I turn this into compiled code that I can use in any of my Blitmax programs? I'm basically building my own language extension based on functions and I don't want to mess with any source/compiling the routines after they're done. I've done limited research on mods, but I don't know if what I want to do IS a mod. Thank you for your detailed help. ;)


tonyg(Posted 2007) [#2]
I would use a module.
How to make and edit modules


MGE(Posted 2007) [#3]
I'm stuck on the simple stuff! Here's my test module:
Strict
Module mge.mgetest
ModuleInfo "Name: My First Module"
'
Type MyXY
 Field x:Float,y:Float
End Type
'
Function CreateNewXY:MyXY()
 Local o:MyXY = New MyXY
 o.x = 100
 o.y = 200
 Return o
EndFunction

Here's my test app that uses the module:
Import mge.mgetest
'
Type MyXY
 Field x:Float,y:Float
End Type
'
Global vt:MyXY
'
vt = CreateNewXY()
Print vt.x
Print vt.y
'

But it doesn't work! Can anyone point me in the right direction? Thanks!


Brucey(Posted 2007) [#4]
For starters, the type MyXY is already defined in the module, so you don't need to redefine it in your app.

You should have created a folder in BlitzMax/mod called mge.mod
Inside that folder you should create another folder called mgetest.mod
Inside that folder you should create a file called mgetest.bmx (which is where you place the source for your module)

You'll know it's all set up properly after building modules and seeing some files like mgetest.debug.win32.x86.a and mgetest.debug.win32.x86.i in your module folder.


MGE(Posted 2007) [#5]
Hi Brucey, thanks...yepper...the module builds fine. The source app that uses the module can't compile. I get a compile error, "Unable to convert from 'MyObject' to 'MyObject'." A compiled collection of routines can manipulate passed objects and return new objects right?

Here's the sources again, more generic. Module:
Strict
Module mge.mgetest
ModuleInfo "Name: My First Module"
'
Type MyObject
 Field x:Float,y:Float
End Type
'
Function CreateNewObject:MyObject()
 Local o:MyObject = New MyObject
 o.x = 100
 o.y = 200
 Return o
EndFunction

And the app that uses the imported module:
Import mge.mgetest
'
Type MyObject
 Field x:Float,y:Float
End Type
'
Global vt:MyObject
'
vt = CreateNewObject()
Print vt.x
Print vt.y



Azathoth(Posted 2007) [#6]
MyObject is already in mge.mgetest, it shouldn't be in the test app.


MGE(Posted 2007) [#7]
Holy !@#$ !! Azathoth, that worked!! The source app just looks like this:
Import mge.mgetest
Global vt:MyObject
vt = CreateNewObject()
Print vt.x
Print vt.y

woo hoo!!!!! THANKS!!!!


Azathoth(Posted 2007) [#8]
Lol. Actually Brucey had said it, you must of missed it or something.


MGE(Posted 2007) [#9]
DOH!!!!! LOL :) "For starters, the type MyXY is already defined in the module, so you don't need to redefine it in your app."

Thanks Brucey too!! ;)


ziggy(Posted 2007) [#10]
The problem here is that you have two different objects with the same name. You can do that on BlitzMax, but the function CreateNewObject was returning a mge.mgetest.MyObject and you were asigning that to a local defined type called MyObject, and they are different unrelated objects, and BlitzMax can't convert one to the other.