<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/11216" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2006-05-21T09:58:07-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/11216</id>

		<entry>
		<author><name><![CDATA[Kappa007]]></name></author>
		<updated>2006-05-21T09:58:07-04:00</updated>

		<published>2006-05-21T09:58:07-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63225#p63225</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63225#p63225"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63225#p63225"><![CDATA[
Edited the code (removed the __stdcall). Should work now.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6524">Kappa007</a> — Sun May 21, 2006 9:58 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[De Kus]]></name></author>
		<updated>2006-05-19T20:02:06-04:00</updated>

		<published>2006-05-19T20:02:06-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63182#p63182</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63182#p63182"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63182#p63182"><![CDATA[
then add define to zero string for __stdcall, if its not compiling on win32 <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy">.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2382">De Kus</a> — Fri May 19, 2006 8:02 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Kappa007]]></name></author>
		<updated>2006-05-18T17:57:30-04:00</updated>

		<published>2006-05-18T17:57:30-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63154#p63154</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63154#p63154"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63154#p63154"><![CDATA[
Yes cut the __stdcall, it's not needed.<br>__stdcall is the calling-convention of the Win32 API it's usually not used on *nix/g++<br><br>Only appeared there cause I used cygwin...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6524">Kappa007</a> — Thu May 18, 2006 5:57 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tulpik]]></name></author>
		<updated>2006-05-16T04:06:59-04:00</updated>

		<published>2006-05-16T04:06:59-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63082#p63082</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63082#p63082"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63082#p63082"><![CDATA[
Yes I create 5 files with Makefile.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7758">tulpik</a> — Tue May 16, 2006 4:06 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Alchera]]></name></author>
		<updated>2006-05-15T19:29:22-04:00</updated>

		<published>2006-05-15T19:29:22-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63065#p63065</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63065#p63065"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63065#p63065"><![CDATA[
<blockquote class="uncited"><div>What header file? hello.h? No, I copy code form web to files.</div></blockquote>Did you correctly name the <em class="text-italics">sections</em> (posted above)? There's 5 files in total, not one.<br><br>i.e. hello.h hello.c hello.hpp hello.cpp and <em class="text-italics">finally</em> the makefile<br><br>Do you know what a header file is?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3646">Alchera</a> — Mon May 15, 2006 7:29 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tulpik]]></name></author>
		<updated>2006-05-15T08:19:45-04:00</updated>

		<published>2006-05-15T08:19:45-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63044#p63044</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63044#p63044"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63044#p63044"><![CDATA[
Lol <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>Btw, probaly nothing.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7758">tulpik</a> — Mon May 15, 2006 8:19 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[De Kus]]></name></author>
		<updated>2006-05-15T08:10:06-04:00</updated>

		<published>2006-05-15T08:10:06-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63041#p63041</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63041#p63041"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63041#p63041"><![CDATA[
No idea, you can look up yourself, I don't have the time for this:<br><a href="http://www.google.com/search?q=__stdcall+%22syntax+error+before%22" class="postlink">http://www.google.com/search?q=__stdcal ... +before%22</a><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2382">De Kus</a> — Mon May 15, 2006 8:10 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tulpik]]></name></author>
		<updated>2006-05-15T08:05:04-04:00</updated>

		<published>2006-05-15T08:05:04-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63039#p63039</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63039#p63039"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63039#p63039"><![CDATA[
What header file? hello.h? No, I copy code form web to files.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7758">tulpik</a> — Mon May 15, 2006 8:05 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[De Kus]]></name></author>
		<updated>2006-05-15T07:57:20-04:00</updated>

		<published>2006-05-15T07:57:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63038#p63038</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63038#p63038"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63038#p63038"><![CDATA[
