mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-23 02:22:31 +00:00
Make ChooseRandom more idiomatic, the fact that the code can return a SV of anytype makes it a bit dangerous, good canidate for rewriting as a plugin
This commit is contained in:
parent
db072e767a
commit
5e9bf3b044
@ -1618,11 +1618,12 @@ XS(XS__ChooseRandom) {
|
|||||||
if (items < 1)
|
if (items < 1)
|
||||||
Perl_croak(aTHX_ "Usage: quest::ChooseRandom(option1, option2, option3, option4, option5...[no limit])");
|
Perl_croak(aTHX_ "Usage: quest::ChooseRandom(option1, option2, option3, option4, option5...[no limit])");
|
||||||
|
|
||||||
|
dXSTARG;
|
||||||
int index = zone->random.Int(0, items - 1);
|
int index = zone->random.Int(0, items - 1);
|
||||||
|
SV *RETVAL = ST(index);
|
||||||
|
|
||||||
SV *tmp = ST(0);
|
XSprePUSH;
|
||||||
ST(0) = ST(index);
|
PUSHs(RETVAL);
|
||||||
ST(index) = tmp;
|
|
||||||
|
|
||||||
XSRETURN(1); //return 1 element from the stack (ST(0))
|
XSRETURN(1); //return 1 element from the stack (ST(0))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user