Merge pull request #1214 from EQEmu/perl_item_macro

[Quest API] Perl Item Validation Macro
This commit is contained in:
Chris Miles 2021-02-01 23:17:05 -06:00 committed by GitHub
commit 91d9a4f73c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,19 @@
#undef THIS #undef THIS
#endif #endif
#define VALIDATE_THIS_IS_ITEM \
do { \
if (sv_derived_from(ST(0), "QuestItem")) { \
IV tmp = SvIV((SV*)SvRV(ST(0))); \
THIS = INT2PTR(EQ::ItemInstance*, tmp); \
} else { \
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance"); \
} \
if (THIS == nullptr) { \
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); \
} \
} while (0);
XS(XS_QuestItem_GetName); XS(XS_QuestItem_GetName);
XS(XS_QuestItem_GetName) { XS(XS_QuestItem_GetName) {
dXSARGS; dXSARGS;
@ -43,15 +56,7 @@ XS(XS_QuestItem_GetName) {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
Const_char *RETVAL; Const_char *RETVAL;
dXSTARG; dXSTARG;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
RETVAL = THIS->GetItem()->Name; RETVAL = THIS->GetItem()->Name;
sv_setpv(TARG, RETVAL); sv_setpv(TARG, RETVAL);
XSprePUSH; XSprePUSH;
@ -68,15 +73,7 @@ XS(XS_QuestItem_SetScale) {
{ {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
float Mult; float Mult;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
Mult = (float) SvNV(ST(1)); Mult = (float) SvNV(ST(1));
if (THIS->IsScaling()) { if (THIS->IsScaling()) {
@ -95,15 +92,7 @@ XS(XS_QuestItem_ItemSay) {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
Const_char *text; Const_char *text;
int lang = 0; int lang = 0;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
text = SvPV_nolen(ST(1)); text = SvPV_nolen(ST(1));
if (items == 3) if (items == 3)
lang = (int) SvUV(ST(2)); lang = (int) SvUV(ST(2));
@ -122,15 +111,7 @@ XS(XS_QuestItem_IsType) {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
bool RETVAL; bool RETVAL;
uint32 type = (int32) SvIV(ST(1)); uint32 type = (int32) SvIV(ST(1));
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
RETVAL = THIS->IsType((EQ::item::ItemClass) type); RETVAL = THIS->IsType((EQ::item::ItemClass) type);
ST(0) = boolSV(RETVAL); ST(0) = boolSV(RETVAL);
sv_2mortal(ST(0)); sv_2mortal(ST(0));
@ -146,15 +127,7 @@ XS(XS_QuestItem_IsAttuned) {
{ {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
bool RETVAL; bool RETVAL;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
RETVAL = THIS->IsAttuned(); RETVAL = THIS->IsAttuned();
ST(0) = boolSV(RETVAL); ST(0) = boolSV(RETVAL);
sv_2mortal(ST(0)); sv_2mortal(ST(0));
@ -171,15 +144,7 @@ XS(XS_QuestItem_GetCharges) {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
int16 RETVAL; int16 RETVAL;
dXSTARG; dXSTARG;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
RETVAL = THIS->GetCharges(); RETVAL = THIS->GetCharges();
XSprePUSH; XSprePUSH;
PUSHi((IV) RETVAL); PUSHi((IV) RETVAL);
@ -196,15 +161,7 @@ XS(XS_QuestItem_GetAugment) {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
int16 slot_id = (int16) SvIV(ST(1)); int16 slot_id = (int16) SvIV(ST(1));
EQ::ItemInstance *RETVAL; EQ::ItemInstance *RETVAL;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
RETVAL = THIS->GetAugment(slot_id); RETVAL = THIS->GetAugment(slot_id);
ST(0) = sv_newmortal(); ST(0) = sv_newmortal();
sv_setref_pv(ST(0), "QuestItem", (void *) RETVAL); sv_setref_pv(ST(0), "QuestItem", (void *) RETVAL);
@ -221,15 +178,7 @@ XS(XS_QuestItem_GetID) {
EQ::ItemInstance *THIS; EQ::ItemInstance *THIS;
uint32 RETVAL; uint32 RETVAL;
dXSTARG; dXSTARG;
VALIDATE_THIS_IS_ITEM;
if (sv_derived_from(ST(0), "QuestItem")) {
IV tmp = SvIV((SV *) SvRV(ST(0)));
THIS = INT2PTR(EQ::ItemInstance *, tmp);
} else
Perl_croak(aTHX_ "THIS is not of type EQ::ItemInstance");
if (THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
RETVAL = THIS->GetItem()->ID; RETVAL = THIS->GetItem()->ID;
XSprePUSH; XSprePUSH;
PUSHi((IV) RETVAL); PUSHi((IV) RETVAL);