| 1 |
MODULE = Atheme PACKAGE = Atheme::Command |
| 2 |
|
| 3 |
Atheme_Command |
| 4 |
create(SV * package, const char * name, const char * desc, SV * access, int maxparc, SV * help_path, SV * help_func, SV * handler) |
| 5 |
CODE: |
| 6 |
perl_command_t * newcmd = malloc(sizeof(perl_command_t)); |
| 7 |
newcmd->command.name = sstrdup(name); |
| 8 |
newcmd->command.desc = sstrdup(desc); |
| 9 |
newcmd->command.access = SvOK(access) ? sstrdup(SvPV_nolen(access)) : NULL; |
| 10 |
*(int*)&newcmd->command.maxparc = maxparc; |
| 11 |
newcmd->command.cmd = perl_command_handler; |
| 12 |
newcmd->command.help.path = SvOK(help_path) ? sstrdup(SvPV_nolen(help_path)) : NULL; |
| 13 |
|
| 14 |
if (SvOK(help_func)) |
| 15 |
newcmd->command.help.func = perl_command_help_func; |
| 16 |
|
| 17 |
if (!SvROK(handler)) |
| 18 |
Perl_croak(aTHX_ "Tried to create a command handler that's not a coderef"); |
| 19 |
|
| 20 |
SvREFCNT_inc(handler); |
| 21 |
newcmd->handler = handler; |
| 22 |
|
| 23 |
if (SvOK(help_func)) |
| 24 |
{ |
| 25 |
SvREFCNT_inc(help_func); |
| 26 |
newcmd->help_func = help_func; |
| 27 |
} |
| 28 |
else |
| 29 |
newcmd->help_func = NULL; |
| 30 |
|
| 31 |
RETVAL = newcmd; |
| 32 |
OUTPUT: |
| 33 |
RETVAL |
| 34 |
|
| 35 |
void |
| 36 |
DESTROY(Atheme_Command self) |
| 37 |
CODE: |
| 38 |
free((void*)self->command.name); |
| 39 |
free((void*)self->command.desc); |
| 40 |
free((void*)self->command.access); |
| 41 |
free((void*)self->command.help.path); |
| 42 |
|
| 43 |
SvREFCNT_dec(self->handler); |
| 44 |
if (self->help_func) |
| 45 |
SvREFCNT_dec(self->help_func); |
| 46 |
|
| 47 |
free(self); |