How to make and edit modules

BlitzMax Forums/BlitzMax Tutorials/How to make and edit modules

Bot Builder(Posted 2005) [#1]
First off, what type of module are you making? Are you making a module that is pure blitzmax code? Are you editing an already existing module that uses C/C++/ObjC? Are you making a module to interface to a DLL?


Mingw

In windows:

First off, to compile modules you will need to have mingw (at least on a windows computer) and have the paths for it set up. For anyone who doesn't know, enviornment paths allow you or other programs to use common programs by simply referencing the name of the program.

Mingw is pretty much multi purpose when used in conjunction with blitzmax. It allows blitzmax to compile non-bmx code into modules (automated), and allows you to use dlls in blitzmax after writing a wrapper/declerations in .bmx. Get it from here

Then, you've gotta set your enviornment paths for it. Go to control panel, System, Advanced tab, click "Enviornment variables", in the new window that pops up there is a listbox labeled "System Variables". Within this, scroll down to a variable named "Path". Select it, click edit. Move to the end of the text, and add a semicolon (;), and paste in the path to your mingw bin directory.


In Mac and Linux:

I'm not sure about mac and linux but most linux distributions will have a copy of gcc (GNU Compiler Collection) which is what BlitzMax requires to compile mixed language modules.


Make your own module

Ok, let's say we decide to make our own module. Open up the default IDE or a 3rd party IDE, and create a new file. First off, I like to declare my modules as Strict:
Strict
Then, define the module name using the Module command:
Strict

Module Bot.FirstModule
This also restricts compilation so you cannot attempt to compile it using standard methods

Next, declare the ModuleInfo, which is basically just misc info about the module:
Strict

Module Bot.FirstModule

ModuleInfo "Name: My First Module"
ModuleInfo "Description: Cool eh?"
ModuleInfo "License: Public Domain"
ModuleInfo "Authors: Bot Builder"
ModuleInfo "CustomAttr: See!"
Now, we declare the modules our module will use:
Strict

Module Bot.FirstModule

ModuleInfo "Name: My First Module"
ModuleInfo "Description: Cool eh?"
ModuleInfo "License: Public Domain"
ModuleInfo "Authors: Bot Builder"
ModuleInfo "CustomAttr: See!"

Import BRL.StandardIO 'Print stuff
NOTE: This doesn't actually import it, yet. It just insures that the other module will be imported into the program. So if you import this module the other will also be imported.

Just for an example we'll use a very, very simple function, of course you can use anything you would write in a normal blitzmax file as the contents. Like, Globals, Constants, Functions, Methods, Types, Arrays, Fields, etc.
Strict

Module Bot.FirstModule

ModuleInfo "Name: My First Module"
ModuleInfo "Description: Cool eh?"
ModuleInfo "License: Public Domain"
ModuleInfo "Authors: Bot Builder"
ModuleInfo "CustomAttr: See!"

Import BRL.StandardIO 'Print stuff

Function SayHello(Name$)
	Print "Hi "+Name$
EndFunction
Now, this is just to demonstrate usage of the private flags which prevent some elements of a file not to be available from the outside:
Strict

Module Bot.FirstModule

ModuleInfo "Name: My First Module"
ModuleInfo "Description: Cool eh?"
ModuleInfo "License: Public Domain"
ModuleInfo "Authors: Bot Builder"
ModuleInfo "CustomAttr: See!"

Import BRL.StandardIO 'Print stuff

Function SayHello(Name$)
	Print Greeting+" "+Name$+"!!!"
EndFunction

Private
Const Greeting$="Hi"
You wont be able to access this externally. Finally, time to save our file. Create a directory inside mods called "bot.mod". This is the directory I will probably use for all my mods. Then, within that create a directory called "firstmodule.mod". Finally, save the source as "firstmodule.bmx". Keep in mind its important that its the same name. Then, start up the command prompt. You can also do this by going Ctrl-Alt-Delete, and in the task manager go File->New Task and type "cmd" and hitting enter. In side this, type "cd C:\BlitzMaxBeta101\bin", or, whatever your bin path is. Then, type "bmk makemods -r bot.firstmodule" this will compile the module in release mode. Make a new file:
SayHello("Everyone")
and run. Hopefully it will display:
Hi Everyone!!!



Using non bmx files

You can simply do this:
Import "TheFile.C"

Extern  'Add "win32" if its a win32 dll
	Function MyFunctionIWantToUse:ReturnType(params:types)
	'ETC
End Extern


Using dlls

Linking to dlls is detailed here


Tibit(Posted 2005) [#2]
Great Tutorial! Simple and Effective, still I managed to screw it up!

I get a compile error when compiling your example =(

It does create some files and a folder .bmx

Here is the error from the prompt:

P:\BlitzMaxBeta101\bin>bmk makemods -r bot.firstmodule
Compiling:firstmodule.bmx
flat assembler version 1.51
3 passes, 671 bytes.
Archiving:firstmodule.a
ar is not an internal command, external command, program or file.
Build Error: Failed to create archive P:/BlitzMaxBeta101/mod/bot.mod/firstmodule
.mod/firstmodule.a
P:\BlitzMaxBeta101\bin>


Bot Builder(Posted 2005) [#3]
Thanks,

Hmm. I'm not sure what the problem is... OOH I bet my tutorial is slightly wrong. You probably need mingw to compile any module. Since .a is a GCC file.

I've taken some stuff out and moved it around so hopefully it's more clear now.


Tibit(Posted 2005) [#4]
And a question on Private, Does everything below private get private?


Bot Builder(Posted 2005) [#5]
Yes, until reaching a public identifier. The only things public/private dont work on is fields and methods which is the reverse of most OOP languages, and IMHO should be fixed.


Tibit(Posted 2005) [#6]
I go it to work after installing Mingw!

I had to Turn Debug Build off or compile in DebugMode for my test.bmax to Build. Both ways works =)


Dirk Krause(Posted 2005) [#7]
A working example for a simple .c mod is here


ziggy(Posted 2005) [#8]
I've done everything and when I try to compile the module, from the command line, i get this output:

D:\BlitzMaxBeta101\bin>bmk -r manel.primero
bmk commandline error
Usage: bmk operation [options] [parameters]
Operations:
makeapp Make application
makemods Make modules
cleanmods clean modules
listmods List modules
modstatus Module status
syncmods Synchronize modules
zapmod Zap module
unzapmod Unzap module
ranlibdir ranlib dirtree (MacOS)
docmods Create module docs
syncdocs Synchronize doc indexes
convertbb Convert .bb file to .bmx
Options:
-q Quiet mode
-v Verbose mode
-a Make all
-d Debug mode
-r Release mode
-k Kill source (danger!)
-o outputfile Specify output file
-f framework Specify framework

What am I doing wrong?


Azathoth(Posted 2005) [#9]
What does Mingw do if you're making a module from bmx files?


ziggy(Posted 2005) [#10]
This the error I get when I try to build a module from the IDE.

Building primero
Linking:primero.exe
D:\BlitzMaxBeta101\bin\ld.exe: cannot find D:/BlitzMaxBeta101/mod/manel.mod/primero.mod/primero.a

Process complete


ziggy(Posted 2005) [#11]
I have installed mingw and the error remains...


erwan(Posted 2005) [#12]
how to compile with linux? :( :(
please help me :)


mangoo(Posted 2005) [#13]
ziggy_bcn, do you see the difference :-) ?


D:\BlitzMaxBeta101\bin>bmk -r manel.primero
P:\BlitzMaxBeta101\bin>bmk makemods -r bot.firstmodule


Mathieu A(Posted 2005) [#14]
Hi! I want to compile a C file and I've got the following error

Compiling:stdcall.c
[ERROR]: Build Error: failed to compile e:/blitzmaxbeta103/mod/tess_engine.mod/gui.mod/stdcall.c

How can I resolve this error?


Paul "Taiphoz"(Posted 2005) [#15]
does this work with the update ?

Just got the update in today, and also downloaded this today, Put the mods in the pub folder, did a bmk makemods -a to make all mods.

and it failed on the zipengine one..


CoderLaureate(Posted 2005) [#16]
My module builds but when I try to import it into an app. I get an error that the module can't be found. More specifically I get an error stating that the module interface cannot be found.


Warren(Posted 2006) [#17]
I'm trying to make a module as well and I get the same error about the module interface. I assume this is the ".i" file that I see included with other modules. Is there a way to generate that file? Please don't tell me it's a hand edited file...


Karnaugh(Posted 2006) [#18]
Try:

Import ModuleScope.ModuleName

so if you used the same names as in Bot Builder's original example the test application would look like:

Import bot.firstmodule

SayHello( "Everyone" )


Dreamora(Posted 2006) [#19]
And make sure you don't use a newer mingw version than the one specified (ie not MingW 5). Otherwise it won't work as well unless you fully rebuild all modules (and rebuild any changed brl / pub module after each syncmod update) as that one is not compatible with BM


Karnaugh(Posted 2006) [#20]
Yes to Dreamora's post. I'm using MinGW Studio and I first synch'd all the mods then rebuilt them. Probably should have mentioned that in the origial post. Sorry...


SculptureOfSoul(Posted 2006) [#21]
I'm trying to make a module as well and I get the same error about the module interface. I assume this is the ".i" file that I see included with other modules. Is there a way to generate that file? Please don't tell me it's a hand edited file...

I'm getting the same error when trying to compile a bmax only module. Anyone got a solution handy?

[edit]Found the problem. My module name was not all lowercase, and it appears that they must be for things to work properly.


ziggy(Posted 2006) [#22]
Note to BLIde users:
To make a module from BLIde, you just have to place (save) the BMX file in the appropiated folder (mod/modserver/modname) and when you press the Build and run button, BLIde will build you program as a module both in debug and release modes. Remember the folder name and bmx file name have to match, and have to be lowercase.


TomToad(Posted 2006) [#23]
Bot Builder's instructions will create mods only in release mode. So if you compile a test program in debug mode, then you'll get errors. You can replace -r with -d in the bmk makemods -r bot.firstmodule command to build a debug version, or you can leave off the option completely to build both a debug and release version.
To summarize:
bmk makemods -r module 'To build release version
bmk makemodes -d module 'To build debug version
bmk makemods module 'To build both debug and release versions



Matt Merkulov(Posted 2007) [#24]
Here's version translated to Russian by Maniak_dobrii:
http://blitzetc.boolean.name/articles/modules.htm


Hardcoal(Posted 2013) [#25]
why do i get this error

Module does not match commandline module


matibee(Posted 2013) [#26]
My guess is that your mod folder doesn't match the module scope declaration.

Open up an existing module and see how they are set up, for example, mod/brl.mod/filesystem.mod

Strict

Rem
bbdoc: System/File system
End Rem
Module BRL.FileSystem


There, right at the top of the file the Module scope matches the directory structure perfectly (minus the ".mod" extensions.)