egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Module segfaulting

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming
View previous topic :: View next topic  
Author Message
keikoz
Voice


Joined: 25 Feb 2006
Posts: 4

PostPosted: Sun Oct 29, 2006 9:19 pm    Post subject: Module segfaulting Reply with quote

Hi. I'm trying to understand how to build eggdrop modules. It is quite hard... Actually, i dont understand why this code doenst work (i have a segfault launching the bot):

Code:

#define MODULE_NAME "testmod"
#define MAKING_TESTMOD
#define TEST_MAJORV 0
#define TEST_MINORV 1
#include "../module.h"
#include "../irc.mod/irc.h"
#undef global

static Function *global = NULL;
static Function *irc_funcs = NULL;

char *testmod_start();


static int print_hi(char *nick, char *host, char *hand,
                    char *channel, char *text) {
  /*  dprintf(DP_STDOUT, "He told hello\n");*/

  return 0;
}

static cmd_t hi_pub[] = {
  {"!hi", "", print_hi, NULL},
  {0, 0, 0, 0}
};


static int testmod_expmem () {
  return 0;
}


static void testmod_report (int idx, int details) {
  if (details) {
    int size = testmod_expmem();
    dprintf(idx, "    Using %d byte%s of memory\n", size, size != 1 ? "s" : "");
  }
}


static char *testmod_close () {
  rem_builtins(H_pub, hi_pub);
  module_undepend(MODULE_NAME);
  return NULL;
}


static Function testmod_table[] = {
  (Function) testmod_start,
  (Function) testmod_close,
  (Function) testmod_expmem,
  (Function) testmod_report,
};


char *testmod_start(Function *global_funcs) {
  global = global_funcs;

  module_register(MODULE_NAME, testmod_table, 0, 1);

  if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
    module_undepend(MODULE_NAME);
    return "This module requires Eggdrop 1.6.0 or later.";
  }

  add_builtins(H_pub, hi_pub);

  return NULL;
}


Some help would be really appreciated ...[/code]
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Oct 29, 2006 9:45 pm    Post subject: Reply with quote

Well, it's because you don't import the function table from the irc-module, which is required to use H_pub bindings...

This should take care of that issue:
Code:
char *testmod_start(Function *global_funcs) {
  global = global_funcs;

  module_register(MODULE_NAME, testmod_table, 0, 1);

  if (!(irc_funcs = module_depend(MODULE_NAME, "irc", 1, 0))) {
    module_undepend(MODULE_NAME);
    return "This module requires the irc module to be loaded";
  }
  if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
    module_undepend(MODULE_NAME);
    return "This module requires Eggdrop 1.6.0 or later.";
  }

  add_builtins(H_pub, hi_pub);

  return NULL;
}

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
keikoz
Voice


Joined: 25 Feb 2006
Posts: 4

PostPosted: Mon Oct 30, 2006 6:17 am    Post subject: Reply with quote

Ok, it is working.

Thank you very much Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber