This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Module segfaulting

Discussion of Eggdrop's code and module programming in C.
Post Reply
k
keikoz
Voice
Posts: 4
Joined: Sat Feb 25, 2006 8:31 pm

Module segfaulting

Post by keikoz »

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: Select all

#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]
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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
k
keikoz
Voice
Posts: 4
Joined: Sat Feb 25, 2006 8:31 pm

Post by keikoz »

Ok, it is working.

Thank you very much :)
Post Reply