Jump to content
  • 0
akka

Splitting large plugin into multiple files.

Question

Hi my plugin project has grown into a huge inconvenient file, so i tried to split it into a number of files. For example i created atcommands.c and atcommands.h

 

 

 

atcommands.h:

struct atcommands_interface {	bool (*atcommand_test) (const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info);};struct atcommands_interface *atcommands;

atcommands.c

ACMD(test){//testreturn true}

Then in the "main" plugin file with the HPExport functions put this:

/* HPMi->addCommand */#define addAtcommand2(cname,funcname) 	if ( HPMi->addCommand != NULL ) { 		HPMi->addCommand(cname,funcname); 	} else { 		ShowWarning("HPM (%s):addAtcommand("%s",%s) failed, addCommand sub is NULL!n",pinfo.name,cname,# funcname);	}

Because the original HPMi->addCommand adds "atcommand_" to the beginning of the atcommand name inorder to call it.

 

and then i just add this as usual:

addAtcommand2("test", atcommands->atcommand_test);

It all compiles just fine, but the map server crashes and I guess its due to missing symbols. Is what im trying to do even possible? I've looked at numerous plugins but all of 'em seems to consist of a .c file and not header files.

Edited by akka

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi my plugin project has grown into a huge inconvenient file, so i tried to split it into a number of files. For example i created atcommands.c and atcommands.h

 

 

 

atcommands.h:

 

struct atcommands_interface {	bool (*atcommand_test) (const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info);};struct atcommands_interface *atcommands;
atcommands.c

ACMD(test){//testreturn true}
Then in the "main" plugin file with the HPExport functions put this:

/* HPMi->addCommand */#define addAtcommand2(cname,funcname) 	if ( HPMi->addCommand != NULL ) { 		HPMi->addCommand(cname,funcname); 	} else { 		ShowWarning("HPM (%s):addAtcommand("%s",%s) failed, addCommand sub is NULL!n",pinfo.name,cname,# funcname);	}
Because the original HPMi->addCommand adds "atcommand_" to the beginning of the atcommand name inorder to call it.

 

and then i just add this as usual:

addAtcommand2("test", atcommands->atcommand_test);
It all compiles just fine, but the map server crashes and I guess its due to missing symbols. Is what im trying to do even possible? I've looked at numerous plugins but all of 'em seems to consist of a .c file and not header files.
You seem to do it in a very confusing way.

Back to the point,

Run gdb, it will get you to exact location of crash, and probably that symbol might be missing, or something like that..

(Also, myself i never feel to split a plugin, my plugin is ~3k lines and still growing...)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.