the errors occur in<div class="codebox"><p>Code: </p><pre><code>void __stdcall InitCppModule();void __stdcall ShutdownCppModule();</code></pre></div>seems they don't like the __stdcall, maybe its not defined. missing a header file?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2382">De Kus</a> — Mon May 15, 2006 7:57 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tulpik]]></name></author>
		<updated>2006-05-15T07:38:15-04:00</updated>

		<published>2006-05-15T07:38:15-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=63036#p63036</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=63036#p63036"/>
		<title type="html"><![CDATA[Compilation problems.]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=63036#p63036"><![CDATA[
Hellow Kappa007, i am problem with compile example module.<br><div class="codebox"><p>Code: </p><pre><code>gcc -pipe -fPIC -g -O2 -Wall -I. -I../../.. -I../../.. -I../../../src/mod -DHAVE_CONFIG_H   -DMAKING_MODS -c .././cpphello.mod/hello.c In file included from ../cpphello.mod/hello.c:20:../cpphello.mod/hello.hpp:20: error: syntax error before "InitCppModule"../cpphello.mod/hello.hpp:20: warning: type defaults to `int' in declaration of `InitCppModule'../cpphello.mod/hello.hpp:20: warning: data definition has no type or storage class../cpphello.mod/hello.hpp:21: error: syntax error before "ShutdownCppModule"../cpphello.mod/hello.hpp:21: warning: type defaults to `int' in declaration of `ShutdownCppModule'../cpphello.mod/hello.hpp:21: warning: data definition has no type or storage classmake[2]: *** [../hello.o] Error 1make[2]: Leaving directory `/home/gimper/downloads/eggdrop/src/mod/cpphello.mod'make[1]: *** [cpphello.mod_so] Error 2make[1]: Leaving directory `/home/gimper/downloads/eggdrop/src/mod'make: *** [modules] Error 2</code></pre></div>Please pack your code to zip archive and share it. Thanx!<br><br><br>tulpik<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=7758">tulpik</a> — Mon May 15, 2006 7:38 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2006-01-20T23:50:29-04:00</updated>

		<published>2006-01-20T23:50:29-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=59554#p59554</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=59554#p59554"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=59554#p59554"><![CDATA[
congratulations!<br><br>good job indeed<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Fri Jan 20, 2006 11:50 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Kappa007]]></name></author>
		<updated>2006-05-21T09:56:37-04:00</updated>

		<published>2006-01-20T22:14:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=59552#p59552</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=59552#p59552"/>
		<title type="html"><![CDATA[Example: Module in C++]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=59552#p59552"><![CDATA[
Oke, since some people (including myself <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink">) thought it might be useful to be able to write modules C++ rather than in plain C here we go <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_biggrin.gif" width="15" height="15" alt=":D" title="Very Happy"><br><br>The problem when trying to use C++ code with eggdrop is that eggdrop uses some global function table for imports which does not mix very with C++.<br>A simple "extern C" is not enough to be able to include the "module.h".<br><br><br>So my approach is to use a wrapper.<br>We start building normal module which wraps all stuff we need and compile that one with C.<br>Then we take the header file of that and just include it in our C++ files.<br>At the end we link all together.<br>Only thing we need are some structs from eggdrop to be able to bind/unbind commands from C++.<br><br>The whole thing ofcourse only works well when we don't need A LOT of eggdrop core functions cause then it might be a lot work to wrap them all <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"><br><br><br>My example module is called "cpphello.mod" and it just outputs a message to channel when triggered via "!hello".<br><div class="codebox"><p>Code: </p><pre><code>/* * hello.h -- part of cpphello.mod *    * Example how to write an eggdrop module in C++ * * Originally written by Kappa007         2006-01-21 * * * Copyright (c) by Kappa007. All rights reserved.  */#ifndef __HELLO_H__#define __HELLO_H__#ifdef __cplusplusextern "C"{#endif // __cplusplus    /*** Common typedefs and structs from eggdrop ***/    typedef void (*Function) ();    struct flag_record {      int match;      int global;      int udef_global;      int bot;      int chan;      int udef_chan;    };    typedef unsigned short int u_16bit_t;    typedef unsigned char u_8bit_t;    typedef struct tcl_cmd_b {      struct tcl_cmd_b *next;      struct flag_record flags;      char *func_name;              /* Proc name. */      int hits;                     /* Number of times this proc was triggered. */      u_8bit_t attributes;          /* Flags for this entry. TC_* */    } tcl_cmd_t;    typedef struct tcl_bind_mask_b {      struct tcl_bind_mask_b *next;      tcl_cmd_t *first;             /* List of commands registered for this bind. */      char *mask;      u_8bit_t flags;               /* Flags for this entry. TBM_*  */    } tcl_bind_mask_t;    typedef struct tcl_bind_list_b {      struct tcl_bind_list_b *next;      tcl_bind_mask_t *first;       /* Pointer to registered binds                                     * for this list.               */      char name[5];                 /* Name of the bind.            */      u_8bit_t flags;               /* Flags for this element. HT_* */      ::Function func;                /* Function used as the Tcl calling interface                                     * for procs actually representing C functions. */    } tcl_bind_list_t, *p_tcl_bind_list;    typedef struct {      char *name;      char *flags;      ::Function func;      char *funcname;    } cmd_t;    /*** Prototypes ***/    int  BindCommand(unsigned char table, cmd_t* cc, unsigned char bind);    void PutServer(const char* text);    void PutDCC(const int idx, const char* text);#ifdef __cplusplus}#endif // __cplusplus#endif // __HELLO_H__</code></pre></div><div class="codebox"><p>Code: </p><pre><code>/* * hello.c -- part of cpphello.mod *    * Example how to write an eggdrop module in C++ * * Originally written by Kappa007         2006-01-21 * * * Copyright (c) by Kappa007. All rights reserved.  */#define MODULE_NAME "CppHello"#include "src/mod/module.h"#include &lt;stdlib.h&gt;#undef global/*** Include your C++ exports here ***/#include "hello.hpp"static Function *global = NULL;static int CppHello_expmem(){    return 0;}static void CppHello_report(int idx, int details){    dprintf(idx, "%s running.", MODULE_NAME);}static char* CppHello_close(){    ShutdownCppModule();    module_undepend(MODULE_NAME);    return NULL;}EXPORT_SCOPE char* CppHello_start();static Function CppHello_table[] = {  (Function) CppHello_start,  (Function) CppHello_close,  (Function) CppHello_expmem,  (Function) CppHello_report,};char* CppHello_start(Function *global_funcs){    global = global_funcs;    module_register(MODULE_NAME, CppHello_table, 1, 0);    //TODO: check module dependencies here    // Call the "init" of your C++ code    InitCppModule();    return NULL;}/*** wrapper functions ***/int BindCommand(unsigned char table, cmd_t* cc, unsigned char bind){    if (cc == NULL)    {        return -1;    }        // get the bind table    p_tcl_bind_list H_temp;    switch (table)    {        case 0:            H_temp = find_bind_table("dcc");            break;        case 1:              H_temp = find_bind_table("msg");            break;        case 2:            H_temp = find_bind_table("pub");            break;        default:            return -1;    }    if (!H_temp) return -1;    // add or remove commands    if (bind != 0)    {        add_builtins(H_temp, cc);    }    else    {        rem_builtins(H_temp, cc);    }    return 0;}void PutServer(const char* text){    dprintf(DP_SERVER, text);}void PutDCC(const int idx, const char* text){    dprintf(idx, text);}</code></pre></div><div class="codebox"><p>Code: </p><pre><code>/* * hello.hpp -- part of cpphello.mod *    * Example how to write an eggdrop module in C++ * * Originally written by Kappa007         2006-01-21 * * * Copyright (c) by Kappa007. All rights reserved.  */#ifndef __HELLO_HPP__#define __HELLO_HPP__#ifdef __cplusplusextern "C"{#endif // __cplusplusvoid InitCppModule();void ShutdownCppModule();#ifdef __cplusplus}#endif // __cplusplus#endif // __HELLO_HPP__</code></pre></div><div class="codebox"><p>Code: </p><pre><code>/* * hello.cpp -- part of cpphello.mod *    * Example how to write an eggdrop module in C++ * * Originally written by Kappa007         2006-01-21 * * * Copyright (c) by Kappa007. All rights reserved.  */#include "hello.h"#include "hello.hpp"#include &lt;string&gt;using namespace std;class  MyHelloClass;static MyHelloClass*myHelloClass = NULL;int ChanHello(char *nick, char *host, char *hand, char *channel, char *text);class MyHelloClass{    private:        cmd_t*myCommandTable;        stringmyReply;    public:        MyHelloClass(string aReply) :           myCommandTable( NULL ),          myReply( aReply )        {            myCommandTable = new cmd_t[2];            myCommandTable[0].name       = "!hello";            myCommandTable[0].flags      = "";            myCommandTable[0].func       = reinterpret_cast&lt;Function&gt;(&amp;ChanHello);            myCommandTable[0].funcname   = NULL;            memset(static_cast&lt;void*&gt;(&amp;myCommandTable[1]), 0, sizeof(cmd_t));            ::BindCommand(2, myCommandTable, true);        }        ~MyHelloClass()        {            ::BindCommand(2, myCommandTable, false);            if (myCommandTable != NULL) delete[] myCommandTable;        }        stringReply()        {            return myReply;        }};void InitCppModule(){    myHelloClass = new MyHelloClass("Hello from C++!");}void ShutdownCppModule(){    if (myHelloClass != NULL)    {        delete myHelloClass;    }}int ChanHello(char *nick, char *host, char *hand, char *channel, char *text){    string aMsg = "";    aMsg += "PRIVMSG ";    aMsg += channel;    aMsg += " :";    aMsg += myHelloClass-&gt;Reply();    PutServer( aMsg.c_str() );    return 0;}</code></pre></div><div class="codebox"><p>Code: </p><pre><code># Makefile for src/mod/cpphello.mod/srcdir = .doofus:@echo ""@echo "Let's try this from the right directory..."@echo ""@cd ../../../ &amp;&amp; makestatic: ../cpphello.omodules: ../../../cpphello.$(MOD_EXT)../hello.o:$(CC) $(CFLAGS) $(CPPFLAGS) -DMAKING_MODS -c $(srcdir)/hello.c@rm -f ../hello.omv hello.o ../../hello_cpp.o:$(CC) $(CFLAGS) $(CPPFLAGS) -DMAKING_MODS -c $(srcdir)/hello.cpp -o $(srcdir)/hello_cpp.o@rm -f ../hello_cpp.omv hello_cpp.o ../../../../cpphello.$(MOD_EXT): \../hello.o \../hello_cpp.o$(LD) -o ../../../cpphello.$(MOD_EXT) ../hello.o ../hello_cpp.o -lstdc++ $(XLIBS) $(MODULE_XLIBS)$(STRIP) ../../../cpphello.$(MOD_EXT)depend:$(CC) $(CFLAGS) $(CPPFLAGS) -MM $(srcdir)/cpphello.c &gt; .dependclean:@rm -f .depend *.o *.$(MOD_EXT) *~distclean: clean#safety hash../cpphello.o: .././cpphello.mod/cpphello.c ../../../src/mod/module.h \ ../../../src/main.h ../../../src/lang.h ../../../src/eggdrop.h \ ../../../src/flags.h ../../../src/proto.h ../../../lush.h \ ../../../src/misc_file.h ../../../src/cmdt.h ../../../src/tclegg.h \ ../../../src/tclhash.h ../../../src/chan.h ../../../src/users.h \ ../../../src/compat/compat.h ../../../src/compat/inet_aton.h \ ../../../src/compat/snprintf.h \ ../../../src/compat/memset.h ../../../src/compat/memcpy.h \ ../../../src/compat/strcasecmp.h ../../../src/mod/modvals.h \ ../../../src/tandem.h</code></pre></div>Tested with eggdrop v1.6.17 and<div class="codebox"><p>Code: </p><pre><code>$ uname -aCYGWIN_NT-5.2 BETA 1.5.18(0.132/4/2) 2005-07-02 20:30 x86_64 unknown unknown Cygwin$ gcc -vReading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specsConfigured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug : (reconfigured)Thread model: posixgcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)</code></pre></div><br>Have fun!<br><br><br>Regards,<br>Kappa007<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6524">Kappa007</a> — Fri Jan 20, 2006 10:14 pm</p><hr />
]]></content>
	</entry>
	</feed>
