View Single Post
  #2  
Old 12-13-2013, 07:41 PM
quido
Fire Beetle
 
Join Date: Oct 2009
Posts: 16
Default

I tried getting this to work by putting all the functionality within the client class.

I added a public function InitiateEncounter in client.h with no return or parameters.

I added a dummy definition for InitiateEncounter in client.cpp.

In perl_client.cpp I copied, pasted, and modified what I thought was an appropriate XS routine:

Code:
XS(XS_Client_InitiateEncounter);
XS(XS_Client_InitiateEncounter)
{
	dXSARGS;
	if (items != 1)
		Perl_croak(aTHX_ "Usage: Client::InitiateEncounter(THIS)");
	{
		Client *		THIS;

		if (sv_derived_from(ST(0), "Client")) {
			IV tmp = SvIV((SV*)SvRV(ST(0)));
			THIS = INT2PTR(Client *,tmp);
		}
		else
			Perl_croak(aTHX_ "THIS is not of type Client");
		if(THIS == nullptr)
			Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");

		THIS->InitiateEncounter();
	}
	XSRETURN_EMPTY;
}
And I added my routine at the bottom of the list in perl_client.cpp
Code:
newXSproto(strcpy(buf, "InitiateEncounter"), XS_Client_InitiateEncounter, file, "$");

Then my script:
Code:
sub EVENT_COMBAT {
	if ($combat_state == 1)
	{
		quest::shout("you super stink!!!");
		quest::shout("you stink!!!");
		$client->InitiateEncounter();
		quest::shout("you so bad!!!");
	}
	else
	{
		quest::shout("eat me");
	}
}
What am I missing here?
Reply With Quote