Difference between revisions of "Writing Modules In C"

From ASSS Wiki
Jump to: navigation, search
(formatted code)
Line 2: Line 2:
  
 
(TODO: How do I format code?)
 
(TODO: How do I format code?)
<nowiki>
+
<pre>/*
/*<br>
+
Template Module
Template Module<br>
+
*/
*/<br>
 
<br>
 
  
 +
#include "asss.h"
 +
// Interfaces
 +
local Imodman *mm;
  
#include "asss.h"<br>
+
// The entry point:
<br>
+
EXPORT int MM_testModule(int action, Imodman *mm_, Arena *arena)
// Interfaces<br>
+
{
local Imodman *mm;<br>
+
if (action == MM_LOAD)
 
+
{
// The entry point:<br>
+
mm = mm_;
EXPORT int MM_testModule(int action, Imodman *mm_, Arena *arena)<br>
+
return MM_OK;
{<br>
+
}
if (action == MM_LOAD)<br>
+
else if (action == MM_UNLOAD)
{<br>
+
{
mm = mm_;<br>
+
return MM_OK;
return MM_OK;<br>
+
}
}<br>
+
else if (action == MM_ATTACH)
else if (action == MM_UNLOAD)<br>
+
{
{ <br>
+
return MM_OK;
return MM_OK;<br>
+
}
}<br>
+
else if (action == MM_DETACH)
else if (action == MM_ATTACH)<br>
+
{
{ <br>
+
return MM_OK;
return MM_OK;<br>
+
}
}<br>
+
return MM_FAIL;
else if (action == MM_DETACH)<br>
+
}
{<br>
+
</pre>
return MM_OK;<br>
 
}<br>
 
return MM_FAIL;<br>
 
}<br>
 
 
 
</nowiki>
 

Revision as of 16:53, 10 January 2005

The easiest way to write a module in C is to work off a template, as certain parts of all modules are identical. Here is a template that does nothing more than connect with the server:

(TODO: How do I format code?)

/*
	Template Module
*/

#include "asss.h"
// Interfaces
local Imodman *mm;

// The entry point:
EXPORT int MM_testModule(int action, Imodman *mm_, Arena *arena)
{
	if (action == MM_LOAD)
	{
		mm = mm_;
		return MM_OK;
	}
	else if (action == MM_UNLOAD)
	{	
		return MM_OK;
	}
	else if (action == MM_ATTACH)
	{		
		return MM_OK;
	}
	else if (action == MM_DETACH)
	{
		return MM_OK;
	}
	return MM_FAIL;
}