blib/lib/Language/Axbasic/Function.pm untested

filter: Statementstmt 0.0% 0 / 3117 Branchbran 0.0% 0 / 486 Conditioncond 0.0% 0 / 372 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 729 Podpod 0.0% 0 / 148 totaltotal 0.0% 0 / 4852 CC 244 SCAR 25.4
CC
244
Cov
0%
evaluate
156.0
evaluate
110.0
evaluate
90.0
CRAP 12.7
1 # Copyright (C) 2011-2021 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # Lesser Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Language::Axbasic::Function, based on Language::Basic by Amir Karger
16  
17 { package Language::Axbasic::Function;
18  
19 use strict;
20 use warnings;
21 use diagnostics;
22  
23 use Glib qw(TRUE FALSE);
24  
25 @Language::Axbasic::Function::ISA = qw(
26 Language::Axbasic
27 );
28  
29 # Sub-classes
30 {
31 package Language::Axbasic::Function::Intrinsic;
32 package Language::Axbasic::Function::Defined;
33 }
34  
35 ##################
36 # Constructors
37  
38 sub new {
39  
40 # Called by LA::Expression::Function->new
41 #
42 # Paraphrased from Language::Basic:
43 # The class that handles user-defined and intrinsic functions in Axbasic
44 #
45 # A Function can be either an intrinsic Axbasic function, like int() or chr$(), or a
46 # user-defined function, defined with the 'def' command (NB Unlike Language::Basic,
47 # user-defined functions don't have to begin with the letters FN)
48 # The ->checkArgs method checks that the right number and type of function arguments were
49 # specified
50 # The ->evaluate method actually calculates the value of the function, using any specified
51 # aguments
52 #
53 # ->new puts the function into LA::Script's function lookup table, as well as blessing the
54 # subclass into existence
55 #
56 # Expected arguments
57 # $scriptObj - Blessed reference of the parent LA::Script
58 # $funcName - The function's name
59 #
60 # Optional arguments
61 # $argTypeString - (When called by LA::Function::Intrinsic->initialise) the value for
62 # $self->argTypeString
63 #
64 # Return values
65 # 'undef' on improper arguments
66 # Blessed reference to the newly-created object (blessed into the function subclass) on
67 # success
68  
69 my ($class, $scriptObj, $funcName, $argTypeString, $check) = @_;
70  
71 # Local variables
72 my ($type, $subClass);
73  
74 # Check for improper arguments
75 if (! defined $class || ! defined $scriptObj || ! defined $funcName || defined $check) {
76  
77 return $axmud::CLIENT->writeImproper($class . '->new', @_);
78 }
79  
80 # Setup
81 my $self = {
82 _objName => $class, # Name Axbasic objects after their class
83 _objClass => $class,
84 _parentFile => undef, # No parent file object
85 _parentWorld => undef, # No parent file object
86 _privFlag => TRUE, # All IVs are private
87  
88 # Perl object components
89 # ----------------------
90  
91 # The parent LA::Script
92 scriptObj => $scriptObj,
93  
94 # IVs
95 # ---
96  
97 # Name of the function
98 funcName => $funcName,
99 # What type of function this is: 'string' or 'numeric'
100 funcType => undef, # Set below
101 # A string, listing the number and type of arguments the function takes. If a function
102 # takes a String and two Numeric arguments, the string will be 'SNN'. A semicolon
103 # separates required from optional arguments
104 # For intrinsic functions, set by ->initialise. For user-defined functions, set by
105 # ->declare
106 argTypeString => $argTypeString,
107 # For user-defined functions, a list of LA::Variable::Lvalues (set by ->declare); an
108 # empty list for intrinsic functions
109 argList => [],
110 # For user-defined functions, an expression which defines the function ('undef' for
111 # intrinsic functions). Set by LA::Statement::def->parse
112 defFuncExp => undef,
113 };
114  
115 # Put this function in LA::Script's lookup table. (If a function with the same name already
116 # exists - even if it is an intrinsic function - the old function is overwritten)
117 $scriptObj->add_funcName($funcName, $self);
118  
119 # If the function name ends with a $, it's a string function, otherwise it's a numeric
120 # function
121 if ($funcName =~ /\$$/) {
122 $type = 'String';
123 } else {
124 $type = 'Numeric';
125 }
126  
127 $self->{'funcType'} = lc($type);
128  
129 # Create the subclass object and return it
130 if ($class =~ m/Language::Axbasic::Function::Defined/) {
131  
132 # User-defined functions
133 $subClass = $class . '::' . $type;
134 bless $self, $subClass;
135  
136 } else {
137  
138 # Intrinsic functions
139 bless $self, $class;
140 }
141 }
142  
143 ##################
144 # Methods
145  
146 sub checkArgs {
147  
148 # Called by LA::Expression::Function->new
149 # Given an LA::Expression::ArgList object, checks the arguments to make sure they are of the
150 # correct number and type
151 # NB unlike the original Language::Basic, we give up at the first error
152 #
153 # Expected arguments
154 # $argListObj - A LA::Expression::ArgList object containing the argument list
155 #
156 # Return values
157 # 'undef' on improper arguments, or if there's an error
158 # 1 if the arguments check out
159  
160 my ($self, $argListObj, $check) = @_;
161  
162 # Local variables
163 my (
164 $typeString, $min, $max,
165 @args,
166 );
167  
168 # Check for improper arguments
169 if (! defined $argListObj || defined $check) {
170  
171 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkArgs', @_);
172 }
173  
174 # Import the argument list from the LA::Expression::ArgList object
175 @args = $argListObj->argList;
176  
177 # Import this function's argument type string
178 $typeString = $self->argTypeString;
179 # From the type string, set the minimum and maximum number of arguments
180 if ($typeString =~ s/(.*);/$1/) {
181 $min = length($1); # Optional arguments
182 } else {
183 $min = length($typeString); # No optional arguments
184 }
185  
186 $max = length($typeString);
187  
188 if (scalar @args < $min || scalar @args > $max) {
189  
190 return $self->scriptObj->setError(
191 'wrong_number_of_arguments',
192 $self->_objClass . '->checkArgs',
193 );
194 }
195  
196 # Check each argument type in turn
197 OUTER: foreach my $type (split (m//, $typeString)) {
198  
199 my ($arg, $argType);
200  
201 $arg = shift @args;
202 if (! defined $arg) {
203  
204 # There may not be any optional args
205 last OUTER;
206 }
207  
208 if (! (ref($arg) =~ m/(String|Numeric)$/)) {
209  
210 return $self->scriptObj->setDebug(
211 'Improbable error in Language::Axbasic::Function::Defined->checkArgs',
212 $self->_objClass . '->checkArgs',
213 );
214  
215 } else {
216  
217 $argType = substr($1, 0, 1);
218 }
219  
220 if ($argType ne $type) {
221  
222 if ($type eq 'N') {
223  
224 return $self->scriptObj->setError(
225 'function_expected_numeric_argument_but_received_string',
226 $self->_objClass . '->checkArgs',
227 );
228  
229 } else {
230  
231 return $self->scriptObj->setError(
232 'function_expecteds_string_argument_but_received_numeric',
233 $self->_objClass . '->checkArgs',
234 );
235 }
236 }
237 }
238  
239 # All the arguments check out
240 return 1;
241 }
242  
243 ##################
244 # Accessors - set
245  
246 sub set_defFuncExp {
247  
248 # Returns 'undef' on improper arguments
249 # Returns 1 on success
250  
251 my ($self, $expression, $check) = @_;
252  
253 # Check for improper arguments
254 if (! defined $expression || defined $check) {
255  
256 return $axmud::CLIENT->writeImproper(
257 $self->_objClass . '->set_defFuncExp',
258 @_,
259 );
260 }
261  
262 # Update IVs
263 $self->ivPoke('defFuncExp', $expression);
264  
265 return 1;
266 }
267  
268 ##################
269 # Accessors - get
270  
271 sub scriptObj
272 { $_[0]->{scriptObj} }
273  
274 sub funcName
275 { $_[0]->{funcName} }
276 sub funcType
277 { $_[0]->{funcType} }
278 sub argTypeString
279 { $_[0]->{argTypeString} }
280 sub argList
281 { my $self = shift; return @{$self->{argList}}; }
282 sub defFuncExp
283 { $_[0]->{defFuncExp} }
284 }
285  
286 { package Language::Axbasic::Function::Intrinsic;
287  
288 use strict;
289 use warnings;
290 use diagnostics;
291  
292 use Glib qw(TRUE FALSE);
293  
294 @Language::Axbasic::Function::Intrinsic::ISA = qw(
295 Language::Axbasic::Function
296 );
297  
298 ##################
299 # Constructors
300  
301 sub initialise {
302  
303 # Called by LA::Script->new
304 # Sets up Axbasic's intrinsic (pre-defined) functions and creates entries for each function
305 # in LA::Script's function lookup table
306 #
307 # Expected arguments:
308 # $scriptObj - Blessed reference of the parent LA::Script
309 #
310 # Return values:
311 # 'undef' on improper arguments, or if there is an error
312 # 1 otherwise
313  
314 my ($class, $scriptObj, $check) = @_;
315  
316 # Local variables
317 my (
318 $subClass, $string,
319 @funcList,
320 %funcHash,
321 );
322  
323 # Check for improper arguments
324 if (! defined $scriptObj || defined $check) {
325  
326 return $axmud::CLIENT->writeImproper($class . '->initialise', @_);
327 }
328  
329 # Import the pre-defined function hash, which states which arguments are required for each
330 # function
331 %funcHash = $scriptObj->funcArgHash;
332  
333 # Create each function in turn
334 foreach my $funcName (keys %funcHash) {
335  
336 if (! ($funcName =~ m/\$$/)) {
337  
338 $subClass = 'Language::Axbasic::Function::Intrinsic::Numeric::' . $funcName;
339  
340 } else {
341  
342 $string = $funcName;
343 $string =~ s/\$$//;
344 $subClass = 'Language::Axbasic::Function::Intrinsic::String::' . $string;
345 }
346  
347 if (! $subClass->new($scriptObj, $funcName, $funcHash{$funcName})) {
348  
349 return $scriptObj->setDebug(
350 'Can\'t set up intrinsic function ' . $funcName . '\'',
351 $class . '->initialise',
352 );
353 }
354 }
355  
356 # Initialisation complete
357 return 1;
358 }
359  
360 ##################
361 # Methods
362  
363 ##################
364 # Accessors - set
365  
366 ##################
367 # Accessors - get
368 }
369  
370 { package Language::Axbasic::Function::Intrinsic::String;
371  
372 use strict;
373 use warnings;
374 use diagnostics;
375  
376 use Glib qw(TRUE FALSE);
377  
378 @Language::Axbasic::Function::Intrinsic::String::ISA = qw(
379 Language::Axbasic::Function::Intrinsic
380 Language::Axbasic::Function::String
381 );
382 }
383  
384 { package Language::Axbasic::Function::Intrinsic::Numeric;
385  
386 use strict;
387 use warnings;
388 use diagnostics;
389  
390 use Glib qw(TRUE FALSE);
391  
392 @Language::Axbasic::Function::Intrinsic::Numeric::ISA = qw(
393 Language::Axbasic::Function::Intrinsic
394 Language::Axbasic::Function::Numeric
395 );
396 }
397  
398 { package Language::Axbasic::Function::Defined;
399  
400 use strict;
401 use warnings;
402 use diagnostics;
403  
404 use Glib qw(TRUE FALSE);
405  
406 @Language::Axbasic::Function::Defined::ISA = qw(
407 Language::Axbasic::Function
408 );
409  
410 # Paraphrased from Language::Basic
411 # This class handles functions defined by the user in 'def' statements
412  
413 ##################
414 # Constructors
415  
416 ##################
417 # Methods
418  
419 sub declare {
420  
421 # Called by LA::Expression::Function->new
422 # Declares how many arguments, and of which type, the newly-defined function should expect.
423 # Sets the IVs $self->argTypeString and $self->argListObj
424 #
425 # Expected arguments
426 # @argList - A list of LA::Variable::Lvalue objects which are the arguments to the
427 # function (e.g., x in 'def myfunc(x)')
428 #
429 # Return values
430 # 'undef' on improper arguments
431 # 1 on success
432  
433 my ($self, @argList) = @_;
434  
435 # Local variables
436 my $argTypeString;
437  
438 # (No improper arguments to check)
439  
440 foreach my $arg (@argList) {
441  
442 my $class = ref($arg);
443  
444 if (! ($class =~ /(String|Numeric)$/)) {
445  
446 return $self->scriptObj->setDebug('Type error', $self->_objClass . '->declare');
447  
448 } else {
449  
450 # $argTypeString is a string made up of S (for String) or N (Numeric) characters in
451 # sequence, showing the Axbasic function's expected argument types
452 $argTypeString .= substr($1, 0, 1);
453 }
454 }
455  
456 # Set IVs
457 $self->ivPoke('argTypeString', $argTypeString);
458 $self->ivPoke('argList', @argList);
459  
460 return 1;
461 }
462  
463 sub evaluate {
464  
465 # Called by LA::Expression::Function->evaluate
466 # Actually evaluate the function with the specified arguments
467 #
468 # Paraphrased from Language::Basic:
469 # Set each parameter (in the ->variables IV) to the value given in the arguments, then
470 # evaluate the expression
471 # Just in case the user has a fn(x) and uses x elsewhere in the script, save the value of x
472 # just before we set x based on the argument (this is a poor man's version of variable
473 # scoping)
474 #
475 # Expected arguments
476 # @args - The arguments with which to evaluate the function
477 #
478 # Return values
479 # 'undef' on improper arguments, or if the ->defFuncExp IV is not defined
480 # Otherwise returns the value of the function
481  
482 my ($self, @args) = @_;
483  
484 # Local variables
485 my (
486 $varObj, $returnValue,
487 @lvalueList, @saveVars,
488 );
489  
490 # (No improper arguments to check)
491  
492 # Check the function has been defined (no reason why it shouldn't have been)
493 if (! defined $self->defFuncExp) {
494  
495 return $self->scriptObj->setError(
496 'function_not_defined',
497 $self->_objClass . '->evaluate',
498 );
499 }
500  
501 # Import the list of LA::Variable::Lvalues objects, which are the arguments to the function
502 # (e.g., x in 'def myfunc(x)')
503 @lvalueList = $self->argList;
504  
505 # Process the list of LA::Variable::Lvalues objects, which are the arguments to the function
506 # (e.g., x in 'def myfunc(x)')
507 foreach my $lvalue (@lvalueList) {
508  
509 # Get a blessed reference to a variable object. If it's a scalar, returns that object;
510 # if it's an array, returns the object specified by the argument list (e.g. the value
511 # of array(5,6) )
512 $varObj = $lvalue->variable;
513  
514 # Save the value of the variable, so we can give the variable a temporary value, and
515 # restore the old value afterwards
516 push (@saveVars, $varObj->value);
517 $varObj->set(shift @args);
518 }
519  
520 # Evaluate the expression that defines the function
521 $returnValue = $self->defFuncExp->evaluate();
522 if (! defined $returnValue) {
523  
524 return undef;
525 }
526  
527 # Now restore the values of the variable objects that we changed a few moments ago
528 foreach my $lvalue (@lvalueList) {
529  
530 $varObj = $lvalue->variable;
531 $varObj->set(shift @saveVars);
532 }
533  
534 # Return the value of the function
535 return $returnValue;
536 }
537  
538 ##################
539 # Accessors - set
540  
541 ##################
542 # Accessors - get
543 }
544  
545 { package Language::Axbasic::Function::Defined::String;
546  
547 use strict;
548 use warnings;
549 use diagnostics;
550  
551 use Glib qw(TRUE FALSE);
552  
553 @Language::Axbasic::Function::Defined::String::ISA = qw(
554 Language::Axbasic::Function::Defined
555 Language::Axbasic::Function::String
556 );
557 }
558  
559 { package Language::Axbasic::Function::Defined::Numeric;
560  
561 use strict;
562 use warnings;
563 use diagnostics;
564  
565 use Glib qw(TRUE FALSE);
566  
567 @Language::Axbasic::Function::Defined::Numeric::ISA = qw(
568 Language::Axbasic::Function::Defined
569 Language::Axbasic::Function::Numeric
570 );
571 }
572  
573 { package Language::Axbasic::Function::String;
574  
575 use strict;
576 use warnings;
577 use diagnostics;
578  
579 use Glib qw(TRUE FALSE);
580  
581 @Language::Axbasic::Function::String::ISA = qw(
582 Language::Axbasic::Function
583 Language::Axbasic::String
584 );
585 }
586  
587 { package Language::Axbasic::Function::Numeric;
588  
589 use strict;
590 use warnings;
591 use diagnostics;
592  
593 use Glib qw(TRUE FALSE);
594  
595 @Language::Axbasic::Function::Numeric::ISA = qw(
596 Language::Axbasic::Function
597 Language::Axbasic::Numeric
598 );
599 }
600  
601 ### Pure BASIC functions (numeric) ###
602  
603 { package Language::Axbasic::Function::Intrinsic::Numeric::abs;
604  
605 use strict;
606 use warnings;
607 use diagnostics;
608  
609 use Glib qw(TRUE FALSE);
610  
611 @Language::Axbasic::Function::Intrinsic::Numeric::abs::ISA = qw(
612 Language::Axbasic::Function::Intrinsic::Numeric
613 );
614  
615 # Abs (x)
616  
617 ##################
618 # Methods
619  
620 sub evaluate {
621  
622 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
623 #
624 # Expected arguments
625 # $arg - The first (and only) argument in the argument list
626 #
627 # Return values
628 # The return value of the function
629  
630 my ($self, $arg) = @_;
631  
632 # (No improper arguments to check)
633  
634 # Evaluate the function and return the value
635 return abs($arg);
636 }
637 }
638  
639 { package Language::Axbasic::Function::Intrinsic::Numeric::acos;
640  
641 use strict;
642 use warnings;
643 use diagnostics;
644  
645 use Glib qw(TRUE FALSE);
646  
647 @Language::Axbasic::Function::Intrinsic::Numeric::acos::ISA = qw(
648 Language::Axbasic::Function::Intrinsic::Numeric
649 );
650  
651 # Acos (x)
652  
653 ##################
654 # Methods
655  
656 sub evaluate {
657  
658 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
659 #
660 # Expected arguments
661 # $arg - The first (and only) argument in the argument list
662 #
663 # Return values
664 # The return value of the function
665  
666 my ($self, $arg) = @_;
667  
668 # Local variables
669 my $value;
670  
671 # (No improper arguments to check)
672  
673 # Evaluate the function and return the value
674 $value = Math::Trig::acos($arg);
675  
676 # $value is in radians by default. Convert to degrees, if required
677 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
678  
679 $value = Math::Trig::rad2deg($value);
680 }
681  
682 return $value;
683 }
684 }
685  
686 { package Language::Axbasic::Function::Intrinsic::Numeric::angle;
687  
688 use strict;
689 use warnings;
690 use diagnostics;
691  
692 use Glib qw(TRUE FALSE);
693  
694 @Language::Axbasic::Function::Intrinsic::Numeric::angle::ISA = qw(
695 Language::Axbasic::Function::Intrinsic::Numeric
696 );
697  
698 # Angle (x, y)
699  
700 ##################
701 # Methods
702  
703 sub evaluate {
704  
705 # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN')
706 #
707 # Expected arguments
708 # @args - The list of arguments supplied to the function
709 #
710 # Return values
711 # The return value of the function
712  
713 my ($self, @args) = @_;
714  
715 # Local variables
716 my ($arctan, $value);
717  
718 # (No improper arguments to check)
719  
720 # Evaluate the function and return the value
721  
722 # Check that both arguments are non-zero numbers
723 if (! $args[0] && ! $args[1]) {
724  
725 return $self->scriptObj->setError(
726 'invalid_matching_arguments',
727 $self->_objClass . '->evaluate',
728 );
729 }
730  
731 # We give a range of angles, in radians, equivalent to -180o < @ <= 180
732 # Use the arctan function to find the angle of the tangent, since we have both the opposite
733 # ($args[1]) and the adjacent ($args[0])
734  
735 # First deal with special cases (so we don't divide by 0)
736 if (! $args[0]) {
737  
738 if ($args[1] > 0) {
739 $value = Math::Trig::deg2rad(90);
740 } else {
741 $value = Math::Trig::deg2rad(-90);
742 }
743  
744 } elsif (! $args[1]) {
745  
746 if ($args[0] > 0) {
747 $value = Math::Trig::deg2rad(0);
748 } else {
749 $value = Math::Trig::deg2rad(180);
750 }
751  
752 } else {
753  
754 $arctan = Math::Trig::atan($args[1] / $args[0]);
755  
756 # Otherwise, tan is opposite / adjacent...
757 if ($args[0] > 0 && $args[1] > 0) {
758  
759 $value = $arctan;
760  
761 } elsif ($args[0] < 0 && $args[1] > 0) {
762  
763 $value = Math::Trig::deg2rad(180) + $arctan;
764  
765 } elsif ($args[0] < 0 && $args[1] < 0) {
766  
767 $value = Math::Trig::deg2rad(-180) + $arctan;
768  
769 } else {
770  
771 $value = $arctan;
772 }
773 }
774  
775 # Convert from radians to degrees, if required
776 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
777  
778 $value = Math::Trig::rad2deg($value);
779 }
780  
781 return $value;
782 }
783 }
784  
785 { package Language::Axbasic::Function::Intrinsic::Numeric::asc;
786  
787 use strict;
788 use warnings;
789 use diagnostics;
790  
791 use Glib qw(TRUE FALSE);
792  
793 @Language::Axbasic::Function::Intrinsic::Numeric::asc::ISA = qw(
794 Language::Axbasic::Function::Intrinsic::Numeric
795 );
796  
797 # Asc (string)
798  
799 ##################
800 # Methods
801  
802 sub evaluate {
803  
804 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
805 #
806 # Expected arguments
807 # $arg - The first (and only) argument in the argument list
808 #
809 # Return values
810 # The return value of the function
811  
812 my ($self, $arg) = @_;
813  
814 # Local variables
815 my $value;
816  
817 # (No improper arguments to check)
818  
819 # Evaluate the function and return the value
820 $value = ord($arg);
821  
822 if ($value < 0 || $value > 127) {
823  
824 return $self->scriptObj->setError(
825 'character_STRING_out_of_range',
826 $self->_objClass . '->evaluate',
827 'STRING', $arg,
828 );
829  
830 } else {
831  
832 return $value;
833 }
834 }
835 }
836  
837 { package Language::Axbasic::Function::Intrinsic::Numeric::asin;
838  
839 use strict;
840 use warnings;
841 use diagnostics;
842  
843 use Glib qw(TRUE FALSE);
844  
845 @Language::Axbasic::Function::Intrinsic::Numeric::asin::ISA = qw(
846 Language::Axbasic::Function::Intrinsic::Numeric
847 );
848  
849 # Asin (x)
850  
851 ##################
852 # Methods
853  
854 sub evaluate {
855  
856 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
857 #
858 # Expected arguments
859 # $arg - The first (and only) argument in the argument list
860 #
861 # Return values
862 # The return value of the function
863  
864 my ($self, $arg) = @_;
865  
866 # Local variables
867 my $value;
868  
869 # (No improper arguments to check)
870  
871 # Evaluate the function and return the value
872 $value = Math::Trig::asin($arg);
873  
874 # $value is in radians by default. Convert to degrees, if required
875 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
876  
877 $value = Math::Trig::rad2deg($value);
878 }
879  
880 return $value;
881 }
882 }
883  
884 { package Language::Axbasic::Function::Intrinsic::Numeric::atn;
885  
886 use strict;
887 use warnings;
888 use diagnostics;
889  
890 use Glib qw(TRUE FALSE);
891  
892 @Language::Axbasic::Function::Intrinsic::Numeric::atn::ISA = qw(
893 Language::Axbasic::Function::Intrinsic::Numeric
894 );
895  
896 # Atn (x)
897  
898 ##################
899 # Methods
900  
901 sub evaluate {
902  
903 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
904 #
905 # Expected arguments
906 # $arg - The first (and only) argument in the argument list
907 #
908 # Return values
909 # The return value of the function
910  
911 my ($self, $arg) = @_;
912  
913 # Local variables
914 my $value;
915  
916 # (No improper arguments to check)
917  
918 # Evaluate the function and return the value
919 $value = Math::Trig::atan($arg);
920  
921 # $value is in radians by default. Convert to degrees, if required
922 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
923  
924 $value = Math::Trig::rad2deg($value);
925 }
926  
927 return $value;
928 }
929 }
930  
931 { package Language::Axbasic::Function::Intrinsic::Numeric::ceil;
932  
933 use strict;
934 use warnings;
935 use diagnostics;
936  
937 use Glib qw(TRUE FALSE);
938  
939 @Language::Axbasic::Function::Intrinsic::Numeric::ceil::ISA = qw(
940 Language::Axbasic::Function::Intrinsic::Numeric
941 );
942  
943 # Ceil (x)
944  
945 ##################
946 # Methods
947  
948 sub evaluate {
949  
950 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
951 #
952 # Expected arguments
953 # $arg - The first (and only) argument in the argument list
954 #
955 # Return values
956 # The return value of the function
957  
958 my ($self, $arg) = @_;
959  
960 # (No improper arguments to check)
961  
962 # Evaluate the function and return the value
963 return POSIX::ceil($arg);
964 }
965 }
966  
967 { package Language::Axbasic::Function::Intrinsic::Numeric::cos;
968  
969 use strict;
970 use warnings;
971 use diagnostics;
972  
973 use Glib qw(TRUE FALSE);
974  
975 @Language::Axbasic::Function::Intrinsic::Numeric::cos::ISA = qw(
976 Language::Axbasic::Function::Intrinsic::Numeric
977 );
978  
979 # Cos (x)
980  
981 ##################
982 # Methods
983  
984 sub evaluate {
985  
986 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
987 #
988 # Expected arguments
989 # $arg - The first (and only) argument in the argument list
990 #
991 # Return values
992 # The return value of the function
993  
994 my ($self, $arg) = @_;
995  
996 # (No improper arguments to check)
997  
998 # Evaluate the function and return the value
999  
1000 # Use radians (default) or degrees?
1001 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
1002  
1003 # Convert to radians
1004 $arg = Math::Trig::deg2rad($arg);
1005 }
1006  
1007 # Evaluate the function and return the value
1008 return cos($arg);
1009 }
1010 }
1011  
1012 { package Language::Axbasic::Function::Intrinsic::Numeric::cosh;
1013  
1014 use strict;
1015 use warnings;
1016 use diagnostics;
1017  
1018 use Glib qw(TRUE FALSE);
1019  
1020 @Language::Axbasic::Function::Intrinsic::Numeric::cosh::ISA = qw(
1021 Language::Axbasic::Function::Intrinsic::Numeric
1022 );
1023  
1024 # Cosh (x)
1025  
1026 ##################
1027 # Methods
1028  
1029 sub evaluate {
1030  
1031 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1032 #
1033 # Expected arguments
1034 # $arg - The first (and only) argument in the argument list
1035 #
1036 # Return values
1037 # The return value of the function
1038  
1039 my ($self, $arg) = @_;
1040  
1041 # (No improper arguments to check)
1042  
1043 # Evaluate the function and return the value
1044 return Math::Trig::cosh($arg);
1045 }
1046 }
1047  
1048 { package Language::Axbasic::Function::Intrinsic::Numeric::cot;
1049  
1050 use strict;
1051 use warnings;
1052 use diagnostics;
1053  
1054 use Glib qw(TRUE FALSE);
1055  
1056 @Language::Axbasic::Function::Intrinsic::Numeric::cot::ISA = qw(
1057 Language::Axbasic::Function::Intrinsic::Numeric
1058 );
1059  
1060 # Cot (x)
1061  
1062 ##################
1063 # Methods
1064  
1065 sub evaluate {
1066  
1067 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1068 #
1069 # Expected arguments
1070 # $arg - The first (and only) argument in the argument list
1071 #
1072 # Return values
1073 # The return value of the function
1074  
1075 my ($self, $arg) = @_;
1076  
1077 # Local variables
1078 my $value;
1079  
1080 # (No improper arguments to check)
1081  
1082 # Evaluate the function and return the value
1083  
1084 # The value of $arg cannot be 0 (because this would cause division by 0)
1085 if (! $arg) {
1086  
1087 return $self->scriptObj->setError(
1088 'number_NUM_out_of_range',
1089 $self->_objClass . '->evaluate',
1090 'NUM', $arg,
1091 );
1092 }
1093  
1094 # Use radians (default) or degrees?
1095 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
1096  
1097 # Convert to radians
1098 $arg = Math::Trig::deg2rad($arg);
1099 }
1100  
1101 # Evaluate the function and return the value
1102 return Math::Trig::cot($arg);
1103 }
1104 }
1105  
1106 { package Language::Axbasic::Function::Intrinsic::Numeric::cpos;
1107  
1108 use strict;
1109 use warnings;
1110 use diagnostics;
1111  
1112 use Glib qw(TRUE FALSE);
1113  
1114 @Language::Axbasic::Function::Intrinsic::Numeric::cpos::ISA = qw(
1115 Language::Axbasic::Function::Intrinsic::Numeric
1116 );
1117  
1118 # Cpos (string, substring)
1119 # Cpos (string, substring, n)
1120  
1121 ##################
1122 # Methods
1123  
1124 sub evaluate {
1125  
1126 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N')
1127 #
1128 # Expected arguments
1129 # $string, $subString, $position
1130 # - The list of arguments supplied to the function
1131 #
1132 # Return values
1133 # The return value of the function
1134  
1135 my ($self, $string, $subString, $posn) = @_;
1136  
1137 # Local variables
1138 my (
1139 $result,
1140 @charList,
1141 );
1142  
1143 # (No improper arguments to check)
1144  
1145 # Evaluate the function and return the value
1146 if (defined $posn) {
1147  
1148 # $posn must not be zero or a negative number
1149 if ($posn < 1) {
1150  
1151 return $self->scriptObj->setError(
1152 'number_NUM_out_of_range',
1153 $self->_objClass . '->evaluate',
1154 'NUM', $posn,
1155 );
1156 }
1157  
1158 # $posn must be rounded
1159 $posn = substr(
1160 $posn + 0.5,
1161 0,
1162 length(int($posn + 0.5)),
1163 );
1164  
1165 # Finally, Perl's index() function uses the number 0 for the first character in the
1166 # string, but True BASIC uses the number 1
1167 $posn--;
1168 }
1169  
1170 # If either string is a null string, True BASIC returns 0
1171 if (! $string || ! $subString) {
1172  
1173 return 0;
1174 }
1175  
1176 # Evaluate the function for each character in $subString
1177 @charList = split(//, $subString);
1178 foreach my $char (@charList) {
1179  
1180 if (defined $posn) {
1181 $result = index($string, $char, $posn);
1182 } else {
1183 $result = index($string, $char);
1184 }
1185  
1186 if ($result != -1) {
1187  
1188 # Look for 'g' in 'disgust' - Perl returns 3, but True BASIC returns 4
1189 return ($result + 1);
1190 }
1191 }
1192  
1193 # No character in the substring was found in the string
1194 return 0;
1195 }
1196 }
1197  
1198 { package Language::Axbasic::Function::Intrinsic::Numeric::cposr;
1199  
1200 use strict;
1201 use warnings;
1202 use diagnostics;
1203  
1204 use Glib qw(TRUE FALSE);
1205  
1206 @Language::Axbasic::Function::Intrinsic::Numeric::cposr::ISA = qw(
1207 Language::Axbasic::Function::Intrinsic::Numeric
1208 );
1209  
1210 # Cposr (string, substring)
1211 # Cposr (string, substring, n)
1212  
1213 ##################
1214 # Methods
1215  
1216 sub evaluate {
1217  
1218 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N')
1219 #
1220 # Expected arguments
1221 # $string, $subString, $posn
1222 # - The list of arguments supplied to the function
1223 #
1224 # Return values
1225 # The return value of the function
1226  
1227 my ($self, $string, $subString, $posn) = @_;
1228  
1229 # Local variables
1230 my (
1231 $result,
1232 @charList,
1233 );
1234  
1235 # (No improper arguments to check)
1236  
1237 # Evaluate the function and return the value
1238 if (defined $posn) {
1239  
1240 # $posn must not be zero or a negative number
1241 if ($posn < 1) {
1242  
1243 return $self->scriptObj->setError(
1244 'number_NUM_out_of_range',
1245 $self->_objClass . '->evaluate',
1246 'NUM', $posn,
1247 );
1248 }
1249  
1250 # $posn must be rounded
1251 $posn = substr(
1252 $posn + 0.5,
1253 0,
1254 length(int($posn + 0.5)),
1255 );
1256  
1257 # Finally, Perl's index() function uses the number 0 for the first character in the
1258 # string, but True BASIC uses the number 1
1259 $posn--;
1260 }
1261  
1262 # If either string is a null string, True BASIC returns 0
1263 if (! $string || ! $subString) {
1264  
1265 return 0;
1266 }
1267  
1268 # Evaluate the function for each character in $subString
1269 @charList = split(//, $subString);
1270 foreach my $char (@charList) {
1271  
1272 if (defined $posn) {
1273 $result = rindex($string, $char, $posn);
1274 } else {
1275 $result = rindex($string, $char);
1276 }
1277  
1278 if ($result != -1) {
1279  
1280 # Look for 'g' in 'disgust' - Perl returns 3, but True BASIC returns 4
1281 return ($result + 1);
1282 }
1283 }
1284  
1285 # No character in the substring was found in the string
1286 return 0;
1287 }
1288 }
1289  
1290 { package Language::Axbasic::Function::Intrinsic::Numeric::csc;
1291  
1292 use strict;
1293 use warnings;
1294 use diagnostics;
1295  
1296 use Glib qw(TRUE FALSE);
1297  
1298 @Language::Axbasic::Function::Intrinsic::Numeric::csc::ISA = qw(
1299 Language::Axbasic::Function::Intrinsic::Numeric
1300 );
1301  
1302 # Csc (x)
1303  
1304 ##################
1305 # Methods
1306  
1307 sub evaluate {
1308  
1309 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1310 #
1311 # Expected arguments
1312 # $arg - The first (and only) argument in the argument list
1313 #
1314 # Return values
1315 # The return value of the function
1316  
1317 my ($self, $arg) = @_;
1318  
1319 # (No improper arguments to check)
1320  
1321 # Evaluate the function and return the value
1322  
1323 # The value of $arg cannot be 0 (because this would cause division by 0)
1324 if (! $arg) {
1325  
1326 return $self->scriptObj->setError(
1327 'number_NUM_out_of_range',
1328 $self->_objClass . '->evaluate',
1329 'NUM', $arg,
1330 );
1331 }
1332  
1333 # Use radians (default) or degrees?
1334 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
1335  
1336 # Convert to radians
1337 $arg = Math::Trig::deg2rad($arg);
1338 }
1339  
1340 # Evaluate the function and return the value
1341 return Math::Trig::csc($arg);
1342 }
1343 }
1344  
1345 { package Language::Axbasic::Function::Intrinsic::Numeric::date;
1346  
1347 use strict;
1348 use warnings;
1349 use diagnostics;
1350  
1351 use Glib qw(TRUE FALSE);
1352  
1353 @Language::Axbasic::Function::Intrinsic::Numeric::date::ISA = qw(
1354 Language::Axbasic::Function::Intrinsic::Numeric
1355 );
1356  
1357 # Date ()
1358  
1359 ##################
1360 # Methods
1361  
1362 sub evaluate {
1363  
1364 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
1365 #
1366 # Expected arguments
1367 # $arg - The first (and only) argument in the argument list
1368 #
1369 # Return values
1370 # The return value of the function
1371  
1372 my ($self, $arg) = @_;
1373  
1374 # (No improper arguments to check)
1375  
1376 # Evaluate the function and return the value
1377  
1378 # Get the time and date
1379 my (
1380 $second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear,
1381 $daylightSavings,
1382 ) = localtime();
1383  
1384 # Return a value in the form YYDDD, where YY is in the range 00-99, and DDD is in the
1385 # range 1-365
1386 return (sprintf("%02d", $yearOffset % 100) . ($dayOfYear + 1));
1387 }
1388 }
1389  
1390 { package Language::Axbasic::Function::Intrinsic::Numeric::deg;
1391  
1392 use strict;
1393 use warnings;
1394 use diagnostics;
1395  
1396 use Glib qw(TRUE FALSE);
1397  
1398 @Language::Axbasic::Function::Intrinsic::Numeric::deg::ISA = qw(
1399 Language::Axbasic::Function::Intrinsic::Numeric
1400 );
1401  
1402 # Deg (x)
1403  
1404 ##################
1405 # Methods
1406  
1407 sub evaluate {
1408  
1409 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1410 #
1411 # Expected arguments
1412 # $arg - The first (and only) argument in the argument list
1413 #
1414 # Return values
1415 # The return value of the function
1416  
1417 my ($self, $arg) = @_;
1418  
1419 # (No improper arguments to check)
1420  
1421 # Evaluate the function and return the value
1422 return Math::Trig::rad2deg($arg);
1423 }
1424 }
1425  
1426 { package Language::Axbasic::Function::Intrinsic::Numeric::eof;
1427  
1428 use strict;
1429 use warnings;
1430 use diagnostics;
1431  
1432 use Glib qw(TRUE FALSE);
1433  
1434 @Language::Axbasic::Function::Intrinsic::Numeric::eof::ISA = qw(
1435 Language::Axbasic::Function::Intrinsic::Numeric
1436 );
1437  
1438 # Eof (channel)
1439  
1440 ##################
1441 # Methods
1442  
1443 sub evaluate {
1444  
1445 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1446 #
1447 # Expected arguments
1448 # $arg - The first (and only) argument in the argument list
1449 #
1450 # Return values
1451 # The return value of the function
1452  
1453 my ($self, $arg) = @_;
1454  
1455 # Local variables
1456 my $channelObj;
1457  
1458 # (No improper arguments to check)
1459  
1460 # Evaluate the function and return the value
1461  
1462 # Check that the file channel exists
1463 if (! $self->scriptObj->ivExists('fileChannelHash', $arg)) {
1464  
1465 # File channel not open
1466 return 0;
1467  
1468 } else {
1469  
1470 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $arg);
1471  
1472 if (eof($channelObj->fileHandle)) {
1473  
1474 # End of file reached, or filehandle not open
1475 return 1;
1476  
1477 } else {
1478  
1479 # End of file not reached
1480 return 0;
1481 }
1482 }
1483 }
1484 }
1485  
1486 { package Language::Axbasic::Function::Intrinsic::Numeric::epoch;
1487  
1488 use strict;
1489 use warnings;
1490 use diagnostics;
1491  
1492 use Glib qw(TRUE FALSE);
1493  
1494 @Language::Axbasic::Function::Intrinsic::Numeric::epoch::ISA = qw(
1495 Language::Axbasic::Function::Intrinsic::Numeric
1496 );
1497  
1498 # Epoch ()
1499  
1500 ##################
1501 # Methods
1502  
1503 sub evaluate {
1504  
1505 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
1506 #
1507 # Expected arguments
1508 # $arg - The first (and only) argument in the argument list
1509 #
1510 # Return values
1511 # The return value of the function
1512  
1513 my ($self, $arg) = @_;
1514  
1515 # (No improper arguments to check)
1516  
1517 # Evaluate the function and return the value
1518 return time;
1519 }
1520 }
1521  
1522 { package Language::Axbasic::Function::Intrinsic::Numeric::exp;
1523  
1524 use strict;
1525 use warnings;
1526 use diagnostics;
1527  
1528 use Glib qw(TRUE FALSE);
1529  
1530 @Language::Axbasic::Function::Intrinsic::Numeric::exp::ISA = qw(
1531 Language::Axbasic::Function::Intrinsic::Numeric
1532 );
1533  
1534 # Exp (x)
1535  
1536 ##################
1537 # Methods
1538  
1539 sub evaluate {
1540  
1541 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1542 #
1543 # Expected arguments
1544 # $arg - The first (and only) argument in the argument list
1545 #
1546 # Return values
1547 # The return value of the function
1548  
1549 my ($self, $arg) = @_;
1550  
1551 # (No improper arguments to check)
1552  
1553 # Evaluate the function and return the value
1554 return exp($arg);
1555 }
1556 }
1557  
1558 { package Language::Axbasic::Function::Intrinsic::Numeric::floor;
1559  
1560 use strict;
1561 use warnings;
1562 use diagnostics;
1563  
1564 use Glib qw(TRUE FALSE);
1565  
1566 @Language::Axbasic::Function::Intrinsic::Numeric::floor::ISA = qw(
1567 Language::Axbasic::Function::Intrinsic::Numeric
1568 );
1569  
1570 # Floor (x)
1571  
1572 ##################
1573 # Methods
1574  
1575 sub evaluate {
1576  
1577 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1578 #
1579 # Expected arguments
1580 # $arg - The first (and only) argument in the argument list
1581 #
1582 # Return values
1583 # The return value of the function
1584  
1585 my ($self, $arg) = @_;
1586  
1587 # (No improper arguments to check)
1588  
1589 # Evaluate the function and return the value
1590 return POSIX::floor($arg);
1591 }
1592 }
1593  
1594 { package Language::Axbasic::Function::Intrinsic::Numeric::fp;
1595  
1596 use strict;
1597 use warnings;
1598 use diagnostics;
1599  
1600 use Glib qw(TRUE FALSE);
1601  
1602 @Language::Axbasic::Function::Intrinsic::Numeric::fp::ISA = qw(
1603 Language::Axbasic::Function::Intrinsic::Numeric
1604 );
1605  
1606 # Fp (x)
1607  
1608 ##################
1609 # Methods
1610  
1611 sub evaluate {
1612  
1613 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1614 #
1615 # Expected arguments
1616 # $arg - The first (and only) argument in the argument list
1617 #
1618 # Return values
1619 # The return value of the function
1620  
1621 my ($self, $arg) = @_;
1622  
1623 # (No improper arguments to check)
1624  
1625 # Evaluate the function and return the value
1626 return ($arg - int($arg));
1627 }
1628 }
1629  
1630 { package Language::Axbasic::Function::Intrinsic::Numeric::int;
1631  
1632 use strict;
1633 use warnings;
1634 use diagnostics;
1635  
1636 use Glib qw(TRUE FALSE);
1637  
1638 @Language::Axbasic::Function::Intrinsic::Numeric::int::ISA = qw(
1639 Language::Axbasic::Function::Intrinsic::Numeric
1640 );
1641  
1642 # Int (number)
1643  
1644 ##################
1645 # Methods
1646  
1647 sub evaluate {
1648  
1649 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1650 #
1651 # Expected arguments
1652 # $arg - The first (and only) argument in the argument list
1653 #
1654 # Return values
1655 # The return value of the function
1656  
1657 my ($self, $arg) = @_;
1658  
1659 # (No improper arguments to check)
1660  
1661 # Evaluate the function and return the value
1662 if ($arg < 0) {
1663 return (int($arg) - 1);
1664 } else {
1665 return (int($arg));
1666 }
1667 }
1668 }
1669  
1670 { package Language::Axbasic::Function::Intrinsic::Numeric::ip;
1671  
1672 use strict;
1673 use warnings;
1674 use diagnostics;
1675  
1676 use Glib qw(TRUE FALSE);
1677  
1678 @Language::Axbasic::Function::Intrinsic::Numeric::ip::ISA = qw(
1679 Language::Axbasic::Function::Intrinsic::Numeric
1680 );
1681  
1682 # Ip (x)
1683  
1684 ##################
1685 # Methods
1686  
1687 sub evaluate {
1688  
1689 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1690 #
1691 # Expected arguments
1692 # $arg - The first (and only) argument in the argument list
1693 #
1694 # Return values
1695 # The return value of the function
1696  
1697 my ($self, $arg) = @_;
1698  
1699 # (No improper arguments to check)
1700  
1701 # Evaluate the function and return the value
1702 return int($arg);
1703 }
1704 }
1705  
1706 { package Language::Axbasic::Function::Intrinsic::Numeric::len;
1707  
1708 use strict;
1709 use warnings;
1710 use diagnostics;
1711  
1712 use Glib qw(TRUE FALSE);
1713  
1714 @Language::Axbasic::Function::Intrinsic::Numeric::len::ISA = qw(
1715 Language::Axbasic::Function::Intrinsic::Numeric
1716 );
1717  
1718 # Len (string)
1719  
1720 ##################
1721 # Methods
1722  
1723 sub evaluate {
1724  
1725 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
1726 #
1727 # Expected arguments
1728 # $arg - The first (and only) argument in the argument list
1729 #
1730 # Return values
1731 # The return value of the function
1732  
1733 my ($self, $arg) = @_;
1734  
1735 # (No improper arguments to check)
1736  
1737 # Evaluate the function and return the value
1738 return length($arg);
1739 }
1740 }
1741  
1742 { package Language::Axbasic::Function::Intrinsic::Numeric::log;
1743  
1744 use strict;
1745 use warnings;
1746 use diagnostics;
1747  
1748 use Glib qw(TRUE FALSE);
1749  
1750 @Language::Axbasic::Function::Intrinsic::Numeric::log::ISA = qw(
1751 Language::Axbasic::Function::Intrinsic::Numeric
1752 );
1753  
1754 # Log (x)
1755  
1756 ##################
1757 # Methods
1758  
1759 sub evaluate {
1760  
1761 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1762 #
1763 # Expected arguments
1764 # $arg - The first (and only) argument in the argument list
1765 #
1766 # Return values
1767 # The return value of the function
1768  
1769 my ($self, $arg) = @_;
1770  
1771 # (No improper arguments to check)
1772  
1773 # Evaluate the function and return the value
1774 return log($arg);
1775 }
1776 }
1777  
1778 { package Language::Axbasic::Function::Intrinsic::Numeric::log2;
1779  
1780 use strict;
1781 use warnings;
1782 use diagnostics;
1783  
1784 use Glib qw(TRUE FALSE);
1785  
1786 @Language::Axbasic::Function::Intrinsic::Numeric::log2::ISA = qw(
1787 Language::Axbasic::Function::Intrinsic::Numeric
1788 );
1789  
1790 # Log2 (x)
1791  
1792 ##################
1793 # Methods
1794  
1795 sub evaluate {
1796  
1797 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1798 #
1799 # Expected arguments
1800 # $arg - The first (and only) argument in the argument list
1801 #
1802 # Return values
1803 # The return value of the function
1804  
1805 my ($self, $arg) = @_;
1806  
1807 # (No improper arguments to check)
1808  
1809 # Evaluate the function and return the value
1810 return (log($arg) / log(2));
1811 }
1812 }
1813  
1814 { package Language::Axbasic::Function::Intrinsic::Numeric::log10;
1815  
1816 use strict;
1817 use warnings;
1818 use diagnostics;
1819  
1820 use Glib qw(TRUE FALSE);
1821  
1822 @Language::Axbasic::Function::Intrinsic::Numeric::log10::ISA = qw(
1823 Language::Axbasic::Function::Intrinsic::Numeric
1824 );
1825  
1826 # Log10 (x)
1827  
1828 ##################
1829 # Methods
1830  
1831 sub evaluate {
1832  
1833 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
1834 #
1835 # Expected arguments
1836 # $arg - The first (and only) argument in the argument list
1837 #
1838 # Return values
1839 # The return value of the function
1840  
1841 my ($self, $arg) = @_;
1842  
1843 # (No improper arguments to check)
1844  
1845 # Evaluate the function and return the value
1846 return (log($arg) / log(10));
1847 }
1848 }
1849  
1850 { package Language::Axbasic::Function::Intrinsic::Numeric::match;
1851  
1852 use strict;
1853 use warnings;
1854 use diagnostics;
1855  
1856 use Glib qw(TRUE FALSE);
1857  
1858 @Language::Axbasic::Function::Intrinsic::Numeric::match::ISA = qw(
1859 Language::Axbasic::Function::Intrinsic::Numeric
1860 );
1861  
1862 # Match (string, regex)
1863  
1864 ##################
1865 # Methods
1866  
1867 sub evaluate {
1868  
1869 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS')
1870 #
1871 # Expected arguments
1872 # @args - The list of arguments supplied to the function
1873 #
1874 # Return values
1875 # The return value of the function
1876  
1877 my ($self, @args) = @_;
1878  
1879 # Local variables
1880 my ($string, $regex);
1881  
1882 # (No improper arguments to check)
1883  
1884 # Evaluate the function and return the value
1885 ($string, $regex) = @args;
1886  
1887 if ($string =~ m/$regex/) {
1888 return 1;
1889 } else {
1890 return 0;
1891 }
1892 }
1893 }
1894  
1895 { package Language::Axbasic::Function::Intrinsic::Numeric::matchi;
1896  
1897 use strict;
1898 use warnings;
1899 use diagnostics;
1900  
1901 use Glib qw(TRUE FALSE);
1902  
1903 @Language::Axbasic::Function::Intrinsic::Numeric::matchi::ISA = qw(
1904 Language::Axbasic::Function::Intrinsic::Numeric
1905 );
1906  
1907 # Matchi (string, regex)
1908  
1909 ##################
1910 # Methods
1911  
1912 sub evaluate {
1913  
1914 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS')
1915 #
1916 # Expected arguments
1917 # @args - The list of arguments supplied to the function
1918 #
1919 # Return values
1920 # The return value of the function
1921  
1922 my ($self, @args) = @_;
1923  
1924 # Local variables
1925 my ($string, $regex);
1926  
1927 # (No improper arguments to check)
1928  
1929 # Evaluate the function and return the value
1930 ($string, $regex) = @args;
1931  
1932 if ($string =~ m/$regex/i) {
1933 return 1;
1934 } else {
1935 return 0;
1936 }
1937 }
1938 }
1939  
1940 { package Language::Axbasic::Function::Intrinsic::Numeric::max;
1941  
1942 use strict;
1943 use warnings;
1944 use diagnostics;
1945  
1946 use Glib qw(TRUE FALSE);
1947  
1948 @Language::Axbasic::Function::Intrinsic::Numeric::max::ISA = qw(
1949 Language::Axbasic::Function::Intrinsic::Numeric
1950 );
1951  
1952 # Max (x, y)
1953  
1954 ##################
1955 # Methods
1956  
1957 sub evaluate {
1958  
1959 # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN')
1960 #
1961 # Expected arguments
1962 # @args - The list of arguments supplied to the function
1963 #
1964 # Return values
1965 # The return value of the function
1966  
1967 my ($self, @args) = @_;
1968  
1969 # (No improper arguments to check)
1970  
1971 # Evaluate the function and return the value
1972 if ($args[0] > $args[1]) {
1973 return $args[0];
1974 } else {
1975 return $args[1];
1976 }
1977 }
1978 }
1979  
1980 { package Language::Axbasic::Function::Intrinsic::Numeric::min;
1981  
1982 use strict;
1983 use warnings;
1984 use diagnostics;
1985  
1986 use Glib qw(TRUE FALSE);
1987  
1988 @Language::Axbasic::Function::Intrinsic::Numeric::min::ISA = qw(
1989 Language::Axbasic::Function::Intrinsic::Numeric
1990 );
1991  
1992 # Min (x, y)
1993  
1994 ##################
1995 # Methods
1996  
1997 sub evaluate {
1998  
1999 # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN')
2000 #
2001 # Expected arguments
2002 # @args - The list of arguments supplied to the function
2003 #
2004 # Return values
2005 # The return value of the function
2006  
2007 my ($self, @args) = @_;
2008  
2009 # (No improper arguments to check)
2010  
2011 # Evaluate the function and return the value
2012 if ($args[0] < $args[1]) {
2013 return $args[0];
2014 } else {
2015 return $args[1];
2016 }
2017 }
2018 }
2019  
2020 { package Language::Axbasic::Function::Intrinsic::Numeric::mod;
2021  
2022 use strict;
2023 use warnings;
2024 use diagnostics;
2025  
2026 use Glib qw(TRUE FALSE);
2027  
2028 @Language::Axbasic::Function::Intrinsic::Numeric::mod::ISA = qw(
2029 Language::Axbasic::Function::Intrinsic::Numeric
2030 );
2031  
2032 # Mod (x, y)
2033  
2034 ##################
2035 # Methods
2036  
2037 sub evaluate {
2038  
2039 # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN')
2040 #
2041 # Evaluates the function using the supplied arguments
2042 #
2043 # Expected arguments
2044 # @args - The list of arguments supplied to the function
2045 #
2046 # Return values
2047 # The return value of the function
2048  
2049 my ($self, @args) = @_;
2050  
2051 # (No improper arguments to check)
2052  
2053 # Evaluate the function and return the value
2054 return ($args[0] % $args[1]);
2055 }
2056 }
2057  
2058 { package Language::Axbasic::Function::Intrinsic::Numeric::ncpos;
2059  
2060 use strict;
2061 use warnings;
2062 use diagnostics;
2063  
2064 use Glib qw(TRUE FALSE);
2065  
2066 @Language::Axbasic::Function::Intrinsic::Numeric::ncpos::ISA = qw(
2067 Language::Axbasic::Function::Intrinsic::Numeric
2068 );
2069  
2070 # Ncpos (string, substring)
2071 # Ncpos (string, substring, n)
2072  
2073 ##################
2074 # Methods
2075  
2076 sub evaluate {
2077  
2078 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N')
2079 #
2080 # Expected arguments
2081 # $string, $subString, $position
2082 # - The list of arguments supplied to the function
2083 #
2084 # Return values
2085 # The return value of the function
2086  
2087 my ($self, $string, $subString, $posn) = @_;
2088  
2089 # Local variables
2090 my @charList;
2091  
2092 # (No improper arguments to check)
2093  
2094 # Evaluate the function and return the value
2095 if (defined $posn) {
2096  
2097 # If $string is a null string, True BASIC returns 0;
2098 if (! $string) {
2099  
2100 return 0;
2101  
2102 # If $subString is a null string, True BASIC returns the starting position
2103 } elsif (! $subString) {
2104  
2105 return $posn;
2106 }
2107  
2108 # $posn must not be zero or a negative number
2109 if ($posn < 1) {
2110  
2111 return $self->scriptObj->setError(
2112 'number_NUM_out_of_range',
2113 $self->_objClass . '->evaluate',
2114 'NUM', $posn,
2115 );
2116 }
2117  
2118 # $posn must be rounded
2119 $posn = substr($posn + 0.5, 0, length(int($posn + 0.5)));
2120  
2121 # Finally, Perl's index() function uses the number 0 for the first character in the
2122 # string, but True BASIC uses the number 1
2123 $posn--;
2124  
2125 } else {
2126  
2127 # If either string is a null string, True BASIC returns 0
2128 if (! $string || ! $subString) {
2129  
2130 return 0;
2131 }
2132  
2133 # We start the search at (Perl) character position 0
2134 $posn = 0;
2135 }
2136  
2137 # Evaluate the function for each character in $string
2138 @charList = split(//, $string);
2139 for (my $count = $posn; $count < length $string; $count++) {
2140  
2141 if (index($subString, $charList[$count]) == -1) {
2142  
2143 # The character doesn't appear in the substring
2144 return ($count + 1);
2145 }
2146 }
2147  
2148 # No character in the string was found in the substring
2149 return 0;
2150 }
2151 }
2152  
2153 { package Language::Axbasic::Function::Intrinsic::Numeric::ncposr;
2154  
2155 use strict;
2156 use warnings;
2157 use diagnostics;
2158  
2159 use Glib qw(TRUE FALSE);
2160  
2161 @Language::Axbasic::Function::Intrinsic::Numeric::ncposr::ISA = qw(
2162 Language::Axbasic::Function::Intrinsic::Numeric
2163 );
2164  
2165 # Ncposr (string, substring)
2166 # Ncposr (string, substring, n)
2167  
2168 ##################
2169 # Methods
2170  
2171 sub evaluate {
2172  
2173 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N')
2174 #
2175 # Expected arguments
2176 # $string, $subString, $posn
2177 # - The list of arguments supplied to the function
2178 #
2179 # Return values
2180 # The return value of the function
2181  
2182 my ($self, $string, $subString, $posn) = @_;
2183  
2184 # Local variables
2185 my @charList;
2186  
2187 # (No improper arguments to check)
2188  
2189 # Evaluate the function and return the value
2190 if (defined $posn) {
2191  
2192 # If $string is a null string, True BASIC returns 0;
2193 if (! $string) {
2194  
2195 return 0;
2196  
2197 # If $subString is a null string, True BASIC returns the starting position
2198 } elsif (! $subString) {
2199  
2200 return $posn;
2201 }
2202  
2203 # $posn must not be zero or a negative number
2204 if ($posn < 1) {
2205  
2206 return $self->scriptObj->setError(
2207 'number_NUM_out_of_range',
2208 $self->_objClass . '->evaluate',
2209 'NUM', $posn,
2210 );
2211 }
2212  
2213 # $posn must be rounded
2214 $posn = substr(
2215 $posn + 0.5,
2216 0,
2217 length(int($posn + 0.5)),
2218 );
2219  
2220 # Finally, Perl's index() function uses the number 0 for the first character in the
2221 # string, but True BASIC uses the number 1
2222 $posn--;
2223  
2224 } else {
2225  
2226 # If the string is a null string, True BASIC returns 0
2227 if (! $string) {
2228  
2229 return 0;
2230  
2231 # If the substring is a null string but the string isn't, True BASIC returns the length
2232 # of the string
2233 } elsif (! $subString) {
2234  
2235 return length($string);
2236 }
2237  
2238 # We start the search at the (Perl) end of the string
2239 $posn = (length($string) - 1);
2240 }
2241  
2242 # Evaluate the function for each character in $string
2243 @charList = split(//, $string);
2244 for (my $count = $posn; $count >= 0; $count--) {
2245  
2246 if (index($subString, $charList[$count]) == -1) {
2247  
2248 # The character doesn't appear in the substring
2249 return ($count + 1);
2250 }
2251 }
2252  
2253 # No character in the string was found in the substring
2254 return 0;
2255 }
2256 }
2257  
2258 { package Language::Axbasic::Function::Intrinsic::Numeric::pi;
2259  
2260 use strict;
2261 use warnings;
2262 use diagnostics;
2263  
2264 use Glib qw(TRUE FALSE);
2265  
2266 @Language::Axbasic::Function::Intrinsic::Numeric::pi::ISA = qw(
2267 Language::Axbasic::Function::Intrinsic::Numeric
2268 );
2269  
2270 # Pi ()
2271  
2272 ##################
2273 # Methods
2274  
2275 sub evaluate {
2276  
2277 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
2278 #
2279 # Expected arguments
2280 # $arg - The first (and only) argument in the argument list
2281 #
2282 # Return values
2283 # The return value of the function
2284  
2285 my ($self, $arg) = @_;
2286  
2287 # (No improper arguments to check)
2288  
2289 # Evaluate the function and return the value
2290 return Math::Trig::pi();
2291 }
2292 }
2293  
2294 { package Language::Axbasic::Function::Intrinsic::Numeric::pos;
2295  
2296 use strict;
2297 use warnings;
2298 use diagnostics;
2299  
2300 use Glib qw(TRUE FALSE);
2301  
2302 @Language::Axbasic::Function::Intrinsic::Numeric::pos::ISA = qw(
2303 Language::Axbasic::Function::Intrinsic::Numeric
2304 );
2305  
2306 # Pos (string, substring)
2307 # Pos (string, substring, n)
2308  
2309 ##################
2310 # Methods
2311  
2312 sub evaluate {
2313  
2314 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N')
2315 #
2316 # Expected arguments
2317 # $string, $subString, $posn
2318 # - The list of arguments supplied to the function
2319 #
2320 # Return values
2321 # The return value of the function
2322  
2323 my ($self, $string, $subString, $posn) = @_;
2324  
2325 # Local variables
2326 my $result;
2327  
2328 # (No improper arguments to check)
2329  
2330 # Evaluate the function and return the value
2331 if (defined $posn) {
2332  
2333 # $posn must not be zero or a negative number
2334 if ($posn < 1) {
2335  
2336 return $self->scriptObj->setError(
2337 'number_NUM_out_of_range',
2338 $self->_objClass . '->evaluate',
2339 'NUM', $posn,
2340 );
2341 }
2342  
2343 # $posn must be rounded
2344 $posn = substr(
2345 $posn + 0.5,
2346 0,
2347 length(int($posn + 0.5)),
2348 );
2349  
2350 # Finally, Perl's index() function uses the number 0 for the first character in the
2351 # string, but True BASIC uses the number 1
2352 $posn--;
2353 }
2354  
2355 # If $string is null but $substring is not, True BASIC returns 0
2356 if (! $string && $subString) {
2357  
2358 return 0;
2359  
2360 } elsif (! $subString) {
2361  
2362 if (defined $posn) {
2363  
2364 # If $subString is null, True BASIC returns the starting position
2365 return ($posn + 1);
2366  
2367 } else {
2368  
2369 # If $subString is null, True BASIC returns 1
2370 return 1;
2371 }
2372 }
2373  
2374 # Evaluate the function and return the value
2375 if (defined $posn) {
2376 $result = index($string, $subString, $posn);
2377 } else {
2378 $result = index($string, $subString);
2379 }
2380  
2381 if ($result == -1) {
2382  
2383 # $subString not found - True BASIC returns 0
2384 return 0;
2385  
2386 } else {
2387  
2388 # Look for 'gust' in 'disgust' - Perl returns 3, but True BASIC returns 4
2389 return ($result + 1);
2390 }
2391 }
2392 }
2393  
2394 { package Language::Axbasic::Function::Intrinsic::Numeric::posr;
2395  
2396 use strict;
2397 use warnings;
2398 use diagnostics;
2399  
2400 use Glib qw(TRUE FALSE);
2401  
2402 @Language::Axbasic::Function::Intrinsic::Numeric::posr::ISA = qw(
2403 Language::Axbasic::Function::Intrinsic::Numeric
2404 );
2405  
2406 # Posr (string, substring)
2407 # Posr (string, substring, n)
2408  
2409 ##################
2410 # Methods
2411  
2412 sub evaluate {
2413  
2414 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SS;N')
2415 #
2416 # Expected arguments
2417 # $string, $subString, $posn
2418 # - The list of arguments supplied to the function
2419 #
2420 # Return values
2421 # The return value of the function
2422  
2423 my ($self, $string, $subString, $posn) = @_;
2424  
2425 # Local variables
2426 my $result;
2427  
2428 # (No improper arguments to check)
2429  
2430 # Evaluate the function and return the value
2431 if (defined $posn) {
2432  
2433 # $posn must not be a negative number
2434 if ($posn < 1) {
2435  
2436 return $self->scriptObj->setError(
2437 'number_NUM_out_of_range',
2438 $self->_objClass . '->evaluate',
2439 'NUM', $posn,
2440 );
2441 }
2442  
2443 # $posn must be rounded
2444 $posn = substr($posn + 0.5, 0, length(int($posn + 0.5)));
2445  
2446 # Finally, Perl's index() function uses the number 0 for the first character in the
2447 # string, but True BASIC uses the number 1
2448 $posn--;
2449 }
2450  
2451 # If $string is null but $substring is not, True BASIC returns 0
2452 if (! $string && $subString) {
2453  
2454 return 0;
2455  
2456 } elsif (! $subString) {
2457  
2458 if (defined $posn) {
2459  
2460 # If $subString is null, True BASIC returns the starting position
2461 return ($posn + 1);
2462  
2463 } else {
2464  
2465 # If $subString is null, True BASIC returns 1
2466 return 1;
2467 }
2468 }
2469  
2470 # Evaluate the function and return the value
2471 if (defined $posn) {
2472 $result = rindex($string, $subString, $posn);
2473 } else {
2474 $result = rindex($string, $subString);
2475 }
2476  
2477 if ($result == -1) {
2478  
2479 # $subString not found - True BASIC returns 0
2480 return 0;
2481  
2482 } else {
2483  
2484 # Look for 'gust' in 'disgust' - Perl returns 3, but True BASIC returns 4
2485 return ($result + 1);
2486 }
2487 }
2488 }
2489  
2490 { package Language::Axbasic::Function::Intrinsic::Numeric::rad;
2491  
2492 use strict;
2493 use warnings;
2494 use diagnostics;
2495  
2496 use Glib qw(TRUE FALSE);
2497  
2498 @Language::Axbasic::Function::Intrinsic::Numeric::rad::ISA = qw(
2499 Language::Axbasic::Function::Intrinsic::Numeric
2500 );
2501  
2502 # Rad (x)
2503  
2504 ##################
2505 # Methods
2506  
2507 sub evaluate {
2508  
2509 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2510 #
2511 # Expected arguments
2512 # $arg - The first (and only) argument in the argument list
2513 #
2514 # Return values
2515 # The return value of the function
2516  
2517 my ($self, $arg) = @_;
2518  
2519 # (No improper arguments to check)
2520  
2521 # Evaluate the function and return the value
2522 return Math::Trig::deg2rad($arg);
2523 }
2524 }
2525  
2526 { package Language::Axbasic::Function::Intrinsic::Numeric::remainder;
2527  
2528 use strict;
2529 use warnings;
2530 use diagnostics;
2531  
2532 use Glib qw(TRUE FALSE);
2533  
2534 @Language::Axbasic::Function::Intrinsic::Numeric::remainder::ISA = qw(
2535 Language::Axbasic::Function::Intrinsic::Numeric
2536 );
2537  
2538 # Remainder (x, y)
2539  
2540 ##################
2541 # Methods
2542  
2543 sub evaluate {
2544  
2545 # Called by LA::Expression::Function->evaluate (using arguments in the form 'NN')
2546 #
2547 # Expected arguments
2548 # @args - The list of arguments supplied to the function
2549 #
2550 # Return values
2551 # The return value of the function
2552  
2553 my ($self, @args) = @_;
2554  
2555 # (No improper arguments to check)
2556  
2557 # Evaluate the function and return the value
2558 return ($args[0] % $args[1]);
2559 }
2560 }
2561  
2562 { package Language::Axbasic::Function::Intrinsic::Numeric::rnd;
2563  
2564 use strict;
2565 use warnings;
2566 use diagnostics;
2567  
2568 use Glib qw(TRUE FALSE);
2569  
2570 @Language::Axbasic::Function::Intrinsic::Numeric::rnd::ISA = qw(
2571 Language::Axbasic::Function::Intrinsic::Numeric
2572 );
2573  
2574 # Rnd (n)
2575  
2576 ##################
2577 # Methods
2578  
2579 sub evaluate {
2580  
2581 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2582 #
2583 # Expected arguments
2584 # $arg - The first (and only) argument in the argument list
2585 #
2586 # Return values
2587 # The return value of the function
2588  
2589 my ($self, $arg) = @_;
2590  
2591 # Local variables
2592 my $value;
2593  
2594 # (No improper arguments to check)
2595  
2596 # Evaluate the function and return the value
2597 return rand($arg);
2598 }
2599 }
2600  
2601 { package Language::Axbasic::Function::Intrinsic::Numeric::round;
2602  
2603 use strict;
2604 use warnings;
2605 use diagnostics;
2606  
2607 use Glib qw(TRUE FALSE);
2608  
2609 @Language::Axbasic::Function::Intrinsic::Numeric::round::ISA = qw(
2610 Language::Axbasic::Function::Intrinsic::Numeric
2611 );
2612  
2613 # Round (x)
2614 # Round (x, n)
2615  
2616 ##################
2617 # Methods
2618  
2619 sub evaluate {
2620  
2621 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N;N')
2622 #
2623 # Expected arguments
2624 # @args - The list of arguments supplied to the function
2625 #
2626 # Return values
2627 # The return value of the function
2628  
2629 my ($self, @args) = @_;
2630  
2631 # Local variables
2632 my ($number, $decimals);
2633  
2634 # (No improper arguments to check)
2635  
2636 # Evaluate the function and return the value
2637 $number = shift @args;
2638 $decimals = shift @args;
2639 if (! defined $decimals) {
2640  
2641 $decimals = 0;
2642 }
2643  
2644 # return sprintf("%." . $decimals . "f", $number);
2645 return Math::Round::nearest((10 ** ($decimals * -1)), $number);
2646 }
2647 }
2648  
2649 { package Language::Axbasic::Function::Intrinsic::Numeric::sec;
2650  
2651 use strict;
2652 use warnings;
2653 use diagnostics;
2654  
2655 use Glib qw(TRUE FALSE);
2656 # Include module here, as well as in Axbasic.pm, so that .../t/00-compile.t won't fail
2657 use Math::Trig;
2658  
2659 @Language::Axbasic::Function::Intrinsic::Numeric::sec::ISA = qw(
2660 Language::Axbasic::Function::Intrinsic::Numeric
2661 );
2662  
2663 # Sec (x)
2664  
2665 ##################
2666 # Methods
2667  
2668 sub evaluate {
2669  
2670 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2671 #
2672 # Expected arguments
2673 # $arg - The first (and only) argument in the argument list
2674 #
2675 # Return values
2676 # The return value of the function
2677  
2678 my ($self, $arg) = @_;
2679  
2680 # Local variables
2681 my $value;
2682  
2683 # (No improper arguments to check)
2684  
2685 # Evaluate the function and return the value
2686  
2687 # $arg must not be (pi/2) + (k * pi), where k is any integer
2688 if (
2689 (
2690 (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi)
2691 == int (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi)
2692 ) || (
2693 # Don't know why we need to use 'eq' instead of '==' in the case of k = 0, but we
2694 # do...
2695 $arg eq (Math::Trig::pi / 2)
2696 )
2697 ) {
2698 return $self->scriptObj->setError(
2699 'number_NUM_out_of_range',
2700 $self->_objClass . '->evaluate',
2701 'NUM', $arg,
2702 );
2703 }
2704  
2705 # Use radians (default) or degrees?
2706 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
2707  
2708 # Convert to radians
2709 $arg = Math::Trig::deg2rad($arg);
2710 }
2711  
2712 # Evaluate the function and return the value
2713 return Math::Trig::sec($arg);
2714 }
2715 }
2716  
2717 { package Language::Axbasic::Function::Intrinsic::Numeric::sgn;
2718  
2719 use strict;
2720 use warnings;
2721 use diagnostics;
2722  
2723 use Glib qw(TRUE FALSE);
2724  
2725 @Language::Axbasic::Function::Intrinsic::Numeric::sgn::ISA = qw(
2726 Language::Axbasic::Function::Intrinsic::Numeric
2727 );
2728  
2729 # Sgn (x)
2730  
2731 ##################
2732 # Methods
2733  
2734 sub evaluate {
2735  
2736 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2737 #
2738 # Expected arguments
2739 # $arg - The first (and only) argument in the argument list
2740 #
2741 # Return values
2742 # The return value of the function
2743  
2744 my ($self, $arg) = @_;
2745  
2746 # (No improper arguments to check)
2747  
2748 # Evaluate the function and return the value
2749 if ($arg > 0) {
2750 return 1;
2751 } elsif ($arg < 0) {
2752 return -1;
2753 } else {
2754 return 0;
2755 }
2756 }
2757 }
2758  
2759 { package Language::Axbasic::Function::Intrinsic::Numeric::sin;
2760  
2761 use strict;
2762 use warnings;
2763 use diagnostics;
2764  
2765 use Glib qw(TRUE FALSE);
2766  
2767 @Language::Axbasic::Function::Intrinsic::Numeric::sin::ISA = qw(
2768 Language::Axbasic::Function::Intrinsic::Numeric
2769 );
2770  
2771 # Sin (x)
2772  
2773 ##################
2774 # Methods
2775  
2776 sub evaluate {
2777  
2778 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2779 #
2780 # Expected arguments
2781 # $arg - The first (and only) argument in the argument list
2782 #
2783 # Return values
2784 # The return value of the function
2785  
2786 my ($self, $arg) = @_;
2787  
2788 # (No improper arguments to check)
2789  
2790 # Evaluate the function and return the value
2791  
2792 # Use radians (default) or degrees?
2793 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
2794  
2795 # Convert to radians
2796 $arg = Math::Trig::deg2rad($arg);
2797 }
2798  
2799 # Evaluate the function and return the value
2800 return sin($arg);
2801 }
2802 }
2803  
2804 { package Language::Axbasic::Function::Intrinsic::Numeric::sinh;
2805  
2806 use strict;
2807 use warnings;
2808 use diagnostics;
2809  
2810 use Glib qw(TRUE FALSE);
2811  
2812 @Language::Axbasic::Function::Intrinsic::Numeric::sinh::ISA = qw(
2813 Language::Axbasic::Function::Intrinsic::Numeric
2814 );
2815  
2816 # Sinh (x)
2817  
2818 ##################
2819 # Methods
2820  
2821 sub evaluate {
2822  
2823 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2824 #
2825 # Expected arguments
2826 # $arg - The first (and only) argument in the argument list
2827 #
2828 # Return values
2829 # The return value of the function
2830  
2831 my ($self, $arg) = @_;
2832  
2833 # (No improper arguments to check)
2834  
2835 # Evaluate the function and return the value
2836 return &sinh($arg);
2837 }
2838 }
2839  
2840 { package Language::Axbasic::Function::Intrinsic::Numeric::sqr;
2841  
2842 use strict;
2843 use warnings;
2844 use diagnostics;
2845  
2846 use Glib qw(TRUE FALSE);
2847  
2848 @Language::Axbasic::Function::Intrinsic::Numeric::sqr::ISA = qw(
2849 Language::Axbasic::Function::Intrinsic::Numeric
2850 );
2851  
2852 # Sqr (x)
2853  
2854 ##################
2855 # Methods
2856  
2857 sub evaluate {
2858  
2859 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2860 #
2861 # Expected arguments
2862 # $arg - The first (and only) argument in the argument list
2863 #
2864 # Return values
2865 # The return value of the function
2866  
2867 my ($self, $arg) = @_;
2868  
2869 # (No improper arguments to check)
2870  
2871 # Evaluate the function and return the value
2872  
2873 # Don't try to get the square root of a negative number
2874 if ($arg < 0) {
2875  
2876 return $self->scriptObj->setError(
2877 'number_NUM_out_of_range',
2878 $self->_objClass . '->evaluate',
2879 'NUM', $arg,
2880 );
2881 }
2882  
2883 # Evaluate the function and return the value
2884 return sqrt($arg);
2885 }
2886 }
2887  
2888 { package Language::Axbasic::Function::Intrinsic::Numeric::tan;
2889  
2890 use strict;
2891 use warnings;
2892 use diagnostics;
2893  
2894 use Glib qw(TRUE FALSE);
2895  
2896 @Language::Axbasic::Function::Intrinsic::Numeric::tan::ISA = qw(
2897 Language::Axbasic::Function::Intrinsic::Numeric
2898 );
2899  
2900 # Tan (x)
2901  
2902 ##################
2903 # Methods
2904  
2905 sub evaluate {
2906  
2907 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2908 #
2909 # Expected arguments
2910 # $arg - The first (and only) argument in the argument list
2911 #
2912 # Return values
2913 # The return value of the function
2914  
2915 my ($self, $arg) = @_;
2916  
2917 # (No improper arguments to check)
2918  
2919 # Evaluate the function and return the value
2920  
2921 # $arg must not be (pi/2) + (k * pi), where k is any integer
2922 if (
2923 (
2924 (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi)
2925 == int (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi)
2926 ) || (
2927 # Don't know why we need to use 'eq' instead of '==' in the case of k = 0, but we
2928 # do...
2929 $arg eq (Math::Trig::pi / 2)
2930 )
2931 ) {
2932 return $self->scriptObj->setError(
2933 'number_NUM_out_of_range',
2934 $self->_objClass . '->evaluate',
2935 'NUM', $arg,
2936 );
2937 }
2938  
2939 # Use radians (default) or degrees?
2940 if ($self->scriptObj->ivShow('optionStatementHash', 'angle') eq 'degrees') {
2941  
2942 # Convert to radians
2943 $arg = Math::Trig::deg2rad($arg);
2944 }
2945  
2946 # Evaluate the function and return the value
2947 return Math::Trig::tan($arg);
2948 }
2949 }
2950  
2951 { package Language::Axbasic::Function::Intrinsic::Numeric::tanh;
2952  
2953 use strict;
2954 use warnings;
2955 use diagnostics;
2956  
2957 use Glib qw(TRUE FALSE);
2958  
2959 @Language::Axbasic::Function::Intrinsic::Numeric::tanh::ISA = qw(
2960 Language::Axbasic::Function::Intrinsic::Numeric
2961 );
2962  
2963 # Tanh (x)
2964  
2965 ##################
2966 # Methods
2967  
2968 sub evaluate {
2969  
2970 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
2971 #
2972 # Expected arguments
2973 # $arg - The first (and only) argument in the argument lisT
2974 #
2975 # Return values
2976 # The return value of the function
2977  
2978 my ($self, $arg) = @_;
2979  
2980 # Local variables
2981 my $value;
2982  
2983 # (No improper arguments to check)
2984  
2985 # Evaluate the function and return the value
2986  
2987 # $arg must not be (pi/2) + (k * pi), where k is any integer
2988 if (
2989 (
2990 (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi)
2991 == int (($arg - (Math::Trig::pi / 2)) / Math::Trig::pi)
2992 ) || (
2993 # Don't know why we need to use 'eq' instead of '==' in the case of k = 0, but we
2994 # do...
2995 $arg eq (Math::Trig::pi / 2)
2996 )
2997 ) {
2998 return $self->scriptObj->setError(
2999 'number_NUM_out_of_range',
3000 $self->_objClass . '->evaluate',
3001 'NUM', $arg,
3002 );
3003 }
3004  
3005 # Evaluate the function and return the value
3006 return Math::Trig::tanh($arg);
3007 }
3008 }
3009  
3010 { package Language::Axbasic::Function::Intrinsic::Numeric::testpat;
3011  
3012 use strict;
3013 use warnings;
3014 use diagnostics;
3015  
3016 use Glib qw(TRUE FALSE);
3017  
3018 @Language::Axbasic::Function::Intrinsic::Numeric::testpat::ISA = qw(
3019 Language::Axbasic::Function::Intrinsic::Numeric
3020 );
3021  
3022 # Testpat (regex)
3023  
3024 ##################
3025 # Methods
3026  
3027 sub evaluate {
3028  
3029 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
3030 #
3031 # Expected arguments
3032 # $arg - The first (and only) argument in the argument lisT
3033 #
3034 # Return values
3035 # The return value of the function
3036  
3037 my ($self, $arg) = @_;
3038  
3039 # Local variables
3040 my $value;
3041  
3042 # (No improper arguments to check)
3043  
3044 # Evaluate the function and return the value
3045  
3046 if ($arg eq '' || $axmud::CLIENT->regexCheck($arg)) {
3047 return 0;
3048 } else {
3049 return 1;
3050 }
3051 }
3052 }
3053  
3054 { package Language::Axbasic::Function::Intrinsic::Numeric::time;
3055  
3056 use strict;
3057 use warnings;
3058 use diagnostics;
3059  
3060 use Glib qw(TRUE FALSE);
3061  
3062 @Language::Axbasic::Function::Intrinsic::Numeric::time::ISA = qw(
3063 Language::Axbasic::Function::Intrinsic::Numeric
3064 );
3065  
3066 # Time
3067  
3068 ##################
3069 # Methods
3070  
3071 sub evaluate {
3072  
3073 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
3074 #
3075 # Expected arguments
3076 # $arg - The first (and only) argument in the argument list
3077 #
3078 # Return values
3079 # The return value of the function
3080  
3081 my ($self, $arg) = @_;
3082  
3083 # (No improper arguments to check)
3084  
3085 # Evaluate the function and return the value
3086  
3087 # Get the time
3088 my ($second, $minute, $hour) = localtime();
3089  
3090 # Return the number of seconds since midnight
3091 return ( ($hour * 3600) + ($minute * 60) + $second);
3092 }
3093 }
3094  
3095 { package Language::Axbasic::Function::Intrinsic::Numeric::trunc;
3096  
3097 use strict;
3098 use warnings;
3099 use diagnostics;
3100  
3101 use Glib qw(TRUE FALSE);
3102  
3103 @Language::Axbasic::Function::Intrinsic::Numeric::trunc::ISA = qw(
3104 Language::Axbasic::Function::Intrinsic::Numeric
3105 );
3106  
3107 # Trunc (x)
3108 # Trunc (x, n)
3109  
3110 ##################
3111 # Methods
3112  
3113 sub evaluate {
3114  
3115 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N;N')
3116 #
3117 # Expected arguments
3118 # @args - The list of arguments supplied to the function
3119 #
3120 # Return values
3121 # The return value of the function
3122  
3123 my ($self, @args) = @_;
3124  
3125 # Local variables
3126 my ($number, $decimals, $value);
3127  
3128 # (No improper arguments to check)
3129  
3130 # Evaluate the function and return the value
3131 $number = shift @args;
3132 $decimals = shift @args;
3133 if (! defined $decimals) {
3134  
3135 $decimals = 0;
3136 }
3137  
3138 if ($decimals < 0) {
3139  
3140 return undef;
3141  
3142 } elsif ($decimals == 0) {
3143  
3144 $value = substr(
3145 $number + ( '0.' . '0' x $decimals ),
3146 0,
3147 $decimals + length(int($number))
3148 );
3149  
3150 } else {
3151  
3152 $value = substr(
3153 $number + ( '0.' . '0' x $decimals ),
3154 0,
3155 $decimals + length(int($number)) + 1
3156 );
3157 }
3158  
3159 return $value;
3160 }
3161 }
3162  
3163 { package Language::Axbasic::Function::Intrinsic::Numeric::val;
3164  
3165 use strict;
3166 use warnings;
3167 use diagnostics;
3168  
3169 use Glib qw(TRUE FALSE);
3170  
3171 @Language::Axbasic::Function::Intrinsic::Numeric::val::ISA = qw(
3172 Language::Axbasic::Function::Intrinsic::Numeric
3173 );
3174  
3175 # Val (string)
3176  
3177 ##################
3178 # Methods
3179  
3180 sub evaluate {
3181  
3182 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
3183 #
3184 # Expected arguments
3185 # $arg - The first (and only) argument in the argument list
3186 #
3187 # Return values
3188 # The return value of the function
3189  
3190 my ($self, $arg) = @_;
3191  
3192 # (No improper arguments to check)
3193  
3194 # Evaluate the function and return the value
3195 if (! $axmud::CLIENT->floatCheck($arg)) {
3196 return 0;
3197 } else {
3198 return ($arg + 0);
3199 }
3200 }
3201 }
3202  
3203 { package Language::Axbasic::Function::Intrinsic::Numeric::version;
3204  
3205 use strict;
3206 use warnings;
3207 use diagnostics;
3208  
3209 use Glib qw(TRUE FALSE);
3210  
3211 @Language::Axbasic::Function::Intrinsic::Numeric::version::ISA = qw(
3212 Language::Axbasic::Function::Intrinsic::Numeric
3213 );
3214  
3215 # Version
3216  
3217 ##################
3218 # Methods
3219  
3220 sub evaluate {
3221  
3222 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
3223 #
3224 # Expected arguments
3225 # $arg - The first (and only) argument in the argument list
3226 #
3227 # Return values
3228 # The return value of the function
3229  
3230 my ($self, $arg) = @_;
3231  
3232 # (No improper arguments to check)
3233  
3234 # Evaluate the function and return the value
3235 return $axmud::BASIC_VERSION;
3236 }
3237 }
3238  
3239 ### Pure BASIC functions (string) ###
3240  
3241 { package Language::Axbasic::Function::Intrinsic::String::chr;
3242  
3243 use strict;
3244 use warnings;
3245 use diagnostics;
3246  
3247 use Glib qw(TRUE FALSE);
3248  
3249 @Language::Axbasic::Function::Intrinsic::String::chr::ISA = qw(
3250 Language::Axbasic::Function::Intrinsic::String
3251 );
3252  
3253 # Chr$ (number)
3254  
3255 ##################
3256 # Methods
3257  
3258 sub evaluate {
3259  
3260 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
3261 #
3262 # Expected arguments
3263 # $arg - The first (and only) argument in the argument list
3264 #
3265 # Return values
3266 # The return value of the function
3267  
3268 my ($self, $arg) = @_;
3269  
3270 # (No improper arguments to check)
3271  
3272 # Evaluate the function and return the value
3273 if ($arg < 0 || $arg > 127) {
3274  
3275 return $self->scriptObj->setError(
3276 'number_NUM_out_of_range\'NUM\'',
3277 $self->_objClass . '->evaluate',
3278 'NUM', $arg,
3279 );
3280  
3281 } else {
3282  
3283 return (chr($arg));
3284 }
3285 }
3286 }
3287  
3288 { package Language::Axbasic::Function::Intrinsic::String::date;
3289  
3290 use strict;
3291 use warnings;
3292 use diagnostics;
3293  
3294 use Glib qw(TRUE FALSE);
3295  
3296 @Language::Axbasic::Function::Intrinsic::String::date::ISA = qw(
3297 Language::Axbasic::Function::Intrinsic::String
3298 );
3299  
3300 # Date$ ()
3301  
3302 ##################
3303 # Methods
3304  
3305 sub evaluate {
3306  
3307 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
3308 #
3309 # Expected arguments
3310 # $arg - The first (and only) argument in the argument list
3311 #
3312 # Return values
3313 # The return value of the function
3314  
3315 my ($self, $arg) = @_;
3316  
3317 # (No improper arguments to check)
3318  
3319 # Evaluate the function and return the value
3320  
3321 # Get the time and date
3322 my (
3323 $second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear,
3324 $daylightSavings
3325 ) = localtime();
3326  
3327 my $year = 1900 + $yearOffset;
3328  
3329 # Return the date in the form "YYYYMMDD".
3330 return ($year . sprintf("%02d", ($month + 1)) . sprintf("%02d", $dayOfMonth));
3331 }
3332 }
3333  
3334 { package Language::Axbasic::Function::Intrinsic::String::ip;
3335  
3336 use strict;
3337 use warnings;
3338 use diagnostics;
3339  
3340 use Glib qw(TRUE FALSE);
3341  
3342 @Language::Axbasic::Function::Intrinsic::String::ip::ISA = qw(
3343 Language::Axbasic::Function::Intrinsic::String
3344 );
3345  
3346 # Ip$ ()
3347  
3348 ##################
3349 # Methods
3350  
3351 sub evaluate {
3352  
3353 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
3354 #
3355 # Expected arguments
3356 # $arg - The first (and only) argument in the argument list
3357 #
3358 # Return values
3359 # The return value of the function
3360  
3361 my ($self, $arg) = @_;
3362  
3363 # (No improper arguments to check)
3364  
3365 # Evaluate the function and return the value
3366  
3367 # Get the user's IP
3368 my $ip = $axmud::CLIENT->ipv4Get();
3369 if (! defined $ip) {
3370  
3371 # Failsafe value
3372 $ip = '127.0.0.1';
3373 }
3374  
3375 return $ip;
3376 }
3377 }
3378  
3379 { package Language::Axbasic::Function::Intrinsic::String::lcase;
3380  
3381 use strict;
3382 use warnings;
3383 use diagnostics;
3384  
3385 use Glib qw(TRUE FALSE);
3386  
3387 @Language::Axbasic::Function::Intrinsic::String::lcase::ISA = qw(
3388 Language::Axbasic::Function::Intrinsic::String
3389 );
3390  
3391 # Lcase$ (string)
3392  
3393 ##################
3394 # Methods
3395  
3396 sub evaluate {
3397  
3398 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
3399 #
3400 # Expected arguments
3401 # $arg - The first (and only) argument in the argument list
3402 #
3403 # Return values
3404 # The return value of the function
3405  
3406 my ($self, $arg) = @_;
3407  
3408 # (No improper arguments to check)
3409  
3410 # Evaluate the function and return the value
3411 return lc($arg);
3412 }
3413 }
3414  
3415 { package Language::Axbasic::Function::Intrinsic::String::left;
3416  
3417 use strict;
3418 use warnings;
3419 use diagnostics;
3420  
3421 use Glib qw(TRUE FALSE);
3422  
3423 @Language::Axbasic::Function::Intrinsic::String::left::ISA = qw(
3424 Language::Axbasic::Function::Intrinsic::String
3425 );
3426  
3427 # Left$ (string, length)
3428  
3429 ##################
3430 # Methods
3431  
3432 sub evaluate {
3433  
3434 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN')
3435 #
3436 # Expected arguments
3437 # @args - The list of arguments supplied to the function
3438 #
3439 # Return values
3440 # The return value of the function
3441  
3442 my ($self, @args) = @_;
3443  
3444 # Local variables
3445 my ($string, $length);
3446  
3447 # (No improper arguments to check)
3448  
3449 # Evaluate the function and return the value
3450 ($string, $length) = @args;
3451  
3452 # The value of $length can be 0 (which returns an empty string), but cannot be negative
3453 if ($length < 0) {
3454  
3455 return $self->scriptObj->setError(
3456 'number_NUM_out_of_range',
3457 $self->_objClass . '->evaluate',
3458 'NUM', $length,
3459 );
3460 }
3461  
3462 return substr($string, 0, $length);
3463 }
3464 }
3465  
3466 { package Language::Axbasic::Function::Intrinsic::String::ltrim;
3467  
3468 use strict;
3469 use warnings;
3470 use diagnostics;
3471  
3472 use Glib qw(TRUE FALSE);
3473  
3474 @Language::Axbasic::Function::Intrinsic::String::ltrim::ISA = qw(
3475 Language::Axbasic::Function::Intrinsic::String
3476 );
3477  
3478 # Ltrim$ (string)
3479  
3480 ##################
3481 # Methods
3482  
3483 sub evaluate {
3484  
3485 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
3486 #
3487 # Expected arguments
3488 # $arg - The first (and only) argument in the argument list
3489 #
3490 # Return values
3491 # The return value of the function
3492  
3493 my ($self, $arg) = @_;
3494  
3495 # (No improper arguments to check)
3496  
3497 # Evaluate the function and return the value
3498 $arg =~ s/^\s+//;
3499  
3500 return uc($arg);
3501 }
3502 }
3503  
3504 { package Language::Axbasic::Function::Intrinsic::String::mid;
3505  
3506 use strict;
3507 use warnings;
3508 use diagnostics;
3509  
3510 use Glib qw(TRUE FALSE);
3511  
3512 @Language::Axbasic::Function::Intrinsic::String::mid::ISA = qw(
3513 Language::Axbasic::Function::Intrinsic::String
3514 );
3515  
3516 # Mid$ (string, offset)
3517 # Mid$ (string, offset, length)
3518  
3519 ##################
3520 # Methods
3521  
3522 sub evaluate {
3523  
3524 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN;N')
3525 #
3526 # Expected arguments
3527 # @args - The list of arguments supplied to the function
3528 #
3529 # Return values
3530 # The return value of the function
3531  
3532 my ($self, @args) = @_;
3533  
3534 # Local variables
3535 my ($string, $index, $length);
3536  
3537 # (No improper arguments to check)
3538  
3539 # Evaluate the function and return the value
3540 ($string, $index, $length) = @args;
3541  
3542 # $index must be 1 or more. $length can be (which returns an empty string), but cannot be
3543 # negative
3544 if ($index < 1) {
3545  
3546 return $self->scriptObj->setError(
3547 'number_NUM_out_of_range',
3548 $self->_objClass . '->evaluate',
3549 'NUM', $index,
3550 );
3551  
3552 } elsif ($length < 0) {
3553  
3554 return $self->scriptObj->setError(
3555 'number_NUM_out_of_range',
3556 $self->_objClass . '->evaluate',
3557 'NUM', $length,
3558 );
3559 }
3560  
3561 # Axbasic strings index from 1
3562 $index--;
3563  
3564 if (defined $length) {
3565 return substr($string, $index, $length);
3566 } else {
3567 return substr($string, $index);
3568 }
3569 }
3570 }
3571  
3572 { package Language::Axbasic::Function::Intrinsic::String::repeat;
3573  
3574 use strict;
3575 use warnings;
3576 use diagnostics;
3577  
3578 use Glib qw(TRUE FALSE);
3579  
3580 @Language::Axbasic::Function::Intrinsic::String::repeat::ISA = qw(
3581 Language::Axbasic::Function::Intrinsic::String
3582 );
3583  
3584 # Repeat$ (string, n)
3585  
3586 ##################
3587 # Methods
3588  
3589 sub evaluate {
3590  
3591 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN')
3592 #
3593 # Expected arguments
3594 # $string, $number
3595 # - The list of arguments supplied to the function
3596 #
3597 # Return values
3598 # The return value of the function
3599  
3600 my ($self, $string, $number) = @_;
3601  
3602 # (No improper arguments to check)
3603  
3604 # Evaluate the function and return the value
3605  
3606 # $number must not be a negative number
3607 if ($number < 0) {
3608  
3609 return $self->scriptObj->setError(
3610 'number_NUM_out_of_range',
3611 $self->_objClass . '->evaluate',
3612 'NUM', $number,
3613 );
3614 }
3615  
3616 # $number must be rounded
3617 $number = substr(
3618 $number + 0.5,
3619 0,
3620 length(int($number + 0.5)),
3621 );
3622  
3623 return ($string x $number);
3624 }
3625 }
3626  
3627 { package Language::Axbasic::Function::Intrinsic::String::right;
3628  
3629 use strict;
3630 use warnings;
3631 use diagnostics;
3632  
3633 use Glib qw(TRUE FALSE);
3634  
3635 @Language::Axbasic::Function::Intrinsic::String::right::ISA = qw(
3636 Language::Axbasic::Function::Intrinsic::String
3637 );
3638  
3639 # Right$ (string, length)
3640  
3641 ##################
3642 # Methods
3643  
3644 sub evaluate {
3645  
3646 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SN')
3647 #
3648 # Expected arguments
3649 # @args - The list of arguments supplied to the function
3650 #
3651 # Return values
3652 # The return value of the function
3653  
3654 my ($self, @args) = @_;
3655  
3656 # Local variables
3657 my ($string, $length);
3658  
3659 # (No improper arguments to check)
3660  
3661 # Evaluate the function and return the value
3662 ($string, $length) = @args;
3663  
3664 # The value of $length can be 0 (which returns an empty string), but cannot be negative
3665 if ($length < 0) {
3666  
3667 return $self->scriptObj->setError(
3668 'number_NUM_out_of_range',
3669 $self->_objClass . '->evaluate',
3670 'NUM', $length,
3671 );
3672 }
3673  
3674 return substr($string, ($length * -1));
3675 }
3676 }
3677  
3678 { package Language::Axbasic::Function::Intrinsic::String::rtrim;
3679  
3680 use strict;
3681 use warnings;
3682 use diagnostics;
3683  
3684 use Glib qw(TRUE FALSE);
3685  
3686 @Language::Axbasic::Function::Intrinsic::String::rtrim::ISA = qw(
3687 Language::Axbasic::Function::Intrinsic::String
3688 );
3689  
3690 # Rtrim$ (string)
3691  
3692 ##################
3693 # Methods
3694  
3695 sub evaluate {
3696  
3697 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
3698 #
3699 # Expected arguments
3700 # $arg - The first (and only) argument in the argument list
3701 #
3702 # Return values
3703 # The return value of the function
3704  
3705 my ($self, $arg) = @_;
3706  
3707 # (No improper arguments to check)
3708  
3709 # Evaluate the function and return the value
3710 $arg =~ s/\s+$//;
3711  
3712 return uc($arg);
3713 }
3714 }
3715  
3716 { package Language::Axbasic::Function::Intrinsic::String::str;
3717  
3718 use strict;
3719 use warnings;
3720 use diagnostics;
3721  
3722 use Glib qw(TRUE FALSE);
3723  
3724 @Language::Axbasic::Function::Intrinsic::String::str::ISA = qw(
3725 Language::Axbasic::Function::Intrinsic::String
3726 );
3727  
3728 # Str$ (number)
3729  
3730 ##################
3731 # Methods
3732  
3733 sub evaluate {
3734  
3735 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
3736 #
3737 # Expected arguments
3738 # $arg - The first (and only) argument in the argument list
3739 #
3740 # Return values
3741 # The return value of the function
3742  
3743 my ($self, $arg) = @_;
3744  
3745 # (No improper arguments to check)
3746  
3747 # Evaluate the function and return the value
3748 return $arg . '';
3749 }
3750 }
3751  
3752 { package Language::Axbasic::Function::Intrinsic::String::testpat;
3753  
3754 use strict;
3755 use warnings;
3756 use diagnostics;
3757  
3758 use Glib qw(TRUE FALSE);
3759  
3760 @Language::Axbasic::Function::Intrinsic::String::testpat::ISA = qw(
3761 Language::Axbasic::Function::Intrinsic::String
3762 );
3763  
3764 # Testpat$ (regex)
3765  
3766 ##################
3767 # Methods
3768  
3769 sub evaluate {
3770  
3771 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
3772 #
3773 # Expected arguments
3774 # $arg - The first (and only) argument in the argument list
3775 #
3776 # Return values
3777 # The return value of the function
3778  
3779 my ($self, $arg) = @_;
3780  
3781 # Local variables
3782 my $result;
3783  
3784 # (No improper arguments to check)
3785  
3786 # Evaluate the function and return the value
3787  
3788 $result = $axmud::CLIENT->regexCheck($arg);
3789  
3790 if ($arg eq '' || ! defined $result) {
3791 return '';
3792 } else {
3793 return $result;
3794 }
3795 }
3796 }
3797  
3798 { package Language::Axbasic::Function::Intrinsic::String::time;
3799  
3800 use strict;
3801 use warnings;
3802 use diagnostics;
3803  
3804 use Glib qw(TRUE FALSE);
3805  
3806 @Language::Axbasic::Function::Intrinsic::String::time::ISA = qw(
3807 Language::Axbasic::Function::Intrinsic::String
3808 );
3809  
3810 # Time$ ()
3811  
3812 ##################
3813 # Methods
3814  
3815 sub evaluate {
3816  
3817 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
3818 #
3819 # Expected arguments
3820 # $arg - The first (and only) argument in the argument list
3821 #
3822 # Return values
3823 # The return value of the function
3824  
3825 my ($self, $arg) = @_;
3826  
3827 # (No improper arguments to check)
3828  
3829 # Evaluate the function and return the value
3830  
3831 # Get the time
3832 my ($second, $minute, $hour) = localtime();
3833  
3834 # Return the time in the form "HH:MM:SS"
3835 return (
3836 sprintf("%02d", ($hour))
3837 . ':' . sprintf("%02d", ($minute))
3838 . ':' . sprintf("%02d", ($second)),
3839 );
3840 }
3841 }
3842  
3843 { package Language::Axbasic::Function::Intrinsic::String::trim;
3844  
3845 use strict;
3846 use warnings;
3847 use diagnostics;
3848  
3849 use Glib qw(TRUE FALSE);
3850  
3851 @Language::Axbasic::Function::Intrinsic::String::trim::ISA = qw(
3852 Language::Axbasic::Function::Intrinsic::String
3853 );
3854  
3855 # Trim$ (string)
3856  
3857 ##################
3858 # Methods
3859  
3860 sub evaluate {
3861  
3862 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
3863 #
3864 # Expected arguments
3865 # $arg - The first (and only) argument in the argument list
3866 #
3867 # Return values
3868 # The return value of the function
3869  
3870 my ($self, $arg) = @_;
3871  
3872 # (No improper arguments to check)
3873  
3874 # Evaluate the function and return the value
3875 $arg =~ s/^\s+//;
3876 $arg =~ s/\s+$//;
3877  
3878 return uc($arg);
3879 }
3880 }
3881  
3882 { package Language::Axbasic::Function::Intrinsic::String::ucase;
3883  
3884 use strict;
3885 use warnings;
3886 use diagnostics;
3887  
3888 use Glib qw(TRUE FALSE);
3889  
3890 @Language::Axbasic::Function::Intrinsic::String::ucase::ISA = qw(
3891 Language::Axbasic::Function::Intrinsic::String
3892 );
3893  
3894 # Ucase$ (string)
3895  
3896 ##################
3897 # Methods
3898  
3899 sub evaluate {
3900  
3901 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
3902 #
3903 # Expected arguments
3904 # $arg - The first (and only) argument in the argument list
3905 #
3906 # Return values
3907 # The return value of the function
3908  
3909 my ($self, $arg) = @_;
3910  
3911 # (No improper arguments to check)
3912  
3913 # Evaluate the function and return the value
3914 return uc($arg);
3915 }
3916 }
3917  
3918 ### Axmud-dependent functions (numeric) ###
3919  
3920 { package Language::Axbasic::Function::Intrinsic::Numeric::addfirstroom;
3921  
3922 use strict;
3923 use warnings;
3924 use diagnostics;
3925  
3926 use Glib qw(TRUE FALSE);
3927  
3928 @Language::Axbasic::Function::Intrinsic::Numeric::addfirstroom::ISA = qw(
3929 Language::Axbasic::Function::Intrinsic::Numeric
3930 );
3931  
3932 # Addfirstroom ()
3933  
3934 ##################
3935 # Methods
3936  
3937 sub evaluate {
3938  
3939 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
3940 #
3941 # Expected arguments
3942 # $arg - The first (and only) argument in the argument list
3943 #
3944 # Return values
3945 # The return value of the function
3946  
3947 my ($self, $arg) = @_;
3948  
3949 # Local variables
3950 my $mapWin;
3951  
3952 # (No improper arguments to check)
3953  
3954 # Evaluate the function and return the value
3955 $mapWin = $self->scriptObj->session->mapWin;
3956  
3957 if (! $mapWin || ! $mapWin->currentRegionmap || $mapWin->currentRegionmap->gridRoomHash) {
3958  
3959 # Automapper window not open, no current regionmap or the current regionmap isn't
3960 # empty
3961 return 0;
3962 }
3963  
3964 # Attemp to add a first room
3965 if (! $mapWin->addFirstRoomCallback()) {
3966  
3967 # Operation failed
3968 return 0;
3969  
3970 } else {
3971  
3972 # Return the number of the room created
3973 return $mapWin->mapObj->currentRoom->number;
3974 }
3975 }
3976 }
3977  
3978 { package Language::Axbasic::Function::Intrinsic::Numeric::addlabel;
3979  
3980 use strict;
3981 use warnings;
3982 use diagnostics;
3983  
3984 use Glib qw(TRUE FALSE);
3985  
3986 @Language::Axbasic::Function::Intrinsic::Numeric::addlabel::ISA = qw(
3987 Language::Axbasic::Function::Intrinsic::Numeric
3988 );
3989  
3990 # Addlabel (string, x, y, z)
3991  
3992 ##################
3993 # Methods
3994  
3995 sub evaluate {
3996  
3997 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SNNN')
3998 #
3999 # Expected arguments
4000 # @args - The list of arguments supplied to the function
4001 #
4002 # Return values
4003 # The return value of the function
4004  
4005 my ($self, @args) = @_;
4006  
4007 # Local variables
4008 my ($mapObj, $wmObj, $regionmapObj, $xPos, $yPos, $zPos, $labelObj);
4009  
4010 # (No improper arguments to check)
4011  
4012 # Evaluate the function and return the value
4013 $mapObj = $self->scriptObj->session->mapObj;
4014 $wmObj = $mapObj->worldModelObj;
4015  
4016 if (
4017 ! $mapObj->currentRoom
4018 || ! $args[0]
4019 ) {
4020 # No current room or empty label string
4021 return 0;
4022 }
4023  
4024 # Get the current room's parent regionmap
4025 $regionmapObj = $wmObj->findRegionmap($mapObj->currentRoom->parent);
4026 if (! $regionmapObj) {
4027  
4028 # Failsafe
4029 return 0;
4030 }
4031  
4032 # Get the current room's coordinates on the grid, and add (or subtract) the relative
4033 # coordinates in the argument list
4034 $xPos = $mapObj->currentRoom->xPosBlocks + $args[1];
4035 $yPos = $mapObj->currentRoom->yPosBlocks + $args[2];
4036 $zPos = $mapObj->currentRoom->zPosBlocks + $args[3];
4037  
4038 # Check that the gridblock is valid
4039 if (! $regionmapObj->checkGridBlock($xPos, $yPos, $zPos)) {
4040  
4041 return 0;
4042 }
4043  
4044 # Attempt to add the label
4045 $labelObj = $wmObj->addLabel(
4046 $self->scriptObj->session,
4047 TRUE, # Update Automapper windows now
4048 $regionmapObj,
4049 ($xPos * $regionmapObj->blockWidthPixels),
4050 ($yPos * $regionmapObj->blockHeightPixels),
4051 $zPos,
4052 $args[0],
4053 );
4054  
4055 if (! $labelObj) {
4056 return 0;
4057 } else {
4058 return $labelObj->number;
4059 }
4060 }
4061 }
4062  
4063 { package Language::Axbasic::Function::Intrinsic::Numeric::addregion;
4064  
4065 use strict;
4066 use warnings;
4067 use diagnostics;
4068  
4069 use Glib qw(TRUE FALSE);
4070  
4071 @Language::Axbasic::Function::Intrinsic::Numeric::addregion::ISA = qw(
4072 Language::Axbasic::Function::Intrinsic::Numeric
4073 );
4074  
4075 # Addregion (string)
4076  
4077 ##################
4078 # Methods
4079  
4080 sub evaluate {
4081  
4082 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
4083 #
4084 # Expected arguments
4085 # $arg - The first (and only) argument in the argument list
4086 #
4087 # Return values
4088 # The return value of the function
4089  
4090 my ($self, $arg) = @_;
4091  
4092 # Local variables
4093 my $regionObj;
4094  
4095 # (No improper arguments to check)
4096  
4097 # Evaluate the function and return the value
4098 $regionObj = $self->scriptObj->session->worldModelObj->addRegion(
4099 $self->scriptObj->session,
4100 TRUE, # Update Automapper windows now
4101 $arg,
4102 );
4103  
4104 if (! $regionObj) {
4105 return 0;
4106 } else {
4107 return $regionObj->number;
4108 }
4109 }
4110 }
4111  
4112 { package Language::Axbasic::Function::Intrinsic::Numeric::addroom;
4113  
4114 use strict;
4115 use warnings;
4116 use diagnostics;
4117  
4118 use Glib qw(TRUE FALSE);
4119  
4120 @Language::Axbasic::Function::Intrinsic::Numeric::addroom::ISA = qw(
4121 Language::Axbasic::Function::Intrinsic::Numeric
4122 );
4123  
4124 # Addroom (x, y, z)
4125  
4126 ##################
4127 # Methods
4128  
4129 sub evaluate {
4130  
4131 # Called by LA::Expression::Function->evaluate (using arguments in the form 'NNN')
4132 #
4133 # Expected arguments
4134 # @args - The list of arguments supplied to the function
4135 #
4136 # Return values
4137 # The return value of the function
4138  
4139 my ($self, @args) = @_;
4140  
4141 # Local variables
4142 my ($mapObj, $wmObj, $regionmapObj, $xPos, $yPos, $zPos, $roomObj);
4143  
4144 # (No improper arguments to check)
4145  
4146 # Evaluate the function and return the value
4147 $mapObj = $self->scriptObj->session->mapObj;
4148 $wmObj = $mapObj->worldModelObj;
4149  
4150 if (! $mapObj->currentRoom ) {
4151  
4152 # No current room
4153 return 0;
4154 }
4155  
4156 # Get the current room's parent regionmap
4157 $regionmapObj = $wmObj->findRegionmap($mapObj->currentRoom->parent);
4158 if (! $regionmapObj) {
4159  
4160 # Failsafe
4161 return 0;
4162 }
4163  
4164 # Get the current room's coordinates on the grid, and add (or subtract) the relative
4165 # coordinates in the argument list
4166 $xPos = $mapObj->currentRoom->xPosBlocks + $args[0];
4167 $yPos = $mapObj->currentRoom->yPosBlocks + $args[1];
4168 $zPos = $mapObj->currentRoom->zPosBlocks + $args[2];
4169  
4170 # Check that the gridblock is valid and not occupied by an existing room
4171 if (
4172 ! $regionmapObj->checkGridBlock($xPos, $yPos, $zPos)
4173 || $regionmapObj->fetchRoom($xPos, $yPos, $zPos)
4174 ) {
4175 return 0;
4176 }
4177  
4178 # Attempt to add the room
4179 $roomObj = $wmObj->addRoom(
4180 $self->scriptObj->session,
4181 TRUE, # Update Automapper windows now
4182 $regionmapObj->name,
4183 $xPos,
4184 $yPos,
4185 $zPos,
4186 );
4187  
4188 if (! $roomObj) {
4189 return 0;
4190 } else {
4191 return $roomObj->number;
4192 }
4193 }
4194 }
4195  
4196 { package Language::Axbasic::Function::Intrinsic::Numeric::addtempregion;
4197  
4198 use strict;
4199 use warnings;
4200 use diagnostics;
4201  
4202 use Glib qw(TRUE FALSE);
4203  
4204 @Language::Axbasic::Function::Intrinsic::Numeric::addtempregion::ISA = qw(
4205 Language::Axbasic::Function::Intrinsic::Numeric
4206 );
4207  
4208 # Addtempregion ()
4209 # Addtempregion (string)
4210  
4211 ##################
4212 # Methods
4213  
4214 sub evaluate {
4215  
4216 # Called by LA::Expression::Function->evaluate (using arguments in the form ';S')
4217 #
4218 # Expected arguments
4219 # $arg - The first (and only) argument in the argument list
4220 #
4221 # Return values
4222 # The return value of the function
4223  
4224 my ($self, $arg) = @_;
4225  
4226 # Local variables
4227 my (
4228 $wmObj, $count, $name, $regionObj,
4229 %regionHash,
4230 );
4231  
4232 # (No improper arguments to check)
4233  
4234 # Evaluate the function and return the value
4235 $wmObj = $self->scriptObj->session->worldModelObj;
4236  
4237 # If a region name wasn't specified, we have to create one in the form 'temp_x'. To protect
4238 # against infinite loops, give up at 9999
4239 if (! $arg) {
4240  
4241 # Get a convenient hash of region names for quick lookup
4242 foreach my $obj ($wmObj->ivValues('regionModelHash')) {
4243  
4244 if ($obj->name) {
4245  
4246 $regionHash{$obj->name} = undef;
4247 }
4248 }
4249  
4250 # First temporary region would be called 'temp_1'
4251 $count = 0;
4252 do {
4253  
4254 $count++;
4255 my $string = 'temp_' . $count;
4256  
4257 if (! exists $regionHash{$string}) {
4258  
4259 # We can use this name
4260 $name = $string;
4261 }
4262  
4263 } until ($name || $count >= 9999);
4264  
4265 } else {
4266  
4267 $name = $arg;
4268 }
4269  
4270 if (! $name) {
4271  
4272 # Could not find a name for the temporary region
4273 return 0;
4274 }
4275  
4276 # Add the temporary region
4277 $regionObj = $wmObj->addRegion(
4278 $self->scriptObj->session,
4279 TRUE, # Update Automapper windows now
4280 $name,
4281 undef, # No parent region
4282 TRUE, # Temporary region
4283 );
4284  
4285 if (! $regionObj) {
4286 return 0;
4287 } else {
4288 return $regionObj->number;
4289 }
4290 }
4291 }
4292  
4293 { package Language::Axbasic::Function::Intrinsic::Numeric::closemap;
4294  
4295 use strict;
4296 use warnings;
4297 use diagnostics;
4298  
4299 use Glib qw(TRUE FALSE);
4300  
4301 @Language::Axbasic::Function::Intrinsic::Numeric::closemap::ISA = qw(
4302 Language::Axbasic::Function::Intrinsic::Numeric
4303 );
4304  
4305 # Closemap ()
4306  
4307 ##################
4308 # Methods
4309  
4310 sub evaluate {
4311  
4312 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
4313 #
4314 # Expected arguments
4315 # $arg - The first (and only) argument in the argument list
4316 #
4317 # Return values
4318 # The return value of the function
4319  
4320 my ($self, $arg) = @_;
4321  
4322 # Local variables
4323 my $mapWin;
4324  
4325 # (No improper arguments to check)
4326  
4327 # Evaluate the function and return the value
4328 $mapWin = $self->scriptObj->session->mapWin;
4329 if (! $mapWin) {
4330  
4331 # The window is already closed
4332 return 1;
4333  
4334 } else {
4335  
4336 # Try to close the window
4337 $mapWin->winDestroy();
4338  
4339 if (! $self->scriptObj->session->mapWin) {
4340  
4341 # Window closed successfully
4342 return 1;
4343  
4344 } else {
4345  
4346 # Could not close window
4347 return 0;
4348 }
4349 }
4350 }
4351 }
4352  
4353 { package Language::Axbasic::Function::Intrinsic::Numeric::counttask;
4354  
4355 use strict;
4356 use warnings;
4357 use diagnostics;
4358  
4359 use Glib qw(TRUE FALSE);
4360  
4361 @Language::Axbasic::Function::Intrinsic::Numeric::counttask::ISA = qw(
4362 Language::Axbasic::Function::Intrinsic::Numeric
4363 );
4364  
4365 # Counttask (string)
4366  
4367 ##################
4368 # Methods
4369  
4370 sub evaluate {
4371  
4372 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
4373 #
4374 # Expected arguments
4375 # $arg - The first (and only) argument in the argument list
4376 #
4377 # Return values
4378 # The return value of the function
4379  
4380 my ($self, $arg) = @_;
4381  
4382 # Local variables
4383 my @list;
4384  
4385 # (No improper arguments to check)
4386  
4387 # Evaluate the function and return the value
4388  
4389 # Get a list of tasks in the current tasklist which match $arg. The ->findTask function
4390 # usually accepts the string '-a', but this Axbasic function does not
4391 if ($arg ne '-a') {
4392  
4393 @list = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $arg);
4394 }
4395  
4396 return scalar @list;
4397 }
4398 }
4399  
4400 { package Language::Axbasic::Function::Intrinsic::Numeric::delregion;
4401  
4402 use strict;
4403 use warnings;
4404 use diagnostics;
4405  
4406 use Glib qw(TRUE FALSE);
4407  
4408 @Language::Axbasic::Function::Intrinsic::Numeric::delregion::ISA = qw(
4409 Language::Axbasic::Function::Intrinsic::Numeric
4410 );
4411  
4412 # Delregion (string)
4413  
4414 ##################
4415 # Methods
4416  
4417 sub evaluate {
4418  
4419 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
4420 #
4421 # Expected arguments
4422 # $arg - The first (and only) argument in the argument list
4423 #
4424 # Return values
4425 # The return value of the function
4426  
4427 my ($self, $arg) = @_;
4428  
4429 # Local variables
4430 my ($wmObj, $regionmapObj, $obj);
4431  
4432 # (No improper arguments to check)
4433  
4434 # Evaluate the function and return the value
4435 $wmObj = $self->scriptObj->session->worldModelObj;
4436  
4437 # Find a region model object whose name matches $arg
4438 $regionmapObj = $wmObj->ivShow('regionmapHash', $arg);
4439 if ($regionmapObj) {
4440  
4441 $obj = $wmObj->ivShow('modelHash', $regionmapObj->number);
4442 }
4443  
4444 if (! $obj) {
4445  
4446 # No region whose name matches $arg
4447 return 0;
4448  
4449 } else {
4450  
4451 # Delete the region and all its children (including its rooms and their contents)
4452 if (
4453 ! $wmObj->deleteRegions(
4454 $self->scriptObj->session,
4455 TRUE, # Update Automapper windows now
4456 $obj,
4457 )
4458 ) {
4459 return 0;
4460 } else {
4461 return 1;
4462 }
4463 }
4464 }
4465 }
4466  
4467 { package Language::Axbasic::Function::Intrinsic::Numeric::deltempregions;
4468  
4469 use strict;
4470 use warnings;
4471 use diagnostics;
4472  
4473 use Glib qw(TRUE FALSE);
4474  
4475 @Language::Axbasic::Function::Intrinsic::Numeric::deltempregions::ISA = qw(
4476 Language::Axbasic::Function::Intrinsic::Numeric
4477 );
4478  
4479 # Deltempregions ()
4480  
4481 ##################
4482 # Methods
4483  
4484 sub evaluate {
4485  
4486 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
4487 #
4488 # Expected arguments
4489 # $arg - The first (and only) argument in the argument list
4490 #
4491 # Return values
4492 # The return value of the function
4493  
4494 my ($self, $arg) = @_;
4495  
4496 # (No improper arguments to check)
4497  
4498 # Evaluate the function and return the value
4499 if (
4500 ! $self->scriptObj->session->worldModelObj->deleteTempRegions(
4501 $self->scriptObj->session,
4502 TRUE, # Update Automapper windows now
4503 )
4504 ) {
4505 return 0;
4506 } else {
4507 return 1;
4508 }
4509 }
4510 }
4511  
4512 { package Language::Axbasic::Function::Intrinsic::Numeric::getexitdest;
4513  
4514 use strict;
4515 use warnings;
4516 use diagnostics;
4517  
4518 use Glib qw(TRUE FALSE);
4519  
4520 @Language::Axbasic::Function::Intrinsic::Numeric::getexitdest::ISA = qw(
4521 Language::Axbasic::Function::Intrinsic::Numeric
4522 );
4523  
4524 # Getexitdest (number)
4525  
4526 ##################
4527 # Methods
4528  
4529 sub evaluate {
4530  
4531 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
4532 #
4533 # Expected arguments
4534 # $arg - The first (and only) argument in the argument list
4535 #
4536 # Return values
4537 # The return value of the function
4538  
4539 my ($self, $arg) = @_;
4540  
4541 # Local variables
4542 my ($mapObj, $wmObj, $dir, $modelNum, $obj);
4543  
4544 # (No improper arguments to check)
4545  
4546 # Evaluate the function and return the value
4547 $mapObj = $self->scriptObj->session->mapObj;
4548 $wmObj = $mapObj->worldModelObj;
4549  
4550 # Perl indexes start at 0, but Axbasic indexes start at 1
4551 $arg--;
4552  
4553 if (
4554 ! $mapObj->currentRoom
4555 || ! $mapObj->currentRoom->sortedExitList
4556 || $arg < 0
4557 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
4558 ) {
4559 # No current room, no exits in current room or invalid exit number
4560 return 0;
4561  
4562 } else {
4563  
4564 # Get the exit model object
4565 $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
4566 $modelNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir);
4567 if (! $modelNum || ! $wmObj->ivExists('exitModelHash', $modelNum)) {
4568  
4569 # Exit model object not found
4570 return 0;
4571  
4572 } else {
4573  
4574 $obj = $wmObj->ivShow('exitModelHash', $modelNum);
4575 if (! $obj->destRoom || $obj->randomType ne 'none') {
4576  
4577 # Exit doesn't have a destination room, or leads to a random destination
4578 return 0;
4579  
4580 } else {
4581  
4582 # Return the numbered exit's destination room
4583 return $obj->destRoom;
4584 }
4585 }
4586 }
4587 }
4588 }
4589  
4590 { package Language::Axbasic::Function::Intrinsic::Numeric::getexitnum;
4591  
4592 use strict;
4593 use warnings;
4594 use diagnostics;
4595  
4596 use Glib qw(TRUE FALSE);
4597  
4598 @Language::Axbasic::Function::Intrinsic::Numeric::getexitnum::ISA = qw(
4599 Language::Axbasic::Function::Intrinsic::Numeric
4600 );
4601  
4602 # Getexitnum (number)
4603  
4604 ##################
4605 # Methods
4606  
4607 sub evaluate {
4608  
4609 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
4610 #
4611 # Expected arguments
4612 # $arg - The first (and only) argument in the argument list
4613 #
4614 # Return values
4615 # The return value of the function
4616  
4617 my ($self, $arg) = @_;
4618  
4619 # Local variables
4620 my ($mapObj, $wmObj, $dir, $modelNum);
4621  
4622 # (No improper arguments to check)
4623  
4624 # Evaluate the function and return the value
4625 $mapObj = $self->scriptObj->session->mapObj;
4626 $wmObj = $mapObj->worldModelObj;
4627  
4628 # Perl indexes start at 0, but Axbasic indexes start at 1
4629 $arg--;
4630  
4631 if (
4632 ! $mapObj->currentRoom
4633 || ! $mapObj->currentRoom->sortedExitList
4634 || $arg < 0
4635 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
4636 ) {
4637 # No current room, no exits in current room or invalid exit number
4638 return 0;
4639  
4640 } else {
4641  
4642 # Get the exit model object
4643 $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
4644 $modelNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir);
4645 if (! $modelNum || ! $wmObj->ivExists('exitModelHash', $modelNum)) {
4646  
4647 # Exit model object not found
4648 return 0;
4649  
4650 } else {
4651  
4652 # Return the exit model number
4653 return $modelNum;
4654 }
4655 }
4656 }
4657 }
4658  
4659 { package Language::Axbasic::Function::Intrinsic::Numeric::getexittwin;
4660  
4661 use strict;
4662 use warnings;
4663 use diagnostics;
4664  
4665 use Glib qw(TRUE FALSE);
4666  
4667 @Language::Axbasic::Function::Intrinsic::Numeric::getexittwin::ISA = qw(
4668 Language::Axbasic::Function::Intrinsic::Numeric
4669 );
4670  
4671 # Getexittwin (number)
4672  
4673 ##################
4674 # Methods
4675  
4676 sub evaluate {
4677  
4678 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
4679 #
4680 # Expected arguments
4681 # $arg - The first (and only) argument in the argument list
4682 #
4683 # Return values
4684 # The return value of the function
4685  
4686 my ($self, $arg) = @_;
4687  
4688 # Local variables
4689 my ($mapObj, $wmObj, $dir, $modelNum, $obj);
4690  
4691 # (No improper arguments to check)
4692  
4693 # Evaluate the function and return the value
4694 $mapObj = $self->scriptObj->session->mapObj;
4695 $wmObj = $mapObj->worldModelObj;
4696  
4697 # Perl indexes start at 0, but Axbasic indexes start at 1
4698 $arg--;
4699  
4700 if (
4701 ! $mapObj->currentRoom
4702 || ! $mapObj->currentRoom->sortedExitList
4703 || $arg < 0
4704 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
4705 ) {
4706 # No current room, no exits in current room or invalid exit number
4707 return 0;
4708  
4709 } else {
4710  
4711 # Get the exit model object
4712 $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
4713 $modelNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir);
4714 if (! $modelNum || ! $wmObj->ivExists('exitModelHash', $modelNum)) {
4715  
4716 # Exit model object not found
4717 return 0;
4718  
4719 } else {
4720  
4721 $obj = $wmObj->ivShow('exitModelHash', $modelNum);
4722 if (! $obj->twinExit) {
4723  
4724 # Exit doesn't have a twin exit
4725 return 0;
4726  
4727 } else {
4728  
4729 # Return the numbered exit's twin exit
4730 return $obj->twinExit;
4731 }
4732 }
4733 }
4734 }
4735 }
4736  
4737 { package Language::Axbasic::Function::Intrinsic::Numeric::getlostroom;
4738  
4739 use strict;
4740 use warnings;
4741 use diagnostics;
4742  
4743 use Glib qw(TRUE FALSE);
4744  
4745 @Language::Axbasic::Function::Intrinsic::Numeric::getlostroom::ISA = qw(
4746 Language::Axbasic::Function::Intrinsic::Numeric
4747 );
4748  
4749 # Getlostroom ()
4750  
4751 ##################
4752 # Methods
4753  
4754 sub evaluate {
4755  
4756 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
4757 #
4758 # Expected arguments
4759 # $arg - The first (and only) argument in the argument list
4760 #
4761 # Return values
4762 # The return value of the function
4763  
4764 my ($self, $arg) = @_;
4765  
4766 # Local variables
4767 my $mapObj;
4768  
4769 # (No improper arguments to check)
4770  
4771 # Evaluate the function and return the value
4772 $mapObj = $self->scriptObj->session->mapObj;
4773 if (! $mapObj->lastKnownRoom) {
4774  
4775 # Automapper not lost
4776 return 0;
4777  
4778 } else {
4779  
4780 # Automapper is lost. Return the number of the previous room
4781 return $mapObj->lastKnownRoom->number;
4782 }
4783 }
4784 }
4785  
4786 { package Language::Axbasic::Function::Intrinsic::Numeric::getobjectalive;
4787  
4788 use strict;
4789 use warnings;
4790 use diagnostics;
4791  
4792 use Glib qw(TRUE FALSE);
4793  
4794 @Language::Axbasic::Function::Intrinsic::Numeric::getobjectalive::ISA = qw(
4795 Language::Axbasic::Function::Intrinsic::Numeric
4796 );
4797  
4798 # Getobjectalive (number)
4799  
4800 ##################
4801 # Methods
4802  
4803 sub evaluate {
4804  
4805 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
4806 #
4807 # Expected arguments
4808 # $arg - The first (and only) argument in the argument list
4809 #
4810 # Return values
4811 # The return value of the function
4812  
4813 my ($self, $arg) = @_;
4814  
4815 # Local variables
4816 my ($taskObj, $roomObj, $thisObj);
4817  
4818 # (No improper arguments to check)
4819  
4820 # Evaluate the function and return the value
4821 $taskObj = $self->scriptObj->session->locatorTask;
4822 if (! $taskObj) {
4823  
4824 # Locator task not running
4825 return 0;
4826 }
4827  
4828 # Perl indexes start at 0, but Axbasic indexes start at 1
4829 $arg--;
4830  
4831 $roomObj = $taskObj->roomObj;
4832 if (
4833 ! $roomObj
4834 || ! $roomObj->tempObjList
4835 || $arg < 0
4836 || scalar $roomObj->tempObjList <= $arg
4837 ) {
4838 # Locator task doesn't know current location, current location is empty or the
4839 # numbered object doesn't exist
4840 return 0;
4841  
4842 } else {
4843  
4844 # Return the object's ->aliveFlag
4845 $thisObj = $roomObj->ivIndex('tempObjList', $arg);
4846 if (! $thisObj->aliveFlag) {
4847 return 0;
4848 } else {
4849 return 1;
4850 }
4851 }
4852 }
4853 }
4854  
4855 { package Language::Axbasic::Function::Intrinsic::Numeric::getobjectcount;
4856  
4857 use strict;
4858 use warnings;
4859 use diagnostics;
4860  
4861 use Glib qw(TRUE FALSE);
4862  
4863 @Language::Axbasic::Function::Intrinsic::Numeric::getobjectcount::ISA = qw(
4864 Language::Axbasic::Function::Intrinsic::Numeric
4865 );
4866  
4867 # Getobjectcount (number)
4868  
4869 ##################
4870 # Methods
4871  
4872 sub evaluate {
4873  
4874 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
4875 #
4876 # Expected arguments
4877 # $arg - The first (and only) argument in the argument list
4878 #
4879 # Return values
4880 # The return value of the function
4881  
4882 my ($self, $arg) = @_;
4883  
4884 # Local variables
4885 my ($taskObj, $roomObj, $thisObj);
4886  
4887 # (No improper arguments to check)
4888  
4889 # Evaluate the function and return the value
4890 $taskObj = $self->scriptObj->session->locatorTask;
4891 if (! $taskObj) {
4892  
4893 # Locator task not running
4894 return 0;
4895 }
4896  
4897 # Perl indexes start at 0, but Axbasic indexes start at 1
4898 $arg--;
4899  
4900 $roomObj = $taskObj->roomObj;
4901 if (
4902 ! $roomObj
4903 || ! $roomObj->tempObjList
4904 || $arg < 0
4905 || scalar $roomObj->tempObjList <= $arg
4906 ) {
4907 # Locator task doesn't know current location, current location is empty or the
4908 # numbered object doesn't exist
4909 return 0;
4910  
4911 } else {
4912  
4913 # Return the object's ->multiple
4914 $thisObj = $roomObj->ivIndex('tempObjList', $arg);
4915 if (! $thisObj->multiple) {
4916  
4917 # Make sure we don't return an 'undef' value (unlikely)
4918 return 0;
4919  
4920 } else {
4921  
4922 return $thisObj->multiple;
4923 }
4924 }
4925 }
4926 }
4927  
4928 { package Language::Axbasic::Function::Intrinsic::Numeric::getregionnum;
4929  
4930 use strict;
4931 use warnings;
4932 use diagnostics;
4933  
4934 use Glib qw(TRUE FALSE);
4935  
4936 @Language::Axbasic::Function::Intrinsic::Numeric::getregionnum::ISA = qw(
4937 Language::Axbasic::Function::Intrinsic::Numeric
4938 );
4939  
4940 # Getregionnum ()
4941  
4942 ##################
4943 # Methods
4944  
4945 sub evaluate {
4946  
4947 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
4948 #
4949 # Expected arguments
4950 # $arg - The first (and only) argument in the argument list
4951 #
4952 # Return values
4953 # The return value of the function
4954  
4955 my ($self, $arg) = @_;
4956  
4957 # Local variables
4958 my $mapWin;
4959  
4960 # (No improper arguments to check)
4961  
4962 # Evaluate the function and return the value
4963 $mapWin = $self->scriptObj->session->mapWin;
4964 if (! $mapWin || ! $mapWin->currentRegionmap) {
4965  
4966 # Automapper window closed, or no current region
4967 return 0;
4968  
4969 } else {
4970  
4971 # Return the number of the current region
4972 return $mapWin->currentRegionmap->number;
4973 }
4974 }
4975 }
4976  
4977 { package Language::Axbasic::Function::Intrinsic::Numeric::getroomexits;
4978  
4979 use strict;
4980 use warnings;
4981 use diagnostics;
4982  
4983 use Glib qw(TRUE FALSE);
4984  
4985 @Language::Axbasic::Function::Intrinsic::Numeric::getroomexits::ISA = qw(
4986 Language::Axbasic::Function::Intrinsic::Numeric
4987 );
4988  
4989 # Getroomexits ()
4990  
4991 ##################
4992 # Methods
4993  
4994 sub evaluate {
4995  
4996 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
4997 #
4998 # Expected arguments
4999 # $arg - The first (and only) argument in the argument list
5000 #
5001 # Return values
5002 # The return value of the function
5003  
5004 my ($self, $arg) = @_;
5005  
5006 # Local variables
5007 my $mapObj;
5008  
5009 # (No improper arguments to check)
5010  
5011 # Evaluate the function and return the value
5012 $mapObj = $self->scriptObj->session->mapObj;
5013 if (! $mapObj->currentRoom || ! $mapObj->currentRoom->sortedExitList) {
5014  
5015 # No current room or current room has no exits
5016 return 0;
5017  
5018 } else {
5019  
5020 # Return the number of exits in the current room
5021 return (scalar $mapObj->currentRoom->sortedExitList);
5022 }
5023 }
5024 }
5025  
5026 { package Language::Axbasic::Function::Intrinsic::Numeric::getroomnum;
5027  
5028 use strict;
5029 use warnings;
5030 use diagnostics;
5031  
5032 use Glib qw(TRUE FALSE);
5033  
5034 @Language::Axbasic::Function::Intrinsic::Numeric::getroomnum::ISA = qw(
5035 Language::Axbasic::Function::Intrinsic::Numeric
5036 );
5037  
5038 # Getroomnum ()
5039  
5040 ##################
5041 # Methods
5042  
5043 sub evaluate {
5044  
5045 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5046 #
5047 # Expected arguments
5048 # $arg - The first (and only) argument in the argument list
5049 #
5050 # Return values
5051 # The return value of the function
5052  
5053 my ($self, $arg) = @_;
5054  
5055 # Local variables
5056 my $mapObj;
5057  
5058 # (No improper arguments to check)
5059  
5060 # Evaluate the function and return the value
5061 $mapObj = $self->scriptObj->session->mapObj;
5062  
5063 if (! $mapObj->currentRoom) {
5064  
5065 # No current room
5066 return 0;
5067  
5068 } else {
5069  
5070 # Return the number of the current room
5071 return $mapObj->currentRoom->number;
5072 }
5073 }
5074 }
5075  
5076 { package Language::Axbasic::Function::Intrinsic::Numeric::getroomobjects;
5077  
5078 use strict;
5079 use warnings;
5080 use diagnostics;
5081  
5082 use Glib qw(TRUE FALSE);
5083  
5084 @Language::Axbasic::Function::Intrinsic::Numeric::getroomobjects::ISA = qw(
5085 Language::Axbasic::Function::Intrinsic::Numeric
5086 );
5087  
5088 # Getroomobjects ()
5089 # Getroomobjects (string)
5090  
5091 ##################
5092 # Methods
5093  
5094 sub evaluate {
5095  
5096 # Called by LA::Expression::Function->evaluate (using arguments in the form ';S')
5097 #
5098 # Expected arguments
5099 # $arg - The first (and only) argument in the argument list
5100 #
5101 # Return values
5102 # The return value of the function
5103  
5104 my ($self, $arg) = @_;
5105  
5106 # Local variables
5107 my ($taskObj, $count);
5108  
5109 # (No improper arguments to check)
5110  
5111 # Evaluate the function and return the value
5112 $taskObj = $self->scriptObj->session->locatorTask;
5113  
5114 if (! $taskObj || ! $taskObj->roomObj || ! $taskObj->roomObj->tempObjList) {
5115  
5116 # Locator task not running, does not know current location, or current location is
5117 # empty
5118 return 0;
5119  
5120 } elsif (! $arg) {
5121  
5122 # Return number of objects in the room
5123 return (scalar $taskObj->roomObj->tempObjList);
5124  
5125 } else {
5126  
5127 # Count matching things
5128 $count = 0;
5129  
5130 if (
5131 $arg eq 'weapon' || $arg eq 'armour' || $arg eq 'garment' || $arg eq 'char'
5132 || $arg eq 'minion' || $arg eq 'sentient' || $arg eq 'creature'
5133 || $arg eq 'portable' || $arg eq 'decoration' || $arg eq 'custom'
5134 ) {
5135 foreach my $obj ($taskObj->roomObj->tempObjList) {
5136  
5137 if ($obj->category eq $arg) {
5138  
5139 $count++;
5140 }
5141 }
5142  
5143 } elsif ($arg eq 'living') {
5144  
5145 foreach my $obj ($taskObj->roomObj->tempObjList) {
5146  
5147 if ($obj->aliveFlag) {
5148  
5149 $count++;
5150 }
5151 }
5152  
5153 } elsif ($arg eq 'not_living') {
5154  
5155 foreach my $obj ($taskObj->roomObj->tempObjList) {
5156  
5157 if (! $obj->aliveFlag) {
5158  
5159 $count++;
5160 }
5161 }
5162  
5163 } else {
5164  
5165 # Unrecognised string
5166 return 0;
5167 }
5168  
5169 # Return the number of matching objects (may be 0)
5170 return $count;
5171 }
5172 }
5173 }
5174  
5175 { package Language::Axbasic::Function::Intrinsic::Numeric::ifacecount;
5176  
5177 use strict;
5178 use warnings;
5179 use diagnostics;
5180  
5181 use Glib qw(TRUE FALSE);
5182  
5183 @Language::Axbasic::Function::Intrinsic::Numeric::ifacecount::ISA = qw(
5184 Language::Axbasic::Function::Intrinsic::Numeric
5185 );
5186  
5187 # Ifacecount ()
5188  
5189 ##################
5190 # Methods
5191  
5192 sub evaluate {
5193  
5194 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5195 #
5196 # Expected arguments
5197 # $arg - The first (and only) argument in the argument list
5198 #
5199 # Return values
5200 # The return value of the function
5201  
5202 my ($self, $arg) = @_;
5203  
5204 # (No improper arguments to check)
5205  
5206 # Evaluate the function and return the value
5207  
5208 # Return the number of LA::Notifications received and not yet processed
5209 return $self->scriptObj->ivNumber('notificationList');
5210 }
5211 }
5212  
5213 { package Language::Axbasic::Function::Intrinsic::Numeric::ifacedefined;
5214  
5215 use strict;
5216 use warnings;
5217 use diagnostics;
5218  
5219 use Glib qw(TRUE FALSE);
5220  
5221 @Language::Axbasic::Function::Intrinsic::Numeric::ifacedefined::ISA = qw(
5222 Language::Axbasic::Function::Intrinsic::Numeric
5223 );
5224  
5225 # Ifacedefined (number)
5226  
5227 ##################
5228 # Methods
5229  
5230 sub evaluate {
5231  
5232 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5233 #
5234 # Expected arguments
5235 # $arg - The first (and only) argument in the argument list
5236 #
5237 # Return values
5238 # The return value of the function
5239  
5240 my ($self, $arg) = @_;
5241  
5242 # Local variables
5243 my ($obj, $substr);
5244  
5245 # (No improper arguments to check)
5246  
5247 # Evaluate the function and return the value
5248 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
5249  
5250 # The notification list is empty
5251 return 0;
5252  
5253 } else {
5254  
5255 # Get the current notification
5256 $obj = $self->scriptObj->ivIndex(
5257 'notificationList',
5258 $self->scriptObj->currentNotification,
5259 );
5260  
5261 if (! $obj->dataList
5262 || $arg < 1
5263 || $obj->ivNumber('dataList') > $arg
5264 ) {
5265 # No additional data to return
5266 return 0;
5267  
5268 } else {
5269  
5270 # For triggers and aliases, if a regex matching a line is in the form (...|...|...),
5271 # with each ... containing its own substrings, ->dataList will contain lots of
5272 # 'undef' values from the ... portions that didn't match the line
5273 # Return 1 if the specified argument is defined, and -1 if it is not defined
5274 $substr = $obj->ivIndex('dataList', ($arg - 1));
5275 if (defined $substr) {
5276 return 1;
5277 } else {
5278 return -1;
5279 }
5280 }
5281 }
5282 }
5283 }
5284  
5285 { package Language::Axbasic::Function::Intrinsic::Numeric::ifacenum;
5286  
5287 use strict;
5288 use warnings;
5289 use diagnostics;
5290  
5291 use Glib qw(TRUE FALSE);
5292  
5293 @Language::Axbasic::Function::Intrinsic::Numeric::ifacenum::ISA = qw(
5294 Language::Axbasic::Function::Intrinsic::Numeric
5295 );
5296  
5297 # Ifacenum ()
5298  
5299 ##################
5300 # Methods
5301  
5302 sub evaluate {
5303  
5304 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5305 #
5306 # Expected arguments
5307 # $arg - The first (and only) argument in the argument list
5308 #
5309 # Return values
5310 # The return value of the function
5311  
5312 my ($self, $arg) = @_;
5313  
5314 # Local variables
5315 my $obj;
5316  
5317 # (No improper arguments to check)
5318  
5319 # Evaluate the function and return the value
5320 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
5321  
5322 # The notification list is empty
5323 return -1;
5324  
5325 } else {
5326  
5327 # Get the current notification
5328 $obj = $self->scriptObj->ivIndex(
5329 'notificationList',
5330 $self->scriptObj->currentNotification,
5331 );
5332  
5333 # Return its corresponding interface number
5334 return $obj->number;
5335 }
5336 }
5337 }
5338  
5339 { package Language::Axbasic::Function::Intrinsic::Numeric::ifacepos;
5340  
5341 use strict;
5342 use warnings;
5343 use diagnostics;
5344  
5345 use Glib qw(TRUE FALSE);
5346  
5347 @Language::Axbasic::Function::Intrinsic::Numeric::ifacepos::ISA = qw(
5348 Language::Axbasic::Function::Intrinsic::Numeric
5349 );
5350  
5351 # Ifacepos ()
5352  
5353 ##################
5354 # Methods
5355  
5356 sub evaluate {
5357  
5358 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5359 #
5360 # Expected arguments
5361 # $arg - The first (and only) argument in the argument list
5362 #
5363 # Return values
5364 # The return value of the function
5365  
5366 my ($self, $arg) = @_;
5367  
5368 # (No improper arguments to check)
5369  
5370 # Evaluate the function and return the value
5371  
5372 # Return the number of index of the current LA::Notification. Perl indexes start from 0,
5373 # but Axbasic indexes start from 1. (If the notification list is empty,
5374 # ->currentNotification is set to -1, and this function returns 0)
5375 return ($self->scriptObj->currentNotification + 1);
5376 }
5377 }
5378  
5379 { package Language::Axbasic::Function::Intrinsic::Numeric::ifacestrings;
5380  
5381 use strict;
5382 use warnings;
5383 use diagnostics;
5384  
5385 use Glib qw(TRUE FALSE);
5386  
5387 @Language::Axbasic::Function::Intrinsic::Numeric::ifacestrings::ISA = qw(
5388 Language::Axbasic::Function::Intrinsic::Numeric
5389 );
5390  
5391 # Ifacestrings ()
5392  
5393 ##################
5394 # Methods
5395  
5396 sub evaluate {
5397  
5398 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5399 #
5400 # Expected arguments
5401 # $arg - The first (and only) argument in the argument list
5402 #
5403 # Return values
5404 # The return value of the function
5405  
5406 my ($self, $arg) = @_;
5407  
5408 # Local variables
5409 my $obj;
5410  
5411 # (No improper arguments to check)
5412  
5413 # Evaluate the function and return the value
5414 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
5415  
5416 # The notification list is empty
5417 return 0;
5418  
5419 } else {
5420  
5421 # Get the current notification
5422 $obj = $self->scriptObj->ivIndex(
5423 'notificationList',
5424 $self->scriptObj->currentNotification,
5425 );
5426  
5427 # Return the number of group substrings stored in it
5428 return $obj->ivNumber('dataList');
5429 }
5430 }
5431 }
5432  
5433 { package Language::Axbasic::Function::Intrinsic::Numeric::ifacetime;
5434  
5435 use strict;
5436 use warnings;
5437 use diagnostics;
5438  
5439 use Glib qw(TRUE FALSE);
5440  
5441 @Language::Axbasic::Function::Intrinsic::Numeric::ifacetime::ISA = qw(
5442 Language::Axbasic::Function::Intrinsic::Numeric
5443 );
5444  
5445 # Ifacetime ()
5446  
5447 ##################
5448 # Methods
5449  
5450 sub evaluate {
5451  
5452 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5453 #
5454 # Expected arguments
5455 # $arg - The first (and only) argument in the argument list
5456 #
5457 # Return values
5458 # The return value of the function
5459  
5460 my ($self, $arg) = @_;
5461  
5462 # Local variables
5463 my $obj;
5464  
5465 # (No improper arguments to check)
5466  
5467 # Evaluate the function and return the value
5468 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
5469  
5470 # The notification list is empty
5471 return -1;
5472  
5473 } else {
5474  
5475 # Get the current notification
5476 $obj = $self->scriptObj->ivIndex(
5477 'notificationList',
5478 $self->scriptObj->currentNotification,
5479 );
5480  
5481 # Return the time it was received
5482 return $obj->time;
5483 }
5484 }
5485 }
5486  
5487 { package Language::Axbasic::Function::Intrinsic::Numeric::ismap;
5488  
5489 use strict;
5490 use warnings;
5491 use diagnostics;
5492  
5493 use Glib qw(TRUE FALSE);
5494  
5495 @Language::Axbasic::Function::Intrinsic::Numeric::ismap::ISA = qw(
5496 Language::Axbasic::Function::Intrinsic::Numeric
5497 );
5498  
5499 # Ismap
5500  
5501 ##################
5502 # Methods
5503  
5504 sub evaluate {
5505  
5506 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5507 #
5508 # Expected arguments
5509 # $arg - The first (and only) argument in the argument list
5510 #
5511 # Return values
5512 # The return value of the function
5513  
5514 my ($self, $arg) = @_;
5515  
5516 # (No improper arguments to check)
5517  
5518 # Evaluate the function and return the value
5519  
5520 # Test whether the Automapper window is open
5521 if (! $self->scriptObj->session->mapWin) {
5522  
5523 # Window not open
5524 return 0;
5525  
5526 } else {
5527  
5528 # Window open
5529 return 1;
5530 }
5531 }
5532 }
5533  
5534 { package Language::Axbasic::Function::Intrinsic::Numeric::isscript;
5535  
5536 use strict;
5537 use warnings;
5538 use diagnostics;
5539  
5540 use Glib qw(TRUE FALSE);
5541  
5542 @Language::Axbasic::Function::Intrinsic::Numeric::isscript::ISA = qw(
5543 Language::Axbasic::Function::Intrinsic::Numeric
5544 );
5545  
5546 # Isscript (string)
5547  
5548 ##################
5549 # Methods
5550  
5551 sub evaluate {
5552  
5553 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5554 #
5555 # Expected arguments
5556 # $arg - The first (and only) argument in the argument list
5557 #
5558 # Return values
5559 # The return value of the function
5560  
5561 my ($self, $arg) = @_;
5562  
5563 # Local variables
5564 my @list;
5565  
5566 # (No improper arguments to check)
5567  
5568 # Evaluate the function and return the value
5569  
5570 # Get a list of currently-running Script tasks
5571 @list = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, 'script_task');
5572 foreach my $taskObj (@list) {
5573  
5574 # If this task is running a script called $arg, return 1
5575 if ($taskObj->scriptName eq $arg) {
5576  
5577 return 1;
5578 }
5579 }
5580  
5581 # No Script tasks running scripts called $arg
5582 return 0;
5583 }
5584 }
5585  
5586 { package Language::Axbasic::Function::Intrinsic::Numeric::istask;
5587  
5588 use strict;
5589 use warnings;
5590 use diagnostics;
5591  
5592 use Glib qw(TRUE FALSE);
5593  
5594 @Language::Axbasic::Function::Intrinsic::Numeric::istask::ISA = qw(
5595 Language::Axbasic::Function::Intrinsic::Numeric
5596 );
5597  
5598 # Istask ()
5599  
5600 ##################
5601 # Methods
5602  
5603 sub evaluate {
5604  
5605 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5606 #
5607 # Expected arguments
5608 # $arg - The first (and only) argument in the argument list
5609 #
5610 # Return values
5611 # The return value of the function
5612  
5613 my ($self, $arg) = @_;
5614  
5615 # (No improper arguments to check)
5616  
5617 # Evaluate the function and return the value
5618  
5619 # Test whether the script is being run by a task
5620 if ($self->scriptObj->parentTask) {
5621  
5622 # Window open
5623 return 1;
5624  
5625 } else {
5626  
5627 # Window not open
5628 return 0;
5629 }
5630 }
5631 }
5632  
5633 { package Language::Axbasic::Function::Intrinsic::Numeric::iswin;
5634  
5635 use strict;
5636 use warnings;
5637 use diagnostics;
5638  
5639 use Glib qw(TRUE FALSE);
5640  
5641 @Language::Axbasic::Function::Intrinsic::Numeric::iswin::ISA = qw(
5642 Language::Axbasic::Function::Intrinsic::Numeric
5643 );
5644  
5645 # Iswin ()
5646  
5647 ##################
5648 # Methods
5649  
5650 sub evaluate {
5651  
5652 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5653 #
5654 # Expected arguments
5655 # $arg - The first (and only) argument in the argument list
5656 #
5657 # Return values
5658 # The return value of the function
5659  
5660 my ($self, $arg) = @_;
5661  
5662 # (No improper arguments to check)
5663  
5664 # Evaluate the function and return the value
5665  
5666 # Test whether the script is being run by a task and, if so, the task window is open
5667 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
5668  
5669 # Window open
5670 return 1;
5671  
5672 } else {
5673  
5674 # Window not open
5675 return 0;
5676 }
5677 }
5678 }
5679  
5680 { package Language::Axbasic::Function::Intrinsic::Numeric::openmap;
5681  
5682 use strict;
5683 use warnings;
5684 use diagnostics;
5685  
5686 use Glib qw(TRUE FALSE);
5687  
5688 @Language::Axbasic::Function::Intrinsic::Numeric::openmap::ISA = qw(
5689 Language::Axbasic::Function::Intrinsic::Numeric
5690 );
5691  
5692 # Openmap ()
5693  
5694 ##################
5695 # Methods
5696  
5697 sub evaluate {
5698  
5699 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
5700 #
5701 # Expected arguments
5702 # $arg - The first (and only) argument in the argument list
5703 #
5704 # Return values
5705 # The return value of the function
5706  
5707 my ($self, $arg) = @_;
5708  
5709 # (No improper arguments to check)
5710  
5711 # Evaluate the function and return the value
5712 if ($self->scriptObj->session->mapWin) {
5713  
5714 # The window is already open
5715 return 1;
5716  
5717 } else {
5718  
5719 # Try to open the window
5720 $self->scriptObj->session->mapObj->openWin();
5721 if ($self->scriptObj->session->mapWin) {
5722  
5723 # Window opened successfully
5724 return 1;
5725  
5726 } else {
5727  
5728 # Could not open window
5729 return 0;
5730 }
5731 }
5732 }
5733 }
5734  
5735 { package Language::Axbasic::Function::Intrinsic::Numeric::setlight;
5736  
5737 use strict;
5738 use warnings;
5739 use diagnostics;
5740  
5741 use Glib qw(TRUE FALSE);
5742  
5743 @Language::Axbasic::Function::Intrinsic::Numeric::setlight::ISA = qw(
5744 Language::Axbasic::Function::Intrinsic::Numeric
5745 );
5746  
5747 # Setlight (string)
5748  
5749 ##################
5750 # Methods
5751  
5752 sub evaluate {
5753  
5754 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
5755 #
5756 # Expected arguments
5757 # $arg - The first (and only) argument in the argument list
5758 #
5759 # Return values
5760 # The return value of the function
5761  
5762 my ($self, $arg) = @_;
5763  
5764 # Local variables
5765 my $wmObj;
5766  
5767 # (No improper arguments to check)
5768  
5769 # Evaluate the function and return the value
5770 $wmObj = $self->scriptObj->session->worldModelObj;
5771  
5772 # Set the light status
5773 $wmObj->set_lightStatus($arg);
5774 if ($wmObj->lightStatus ne $arg) {
5775  
5776 # Operation failed
5777 return 0;
5778  
5779 } else {
5780  
5781 # Operation succeeded
5782 return 1;
5783 }
5784 }
5785 }
5786  
5787 { package Language::Axbasic::Function::Intrinsic::Numeric::setmapmode;
5788  
5789 use strict;
5790 use warnings;
5791 use diagnostics;
5792  
5793 use Glib qw(TRUE FALSE);
5794  
5795 @Language::Axbasic::Function::Intrinsic::Numeric::setmapmode::ISA = qw(
5796 Language::Axbasic::Function::Intrinsic::Numeric
5797 );
5798  
5799 # Setmapmode (string)
5800  
5801 ##################
5802 # Methods
5803  
5804 sub evaluate {
5805  
5806 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
5807 #
5808 # Expected arguments
5809 # $arg - The first (and only) argument in the argument list
5810 #
5811 # Return values
5812 # The return value of the function
5813  
5814 my ($self, $arg) = @_;
5815  
5816 # Local variables
5817 my $mapWin;
5818  
5819 # (No improper arguments to check)
5820  
5821 # Evaluate the function and return the value
5822  
5823 # Check that the Automapper window is open, and that a recognised string has been used
5824 $mapWin = $self->scriptObj->session->mapWin;
5825  
5826 if (! $mapWin || ($arg ne 'wait' && $arg ne 'follow' && $arg ne 'update')) {
5827  
5828 return 0;
5829  
5830 } else {
5831  
5832 # Make sure that the specified mode is in its lower-case form
5833 $arg = lc($arg);
5834 # Try to set the current mode
5835 $mapWin->setMode($arg);
5836  
5837 # See if the mode was correctly set
5838 if ($mapWin->mode eq $arg) {
5839  
5840 # Mode correctly set, or mode was already set
5841 return 1;
5842  
5843 } else {
5844  
5845 # Mode not set
5846 return 0;
5847 }
5848 }
5849 }
5850 }
5851  
5852 { package Language::Axbasic::Function::Intrinsic::Numeric::setregion;
5853  
5854 use strict;
5855 use warnings;
5856 use diagnostics;
5857  
5858 use Glib qw(TRUE FALSE);
5859  
5860 @Language::Axbasic::Function::Intrinsic::Numeric::setregion::ISA = qw(
5861 Language::Axbasic::Function::Intrinsic::Numeric
5862 );
5863  
5864 # Setregion (string)
5865  
5866 ##################
5867 # Methods
5868  
5869 sub evaluate {
5870  
5871 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
5872 #
5873 # Expected arguments
5874 # $arg - The first (and only) argument in the argument list
5875 #
5876 # Return values
5877 # The return value of the function
5878  
5879 my ($self, $arg) = @_;
5880  
5881 # Local variables
5882 my $mapWin;
5883  
5884 # (No improper arguments to check)
5885  
5886 # Evaluate the function and return the value
5887  
5888 # Check that the Automapper window is open
5889 $mapWin = $self->scriptObj->session->mapWin;
5890 if (! $mapWin) {
5891  
5892 return 0;
5893  
5894 } else {
5895  
5896 # Set the current region. Return 1 on success, 0 on failure
5897 if (! $mapWin->setCurrentRegion($arg)) {
5898 return 0;
5899 } else {
5900 return 1;
5901 }
5902 }
5903 }
5904 }
5905  
5906 { package Language::Axbasic::Function::Intrinsic::Numeric::setregionnum;
5907  
5908 use strict;
5909 use warnings;
5910 use diagnostics;
5911  
5912 use Glib qw(TRUE FALSE);
5913  
5914 @Language::Axbasic::Function::Intrinsic::Numeric::setregionnum::ISA = qw(
5915 Language::Axbasic::Function::Intrinsic::Numeric
5916 );
5917  
5918 # Setregionnum (number)
5919  
5920 ##################
5921 # Methods
5922  
5923 sub evaluate {
5924  
5925 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
5926 #
5927 # Expected arguments
5928 # $arg - The first (and only) argument in the argument list
5929 #
5930 # Return values
5931 # The return value of the function
5932  
5933 my ($self, $arg) = @_;
5934  
5935 # Local variables
5936 my ($mapWin, $obj);
5937  
5938 # (No improper arguments to check)
5939  
5940 # Evaluate the function and return the value
5941 $mapWin = $self->scriptObj->session->mapWin;
5942  
5943 # Check that the Automapper window is open
5944 if (! $mapWin) {
5945  
5946 return 0;
5947  
5948 } else {
5949  
5950 # Check that the world model number $arg exists, and that it is a region
5951 $obj = $self->scriptObj->session->worldModelObj->ivShow('modelHash', $arg);
5952 if (! $obj || $obj->category ne 'region') {
5953  
5954 return 0;
5955  
5956 } else {
5957  
5958 # Set the current region. Return 1 on success, 0 on failure
5959 if (! $mapWin->setCurrentRegion($obj->name)) {
5960 return 0;
5961 } else {
5962 return 1;
5963 }
5964 }
5965 }
5966 }
5967 }
5968  
5969 { package Language::Axbasic::Function::Intrinsic::Numeric::setroomnum;
5970  
5971 use strict;
5972 use warnings;
5973 use diagnostics;
5974  
5975 use Glib qw(TRUE FALSE);
5976  
5977 @Language::Axbasic::Function::Intrinsic::Numeric::setroomnum::ISA = qw(
5978 Language::Axbasic::Function::Intrinsic::Numeric
5979 );
5980  
5981 # Setroomnum ()
5982 # Setroomnum (number)
5983  
5984 ##################
5985 # Methods
5986  
5987 sub evaluate {
5988  
5989 # Called by LA::Expression::Function->evaluate (using arguments in the form ';N')
5990 #
5991 # Expected arguments
5992 # $arg - The first (and only) argument in the argument list
5993 #
5994 # Return values
5995 # The return value of the function
5996  
5997 my ($self, $arg) = @_;
5998  
5999 # Local variables
6000 my ($mapObj, $obj);
6001  
6002 # (No improper arguments to check)
6003  
6004 # Evaluate the function and return the value
6005 $mapObj = $self->scriptObj->session->mapObj;
6006  
6007 # Check that a valid value for $arg (if specified at all) was supplied
6008 if ($arg && $arg < 1) {
6009  
6010 return 0;
6011 }
6012  
6013 # If $arg was specified...
6014 if ($arg) {
6015  
6016 # ...check it's a valid room model object
6017 $obj = $self->scriptObj->session->worldModelObj->ivShow('modelHash', $arg);
6018 if (! $obj || $obj->category ne 'room') {
6019  
6020 return 0;
6021 }
6022  
6023 # Attempt to set the current room
6024 $mapObj->setCurrentRoom($obj);
6025 if (! $mapObj->currentRoom || $mapObj->currentRoom ne $obj) {
6026  
6027 # Set operation failed
6028 return 0;
6029  
6030 } else {
6031  
6032 # Set operation succeeded
6033 return 1;
6034 }
6035  
6036 } else {
6037  
6038 # Attempt to usnet the current room
6039 $mapObj->setCurrentRoom();
6040 if ($mapObj->currentRoom) {
6041  
6042 # Unset operation failed
6043 return 0;
6044  
6045 } else {
6046  
6047 # Unset operation succeeded
6048 return 1;
6049 }
6050 }
6051 }
6052 }
6053  
6054 { package Language::Axbasic::Function::Intrinsic::Numeric::setroomtagged;
6055  
6056 use strict;
6057 use warnings;
6058 use diagnostics;
6059  
6060 use Glib qw(TRUE FALSE);
6061  
6062 @Language::Axbasic::Function::Intrinsic::Numeric::setroomtagged::ISA = qw(
6063 Language::Axbasic::Function::Intrinsic::Numeric
6064 );
6065  
6066 # Setroomtagged (string)
6067  
6068 ##################
6069 # Methods
6070  
6071 sub evaluate {
6072  
6073 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
6074 #
6075 # Expected arguments
6076 # $arg - The first (and only) argument in the argument list
6077 #
6078 # Return values
6079 # The return value of the function
6080  
6081 my ($self, $arg) = @_;
6082  
6083 # Local variables
6084 my ($mapObj, $wmObj, $number, $obj);
6085  
6086 # (No improper arguments to check)
6087  
6088 # Evaluate the function and return the value
6089 $mapObj = $self->scriptObj->session->mapObj;
6090 $wmObj = $mapObj->worldModelObj;
6091  
6092 # Room tags are stored as lower-case letters
6093 $arg = lc($arg);
6094  
6095 # Check that $arg is a tag used by a world model room, if it was specified
6096 if ($arg && ! $wmObj->ivExists('roomTagHash', $arg)) {
6097  
6098 # The room tag isn't valid
6099 return 0;
6100 }
6101  
6102 # If $arg was specified...
6103 if ($arg) {
6104  
6105 # Get the corresponding room
6106 $number = $wmObj->ivShow('roomTagHash', $arg);
6107 $obj = $wmObj->ivShow('modelHash', $number);
6108 if (! $obj) {
6109  
6110 return 0;
6111 }
6112  
6113 # Attempt to set the current room
6114 $mapObj->setCurrentRoom($obj);
6115 if (! $mapObj->currentRoom || $mapObj->currentRoom ne $obj) {
6116  
6117 # Set operation failed
6118 return 0;
6119  
6120 } else {
6121  
6122 # Set operation succeeded
6123 return 1;
6124 }
6125  
6126 } else {
6127  
6128 # Attempt to usnet the current room
6129 $mapObj->setCurrentRoom();
6130 if ($mapObj->currentRoom) {
6131  
6132 # Unset operation failed
6133 return 0;
6134  
6135 } else {
6136  
6137 # Unset operation succeeded
6138 return 1;
6139 }
6140 }
6141 }
6142 }
6143  
6144 { package Language::Axbasic::Function::Intrinsic::Numeric::timestamp;
6145  
6146 use strict;
6147 use warnings;
6148 use diagnostics;
6149  
6150 use Glib qw(TRUE FALSE);
6151  
6152 @Language::Axbasic::Function::Intrinsic::Numeric::timestamp::ISA = qw(
6153 Language::Axbasic::Function::Intrinsic::Numeric
6154 );
6155  
6156 # Timestamp ()
6157  
6158 ##################
6159 # Methods
6160  
6161 sub evaluate {
6162  
6163 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6164 #
6165 # Expected arguments
6166 # $arg - The first (and only) argument in the argument list
6167 #
6168 # Return values
6169 # The return value of the function
6170  
6171 my ($self, $arg) = @_;
6172  
6173 # (No improper arguments to check)
6174  
6175 # Evaluate the function and return the value
6176 return int($self->scriptObj->session->sessionLoopObj->spinTime);
6177 }
6178 }
6179  
6180 ### Axmud-dependent functions (string) ###
6181  
6182 { package Language::Axbasic::Function::Intrinsic::String::abbrevdir;
6183  
6184 use strict;
6185 use warnings;
6186 use diagnostics;
6187  
6188 use Glib qw(TRUE FALSE);
6189  
6190 @Language::Axbasic::Function::Intrinsic::String::abbrevdir::ISA = qw(
6191 Language::Axbasic::Function::Intrinsic::String
6192 );
6193  
6194 # Abbrevdir$ ()
6195  
6196 ##################
6197 # Methods
6198  
6199 sub evaluate {
6200  
6201 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6202 #
6203 # Expected arguments
6204 # $arg - The first (and only) argument in the argument list
6205 #
6206 # Return values
6207 # The return value of the function
6208  
6209 my ($self, $arg) = @_;
6210  
6211 # (No improper arguments to check)
6212  
6213 # Evaluate the function and return the value
6214 return $self->scriptObj->session->currentDict->abbrevDir($arg);
6215 }
6216 }
6217  
6218 { package Language::Axbasic::Function::Intrinsic::String::clientdate;
6219  
6220 use strict;
6221 use warnings;
6222 use diagnostics;
6223  
6224 use Glib qw(TRUE FALSE);
6225  
6226 @Language::Axbasic::Function::Intrinsic::String::clientdate::ISA = qw(
6227 Language::Axbasic::Function::Intrinsic::String
6228 );
6229  
6230 # Clientdate$ ()
6231  
6232 ##################
6233 # Methods
6234  
6235 sub evaluate {
6236  
6237 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6238 #
6239 # Expected arguments
6240 # $arg - The first (and only) argument in the argument list
6241 #
6242 # Return values
6243 # The return value of the function
6244  
6245 my ($self, $arg) = @_;
6246  
6247 # (No improper arguments to check)
6248  
6249 # Evaluate the function and return the value
6250 return $axmud::DATE;
6251 }
6252 }
6253  
6254 { package Language::Axbasic::Function::Intrinsic::String::clientname;
6255  
6256 use strict;
6257 use warnings;
6258 use diagnostics;
6259  
6260 use Glib qw(TRUE FALSE);
6261  
6262 @Language::Axbasic::Function::Intrinsic::String::clientname::ISA = qw(
6263 Language::Axbasic::Function::Intrinsic::String
6264 );
6265  
6266 # Clientname$ ()
6267  
6268 ##################
6269 # Methods
6270  
6271 sub evaluate {
6272  
6273 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6274 #
6275 # Expected arguments
6276 # $arg - The first (and only) argument in the argument list
6277 #
6278 # Return values
6279 # The return value of the function
6280  
6281 my ($self, $arg) = @_;
6282  
6283 # (No improper arguments to check)
6284  
6285 # Evaluate the function and return the value
6286 return $axmud::SCRIPT;
6287 }
6288 }
6289  
6290 { package Language::Axbasic::Function::Intrinsic::String::clientversion;
6291  
6292 use strict;
6293 use warnings;
6294 use diagnostics;
6295  
6296 use Glib qw(TRUE FALSE);
6297  
6298 @Language::Axbasic::Function::Intrinsic::String::clientversion::ISA = qw(
6299 Language::Axbasic::Function::Intrinsic::String
6300 );
6301  
6302 # Clientversion$ ()
6303  
6304 ##################
6305 # Methods
6306  
6307 sub evaluate {
6308  
6309 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6310 #
6311 # Expected arguments
6312 # $arg - The first (and only) argument in the argument list
6313 #
6314 # Return values
6315 # The return value of the function
6316  
6317 my ($self, $arg) = @_;
6318  
6319 # (No improper arguments to check)
6320  
6321 # Evaluate the function and return the value
6322 return $axmud::VERSION;
6323 }
6324 }
6325  
6326 { package Language::Axbasic::Function::Intrinsic::String::findtask;
6327  
6328 use strict;
6329 use warnings;
6330 use diagnostics;
6331  
6332 use Glib qw(TRUE FALSE);
6333  
6334 @Language::Axbasic::Function::Intrinsic::String::findtask::ISA = qw(
6335 Language::Axbasic::Function::Intrinsic::String
6336 );
6337  
6338 # Findtask$ (string)
6339  
6340 ##################
6341 # Methods
6342  
6343 sub evaluate {
6344  
6345 # Called by LA::Expression::Function->evaluate (using arguments in the form 'S')
6346 #
6347 # Expected arguments
6348 # $arg - The first (and only) argument in the argument list
6349 #
6350 # Return values
6351 # The return value of the function
6352  
6353 my ($self, $arg) = @_;
6354  
6355 # Local variables
6356 my (
6357 $taskObj,
6358 @list,
6359 );
6360  
6361 # (No improper arguments to check)
6362  
6363 # Evaluate the function and return the value
6364  
6365 # Get a list of tasks in the current tasklist which match $arg. The ->findTask function
6366 # usually accepts the string '-a', but this Axbasic function does not
6367 if ($arg ne '-a') {
6368  
6369 @list = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $arg);
6370 }
6371  
6372 if (! @list) {
6373  
6374 # No matching tasks found
6375 return '';
6376  
6377 } else {
6378  
6379 # One or more matching tasks found. Return the first one
6380 $taskObj = $list[0];
6381 return $taskObj->uniqueName;
6382 }
6383 }
6384 }
6385  
6386 { package Language::Axbasic::Function::Intrinsic::String::getexit;
6387  
6388 use strict;
6389 use warnings;
6390 use diagnostics;
6391  
6392 use Glib qw(TRUE FALSE);
6393  
6394 @Language::Axbasic::Function::Intrinsic::String::getexit::ISA = qw(
6395 Language::Axbasic::Function::Intrinsic::String
6396 );
6397  
6398 # Getexit$ (number)
6399  
6400 ##################
6401 # Methods
6402  
6403 sub evaluate {
6404  
6405 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6406 #
6407 # Expected arguments
6408 # $arg - The first (and only) argument in the argument list
6409 #
6410 # Return values
6411 # The return value of the function
6412  
6413 my ($self, $arg) = @_;
6414  
6415 # Local variables
6416 my $mapObj;
6417  
6418 # (No improper arguments to check)
6419  
6420 # Evaluate the function and return the value
6421 $mapObj = $self->scriptObj->session->mapObj;
6422  
6423 # Perl indexes start at 0, but Axbasic indexes start at 1
6424 $arg--;
6425  
6426 if (
6427 ! $mapObj->currentRoom
6428 || ! $mapObj->currentRoom->sortedExitList
6429 || $arg < 0
6430 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
6431 ) {
6432 # No current room, no exits in current room, invalid exit number or numbered exit
6433 # doesn't exist
6434 return '';
6435  
6436 } else {
6437  
6438 # Return the numbered exit
6439 return $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
6440 }
6441 }
6442 }
6443  
6444 { package Language::Axbasic::Function::Intrinsic::String::getexitdrawn;
6445  
6446 use strict;
6447 use warnings;
6448 use diagnostics;
6449  
6450 use Glib qw(TRUE FALSE);
6451  
6452 @Language::Axbasic::Function::Intrinsic::String::getexitdrawn::ISA = qw(
6453 Language::Axbasic::Function::Intrinsic::String
6454 );
6455  
6456 # Getexitdrawn$ (number)
6457  
6458 ##################
6459 # Methods
6460  
6461 sub evaluate {
6462  
6463 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6464 #
6465 # Expected arguments
6466 # $arg - The first (and only) argument in the argument list
6467 #
6468 # Return values
6469 # The return value of the function
6470  
6471 my ($self, $arg) = @_;
6472  
6473 # Local variables
6474 my ($mapObj, $wmObj, $dir, $exitNum, $obj);
6475  
6476 # (No improper arguments to check)
6477  
6478 # Evaluate the function and return the value
6479 $mapObj = $self->scriptObj->session->mapObj;
6480 $wmObj = $mapObj->worldModelObj;
6481  
6482 # Perl indexes start at 0, but Axbasic indexes start at 1
6483 $arg--;
6484  
6485 if (
6486 ! $mapObj->currentRoom
6487 || ! $mapObj->currentRoom->sortedExitList
6488 || $arg < 0
6489 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
6490 ) {
6491 # No current room, no exits in current room, invalid exit number or numbered exit
6492 # doesn't exist
6493 return '';
6494  
6495 } else {
6496  
6497 # Get the exit model object
6498 $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
6499 $exitNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir);
6500 if (! $exitNum || ! $wmObj->ivExists('exitModelHash', $exitNum)) {
6501  
6502 # Exit model object not found
6503 return '';
6504  
6505 } else {
6506  
6507 $obj = $wmObj->ivShow('exitModelHash', $exitNum);
6508 if (! $obj->mapDir) {
6509  
6510 # Exit is unallocatable
6511 return '';
6512  
6513 } else {
6514  
6515 # Return the numbered exit's primary direction
6516 return $obj->mapDir;
6517 }
6518 }
6519 }
6520 }
6521 }
6522  
6523 { package Language::Axbasic::Function::Intrinsic::String::getexitstatus;
6524  
6525 use strict;
6526 use warnings;
6527 use diagnostics;
6528  
6529 use Glib qw(TRUE FALSE);
6530  
6531 @Language::Axbasic::Function::Intrinsic::String::getexitstatus::ISA = qw(
6532 Language::Axbasic::Function::Intrinsic::String
6533 );
6534  
6535 # Getexitstatus$ (number)
6536  
6537 ##################
6538 # Methods
6539  
6540 sub evaluate {
6541  
6542 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6543 #
6544 # Expected arguments
6545 # $arg - The first (and only) argument in the argument list
6546 #
6547 # Return values
6548 # The return value of the function
6549  
6550 my ($self, $arg) = @_;
6551  
6552 # Local variables
6553 my ($mapObj, $wmObj, $dir, $exitNum, $obj);
6554  
6555 # (No improper arguments to check)
6556  
6557 # Evaluate the function and return the value
6558 $mapObj = $self->scriptObj->session->mapObj;
6559 $wmObj = $mapObj->worldModelObj;
6560  
6561 # Perl indexes start at 0, but Axbasic indexes start at 1
6562 $arg--;
6563  
6564 if (
6565 ! $mapObj->currentRoom
6566 || ! $mapObj->currentRoom->sortedExitList
6567 || $arg < 0
6568 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
6569 ) {
6570 # No current room, no exits in current room, invalid exit number or numbered exit
6571 # doesn't exist
6572 return '';
6573  
6574 } else {
6575  
6576 # Get the exit model object
6577 $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
6578 $exitNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir);
6579 if (! $exitNum || ! $wmObj->ivExists('exitModelHash', $exitNum)) {
6580  
6581 # Exit model object not found
6582 return '';
6583  
6584 } else {
6585  
6586 $obj = $wmObj->ivShow('exitModelHash', $exitNum);
6587  
6588 # Return the exit's status
6589 if ($obj->superFlag) {
6590 return 'super';
6591 } elsif ($obj->regionFlag) {
6592 return 'region';
6593 } elsif ($obj->brokenFlag) {
6594 return 'broken';
6595 } else {
6596 return 'normal';
6597 }
6598 }
6599 }
6600 }
6601 }
6602  
6603 { package Language::Axbasic::Function::Intrinsic::String::getexittype;
6604  
6605 use strict;
6606 use warnings;
6607 use diagnostics;
6608  
6609 use Glib qw(TRUE FALSE);
6610  
6611 @Language::Axbasic::Function::Intrinsic::String::getexittype::ISA = qw(
6612 Language::Axbasic::Function::Intrinsic::String
6613 );
6614  
6615 # Getexittype$ (number)
6616  
6617 ##################
6618 # Methods
6619  
6620 sub evaluate {
6621  
6622 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6623 #
6624 # Expected arguments
6625 # $arg - The first (and only) argument in the argument list
6626 #
6627 # Return values
6628 # The return value of the function
6629  
6630 my ($self, $arg) = @_;
6631  
6632 # Local variables
6633 my ($mapObj, $wmObj, $dir, $exitNum, $obj);
6634  
6635 # (No improper arguments to check)
6636  
6637 # Evaluate the function and return the value
6638 $mapObj = $self->scriptObj->session->mapObj;
6639 $wmObj = $mapObj->worldModelObj;
6640  
6641 # Perl indexes start at 0, but Axbasic indexes start at 1
6642 $arg--;
6643  
6644 if (
6645 ! $mapObj->currentRoom
6646 || ! $mapObj->currentRoom->sortedExitList
6647 || $arg < 0
6648 || $arg >= scalar ($mapObj->currentRoom->sortedExitList)
6649 ) {
6650 # No current room, no exits in current room, invalid exit number or numbered exit
6651 # doesn't exist
6652 return '';
6653  
6654 } else {
6655  
6656 # Get the exit model object
6657 $dir = $mapObj->currentRoom->ivIndex('sortedExitList', $arg);
6658 $exitNum = $mapObj->currentRoom->ivShow('exitNumHash', $dir);
6659 if (! $exitNum || ! $wmObj->ivExists('exitModelHash', $exitNum)) {
6660  
6661 # Exit model object not found
6662 return '';
6663  
6664 } else {
6665  
6666 $obj = $wmObj->ivShow('exitModelHash', $exitNum);
6667  
6668 # Return the type of exit
6669 if ($obj->exitOrnament eq 'impass') {
6670  
6671 return 'impassable';
6672  
6673 } elsif ($obj->exitOrnament eq 'mystery') {
6674  
6675 return 'mystery';
6676  
6677 } elsif ($obj->drawMode eq 'temp_alloc' || $obj->drawMode eq 'temp_unalloc') {
6678  
6679 return 'unallocated';
6680  
6681 } elsif ($obj->destRoom) {
6682  
6683 if ($obj->twinExit) {
6684 return 'two_way';
6685 } elsif ($obj->retraceFlag) {
6686 return 'retrace';
6687 } elsif ($obj->oneWayFlag) {
6688 return 'one_way';
6689 } elsif ($obj->randomType ne 'none') {
6690 return 'random';
6691 } else {
6692 return 'uncertain';
6693 }
6694  
6695 } elsif ($obj->randomType ne 'none') {
6696  
6697 return 'random';
6698  
6699 } else {
6700  
6701 return 'incomplete';
6702 }
6703 }
6704 }
6705 }
6706 }
6707  
6708 { package Language::Axbasic::Function::Intrinsic::String::getlight;
6709  
6710 use strict;
6711 use warnings;
6712 use diagnostics;
6713  
6714 use Glib qw(TRUE FALSE);
6715  
6716 @Language::Axbasic::Function::Intrinsic::String::getlight::ISA = qw(
6717 Language::Axbasic::Function::Intrinsic::String
6718 );
6719  
6720 # Getlight$ ()
6721  
6722 ##################
6723 # Methods
6724  
6725 sub evaluate {
6726  
6727 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6728 #
6729 # Expected arguments
6730 # $arg - The first (and only) argument in the argument list
6731 #
6732 # Return values
6733 # The return value of the function
6734  
6735 my ($self, $arg) = @_;
6736  
6737 # (No improper arguments to check)
6738  
6739 # Evaluate the function and return the value
6740 return $self->scriptObj->session->worldModelObj->lightStatus;
6741 }
6742 }
6743  
6744 { package Language::Axbasic::Function::Intrinsic::String::getmapmode;
6745  
6746 use strict;
6747 use warnings;
6748 use diagnostics;
6749  
6750 use Glib qw(TRUE FALSE);
6751  
6752 @Language::Axbasic::Function::Intrinsic::String::getmapmode::ISA = qw(
6753 Language::Axbasic::Function::Intrinsic::String
6754 );
6755  
6756 # Getmapmode$ ()
6757  
6758 ##################
6759 # Methods
6760  
6761 sub evaluate {
6762  
6763 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
6764 #
6765 # Expected arguments
6766 # $arg - The first (and only) argument in the argument list
6767 #
6768 # Return values
6769 # The return value of the function
6770  
6771 my ($self, $arg) = @_;
6772  
6773 # Local variables
6774 my $mapWin;
6775  
6776 # (No improper arguments to check)
6777  
6778 # Evaluate the function and return the value
6779 $mapWin = $self->scriptObj->session->mapWin;
6780  
6781 if (! $mapWin || ! $mapWin->mode) {
6782  
6783 # Automapper window closed, or no mode set (unlikely)
6784 return '';
6785  
6786 } else {
6787  
6788 # Return the mode
6789 return $mapWin->mode;
6790 }
6791 }
6792 }
6793  
6794 { package Language::Axbasic::Function::Intrinsic::String::getobject;
6795  
6796 use strict;
6797 use warnings;
6798 use diagnostics;
6799  
6800 use Glib qw(TRUE FALSE);
6801  
6802 @Language::Axbasic::Function::Intrinsic::String::getobject::ISA = qw(
6803 Language::Axbasic::Function::Intrinsic::String
6804 );
6805  
6806 # Getobject$ (number)
6807  
6808 ##################
6809 # Methods
6810  
6811 sub evaluate {
6812  
6813 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6814 #
6815 # Expected arguments
6816 # $arg - The first (and only) argument in the argument list
6817 #
6818 # Return values
6819 # The return value of the function
6820  
6821 my ($self, $arg) = @_;
6822  
6823 # Local variables
6824 my ($taskObj, $roomObj, $thisObj);
6825  
6826 # (No improper arguments to check)
6827  
6828 # Evaluate the function and return the value
6829 $taskObj = $self->scriptObj->session->locatorTask;
6830 if (! $taskObj) {
6831  
6832 # Locator task not running
6833 return '';
6834 }
6835  
6836 # Perl indexes start at 0, but Axbasic indexes start at 1
6837 $arg--;
6838  
6839 $roomObj = $taskObj->roomObj;
6840 if (
6841 ! $roomObj
6842 || ! $roomObj->tempObjList
6843 || $arg < 0
6844 || scalar $roomObj->tempObjList <= $arg
6845 ) {
6846 # Locator task doesn't know current location, current location is empty or the
6847 # numbered object doesn't exist
6848 return '';
6849  
6850 } else {
6851  
6852 # Return the object's base string
6853 $thisObj = $roomObj->ivIndex('tempObjList', $arg);
6854  
6855 if (defined $thisObj->baseString) {
6856 return $thisObj->baseString;
6857 } else {
6858 return '';
6859 }
6860 }
6861 }
6862 }
6863  
6864 { package Language::Axbasic::Function::Intrinsic::String::getobjectnoun;
6865  
6866 use strict;
6867 use warnings;
6868 use diagnostics;
6869  
6870 use Glib qw(TRUE FALSE);
6871  
6872 @Language::Axbasic::Function::Intrinsic::String::getobjectnoun::ISA = qw(
6873 Language::Axbasic::Function::Intrinsic::String
6874 );
6875  
6876 # Getobjectnoun$ (number)
6877  
6878 ##################
6879 # Methods
6880  
6881 sub evaluate {
6882  
6883 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6884 #
6885 # Expected arguments
6886 # $arg - The first (and only) argument in the argument list
6887 #
6888 # Return values
6889 # The return value of the function
6890  
6891 my ($self, $arg) = @_;
6892  
6893 # Local variables
6894 my ($taskObj, $roomObj, $thisObj);
6895  
6896 # (No improper arguments to check)
6897  
6898 # Evaluate the function and return the value
6899 $taskObj = $self->scriptObj->session->locatorTask;
6900 if (! $taskObj) {
6901  
6902 # Locator task not running
6903 return '';
6904 }
6905  
6906 # Perl indexes start at 0, but Axbasic indexes start at 1
6907 $arg--;
6908  
6909 $roomObj = $taskObj->roomObj;
6910 if (
6911 ! $roomObj
6912 || ! $roomObj->tempObjList
6913 || $arg < 0
6914 || scalar $roomObj->tempObjList <= $arg
6915 ) {
6916 # Locator task doesn't know current location, current location is empty or the
6917 # numbered object doesn't exist
6918 return '';
6919  
6920 } else {
6921  
6922 # Return the object's main noun, if set
6923 $thisObj = $roomObj->ivIndex('tempObjList', $arg);
6924  
6925 if (defined $thisObj->noun) {
6926 return $thisObj->noun;
6927 } else {
6928 return '';
6929 }
6930 }
6931 }
6932 }
6933  
6934 { package Language::Axbasic::Function::Intrinsic::String::getobjecttype;
6935  
6936 use strict;
6937 use warnings;
6938 use diagnostics;
6939  
6940 use Glib qw(TRUE FALSE);
6941  
6942 @Language::Axbasic::Function::Intrinsic::String::getobjecttype::ISA = qw(
6943 Language::Axbasic::Function::Intrinsic::String
6944 );
6945  
6946 # Getobjecttype$ (number)
6947  
6948 ##################
6949 # Methods
6950  
6951 sub evaluate {
6952  
6953 # Called by LA::Expression::Function->evaluate (using arguments in the form 'N')
6954 #
6955 # Expected arguments
6956 # $arg - The first (and only) argument in the argument list
6957 #
6958 # Return values
6959 # The return value of the function
6960  
6961 my ($self, $arg) = @_;
6962  
6963 # Local variables
6964 my ($taskObj, $roomObj, $thisObj);
6965  
6966 # (No improper arguments to check)
6967  
6968 # Evaluate the function and return the value
6969 $taskObj = $self->scriptObj->session->locatorTask;
6970 if (! $taskObj) {
6971  
6972 # Locator task not running
6973 return '';
6974 }
6975  
6976 # Perl indexes start at 0, but Axbasic indexes start at 1
6977 $arg--;
6978  
6979 $roomObj = $taskObj->roomObj;
6980 if (
6981 ! $roomObj
6982 || ! $roomObj->tempObjList
6983 || $arg < 0
6984 || scalar $roomObj->tempObjList <= $arg
6985 ) {
6986 # Locator task doesn't know current location, current location is empty or the
6987 # numbered object doesn't exist
6988 return '';
6989  
6990 } else {
6991  
6992 # Return the object's category
6993 $thisObj = $roomObj->ivIndex('tempObjList', $arg);
6994  
6995 if (defined $thisObj) {
6996 return $thisObj->category;
6997 } else {
6998 return '';
6999 }
7000 }
7001 }
7002 }
7003  
7004 { package Language::Axbasic::Function::Intrinsic::String::getregion;
7005  
7006 use strict;
7007 use warnings;
7008 use diagnostics;
7009  
7010 use Glib qw(TRUE FALSE);
7011  
7012 @Language::Axbasic::Function::Intrinsic::String::getregion::ISA = qw(
7013 Language::Axbasic::Function::Intrinsic::String
7014 );
7015  
7016 # Getregion$ ()
7017  
7018 ##################
7019 # Methods
7020  
7021 sub evaluate {
7022  
7023 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7024 #
7025 # Expected arguments
7026 # $arg - The first (and only) argument in the argument list
7027 #
7028 # Return values
7029 # The return value of the function
7030  
7031 my ($self, $arg) = @_;
7032  
7033 # Local variables
7034 my $mapWin;
7035  
7036 # (No improper arguments to check)
7037  
7038 # Evaluate the function and return the value
7039 $mapWin = $self->scriptObj->session->mapWin;
7040 if (! $mapWin || ! $mapWin->currentRegionmap) {
7041  
7042 # Automapper window closed, or no current region
7043 return '';
7044  
7045 } else {
7046  
7047 # Return the name of the current region
7048 return $mapWin->currentRegionmap->name;
7049 }
7050 }
7051 }
7052  
7053 { package Language::Axbasic::Function::Intrinsic::String::getroomdescrip;
7054  
7055 use strict;
7056 use warnings;
7057 use diagnostics;
7058  
7059 use Glib qw(TRUE FALSE);
7060  
7061 @Language::Axbasic::Function::Intrinsic::String::getroomdescrip::ISA = qw(
7062 Language::Axbasic::Function::Intrinsic::String
7063 );
7064  
7065 # Getroomdescrip$ ()
7066 # Getroomdescrip$ (string)
7067  
7068 ##################
7069 # Methods
7070  
7071 sub evaluate {
7072  
7073 # Called by LA::Expression::Function->evaluate (using arguments in the form ';S')
7074 #
7075 # Expected arguments
7076 # $arg - The first (and only) argument in the argument list
7077 #
7078 # Return values
7079 # The return value of the function
7080  
7081 my ($self, $arg) = @_;
7082  
7083 # Local variables
7084 my $mapObj;
7085  
7086 # (No improper arguments to check)
7087  
7088 # Evaluate the function and return the value
7089 $mapObj = $self->scriptObj->session->mapObj;
7090 if (! $mapObj->currentRoom) {
7091  
7092 # No current room
7093 return '';
7094  
7095 } else {
7096  
7097 # If the user didn't specify a light status, use the current light status
7098 if (! $arg) {
7099  
7100 $arg = $mapObj->worldModelObj->lightStatus;
7101 }
7102  
7103 # Return the matching verbose descrip (if there is one) or an empty string otherwise
7104 if ($mapObj->currentRoom->ivExists('descripHash', $arg)) {
7105  
7106 return $mapObj->currentRoom->ivShow('descripHash', $arg)
7107  
7108 } else {
7109  
7110 return '';
7111 }
7112 }
7113 }
7114 }
7115  
7116 { package Language::Axbasic::Function::Intrinsic::String::getroomguild;
7117  
7118 use strict;
7119 use warnings;
7120 use diagnostics;
7121  
7122 use Glib qw(TRUE FALSE);
7123  
7124 @Language::Axbasic::Function::Intrinsic::String::getroomguild::ISA = qw(
7125 Language::Axbasic::Function::Intrinsic::String
7126 );
7127  
7128 # Getroomguild$ ()
7129  
7130 ##################
7131 # Methods
7132  
7133 sub evaluate {
7134  
7135 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7136 #
7137 # Expected arguments
7138 # $arg - The first (and only) argument in the argument list
7139 #
7140 # Return values
7141 # The return value of the function
7142  
7143 my ($self, $arg) = @_;
7144  
7145 # Local variables
7146 my $mapObj;
7147  
7148 # (No improper arguments to check)
7149  
7150 # Evaluate the function and return the value
7151 $mapObj = $self->scriptObj->session->mapObj;
7152  
7153 if (! $mapObj->currentRoom || ! $mapObj->currentRoom->roomGuild) {
7154  
7155 # No current room, or current room has no room guild
7156 return '';
7157  
7158 } else {
7159  
7160 # Return the current room's room guild
7161 return $mapObj->currentRoom->roomGuild;
7162 }
7163 }
7164 }
7165  
7166 { package Language::Axbasic::Function::Intrinsic::String::getroomsource;
7167  
7168 use strict;
7169 use warnings;
7170 use diagnostics;
7171  
7172 use Glib qw(TRUE FALSE);
7173  
7174 @Language::Axbasic::Function::Intrinsic::String::getroomsource::ISA = qw(
7175 Language::Axbasic::Function::Intrinsic::String
7176 );
7177  
7178 # Getroomsource$ ()
7179  
7180 ##################
7181 # Methods
7182  
7183 sub evaluate {
7184  
7185 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7186 #
7187 # Expected arguments
7188 # $arg - The first (and only) argument in the argument list
7189 #
7190 # Return values
7191 # The return value of the function
7192  
7193 my ($self, $arg) = @_;
7194  
7195 # Local variables
7196 my $mapObj;
7197  
7198 # (No improper arguments to check)
7199  
7200 # Evaluate the function and return the value
7201 $mapObj = $self->scriptObj->session->mapObj;
7202  
7203 if (
7204 ! $mapObj->currentRoom
7205 || (! $mapObj->currentRoom->sourceCodePath && ! $mapObj->currentRoom->virtualAreaPath)
7206 ) {
7207 # No current room, or current room has no source code path set
7208 return '';
7209  
7210 } else {
7211  
7212 # Return the current room's virtual area path, if set; otherwise return its source code
7213 # path
7214 if ($mapObj->currentRoom->virtualAreaPath) {
7215 return $mapObj->currentRoom->virtualAreaPath;
7216 } else {
7217 return $mapObj->currentRoom->sourceCodePath;
7218 }
7219 }
7220 }
7221 }
7222  
7223 { package Language::Axbasic::Function::Intrinsic::String::getroomtag;
7224  
7225 use strict;
7226 use warnings;
7227 use diagnostics;
7228  
7229 use Glib qw(TRUE FALSE);
7230  
7231 @Language::Axbasic::Function::Intrinsic::String::getroomtag::ISA = qw(
7232 Language::Axbasic::Function::Intrinsic::String
7233 );
7234  
7235 # Getroomtag$ ()
7236  
7237 ##################
7238 # Methods
7239  
7240 sub evaluate {
7241  
7242 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7243 #
7244 # Expected arguments
7245 # $arg - The first (and only) argument in the argument list
7246 #
7247 # Return values
7248 # The return value of the function
7249  
7250 my ($self, $arg) = @_;
7251  
7252 # Local variables
7253 my $mapObj;
7254  
7255 # (No improper arguments to check)
7256  
7257 # Evaluate the function and return the value
7258 $mapObj = $self->scriptObj->session->mapObj;
7259  
7260 if (! $mapObj->currentRoom || ! $mapObj->currentRoom->roomTag) {
7261  
7262 # No current room, or current room has no room tag
7263 return '';
7264  
7265 } else {
7266  
7267 # Return the current room's room tag
7268 return $mapObj->currentRoom->roomTag;
7269 }
7270 }
7271 }
7272  
7273 { package Language::Axbasic::Function::Intrinsic::String::getroomtitle;
7274  
7275 use strict;
7276 use warnings;
7277 use diagnostics;
7278  
7279 use Glib qw(TRUE FALSE);
7280  
7281 @Language::Axbasic::Function::Intrinsic::String::getroomtitle::ISA = qw(
7282 Language::Axbasic::Function::Intrinsic::String
7283 );
7284  
7285 # Getroomtitle$ ()
7286  
7287 ##################
7288 # Methods
7289  
7290 sub evaluate {
7291  
7292 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7293 #
7294 # Expected arguments
7295 # $arg - The first (and only) argument in the argument list
7296 #
7297 # Return values
7298 # The return value of the function
7299  
7300 my ($self, $arg) = @_;
7301  
7302 # Local variables
7303 my $mapObj;
7304  
7305 # (No improper arguments to check)
7306  
7307 # Evaluate the function and return the value
7308 $mapObj = $self->scriptObj->session->mapObj;
7309  
7310 if (
7311 ! $mapObj->currentRoom
7312 || ! $mapObj->currentRoom->titleList
7313 ) {
7314 # No current room, or current room has no title set
7315 return '';
7316  
7317 } else {
7318  
7319 # Return the current room's (first) title
7320 return $mapObj->currentRoom->ivFirst('titleList');
7321 }
7322 }
7323 }
7324  
7325 { package Language::Axbasic::Function::Intrinsic::String::iface;
7326  
7327 use strict;
7328 use warnings;
7329 use diagnostics;
7330  
7331 use Glib qw(TRUE FALSE);
7332  
7333 @Language::Axbasic::Function::Intrinsic::String::iface::ISA = qw(
7334 Language::Axbasic::Function::Intrinsic::String
7335 );
7336  
7337 # Iface$ ()
7338  
7339 ##################
7340 # Methods
7341  
7342 sub evaluate {
7343  
7344 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7345 #
7346 # Expected arguments
7347 # $arg - The first (and only) argument in the argument list
7348 #
7349 # Return values
7350 # The return value of the function
7351  
7352 my ($self, $arg) = @_;
7353  
7354 # (No improper arguments to check)
7355  
7356 # Evaluate the function and return the value
7357 if (! $self->scriptObj->depInterfaceName) {
7358  
7359 # Either no dependent interface has been created by this script, or the last attempt
7360 # failed
7361 return '';
7362  
7363 } else {
7364  
7365 # The IV contains the name of the most recently-created dependent interface
7366 return $self->scriptObj->depInterfaceName;
7367 }
7368 }
7369 }
7370  
7371 { package Language::Axbasic::Function::Intrinsic::String::ifacedata;
7372  
7373 use strict;
7374 use warnings;
7375 use diagnostics;
7376  
7377 use Glib qw(TRUE FALSE);
7378  
7379 @Language::Axbasic::Function::Intrinsic::String::ifacedata::ISA = qw(
7380 Language::Axbasic::Function::Intrinsic::String
7381 );
7382  
7383 # Ifacedata$ ()
7384  
7385 ##################
7386 # Methods
7387  
7388 sub evaluate {
7389  
7390 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7391 #
7392 # Expected arguments
7393 # $arg - The first (and only) argument in the argument list
7394 #
7395 # Return values
7396 # The return value of the function
7397  
7398 my ($self, $arg) = @_;
7399  
7400 # Local variables
7401 my ($obj, $substr);
7402  
7403 # (No improper arguments to check)
7404  
7405 # Evaluate the function and return the value
7406 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7407  
7408 # The notification list is empty, so return an empty string
7409 return '';
7410  
7411 } else {
7412  
7413 # Get the current notification
7414 $obj = $self->scriptObj->ivIndex(
7415 'notificationList',
7416 $self->scriptObj->currentNotification,
7417 );
7418  
7419 # Return the first item in ->dataList. If it's an undefined value, returns an empty
7420 # string instead
7421 # For triggers/aliases, it's the first substring (which might be 'undef', which is
7422 # converted to an empty string)
7423 # For macros, ->dataList is always empty, so an empty string will be returned
7424 # For timers whose stimulus is a clock string (in the form "HH:MM" or "99::MM"), returns
7425 # the clock string, otherwise returns an empty string, returns the
7426 # For hooks, if the hook event has hook data, returns it; otherwise returns an empty
7427 # string
7428 if (! $obj->dataList) {
7429  
7430 # No meaningful value to return
7431 return '';
7432  
7433 } else {
7434  
7435 # If a regex matching a line is in the form (...|...|...), with each ... containing
7436 # its own substrings, ->dataList will contain lots of 'undef' values from
7437 # the ... portions that didn't match the line
7438 # We can't return the 'undef' because it will cause an Axbasic 'Undefined function
7439 # error'. Therefore, return an empty string instead
7440 $substr = $obj->ivFirst('dataList');
7441 if (defined $substr) {
7442 return $substr
7443 } else {
7444 return '';
7445 }
7446 }
7447 }
7448 }
7449 }
7450  
7451 { package Language::Axbasic::Function::Intrinsic::String::ifacename;
7452  
7453 use strict;
7454 use warnings;
7455 use diagnostics;
7456  
7457 use Glib qw(TRUE FALSE);
7458  
7459 @Language::Axbasic::Function::Intrinsic::String::ifacename::ISA = qw(
7460 Language::Axbasic::Function::Intrinsic::String
7461 );
7462  
7463 # Ifacename$ ()
7464  
7465 ##################
7466 # Methods
7467  
7468 sub evaluate {
7469  
7470 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7471 #
7472 # Expected arguments
7473 # $arg - The first (and only) argument in the argument list
7474 #
7475 # Return values
7476 # The return value of the function
7477  
7478 my ($self, $arg) = @_;
7479  
7480 # Local variables
7481 my $obj;
7482  
7483 # (No improper arguments to check)
7484  
7485 # Evaluate the function and return the value
7486 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7487  
7488 # The notification list is empty, so return an empty string
7489 return '';
7490  
7491 } else {
7492  
7493 # Get the current notification
7494 $obj = $self->scriptObj->ivIndex(
7495 'notificationList',
7496 $self->scriptObj->currentNotification,
7497 );
7498  
7499 # Return its name of the corresponding interface
7500 return $obj->name;
7501 }
7502 }
7503 }
7504  
7505 { package Language::Axbasic::Function::Intrinsic::String::ifacepop;
7506  
7507 use strict;
7508 use warnings;
7509 use diagnostics;
7510  
7511 use Glib qw(TRUE FALSE);
7512  
7513 @Language::Axbasic::Function::Intrinsic::String::ifacepop::ISA = qw(
7514 Language::Axbasic::Function::Intrinsic::String
7515 );
7516  
7517 # Ifacepop$ ()
7518  
7519 ##################
7520 # Methods
7521  
7522 sub evaluate {
7523  
7524 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7525 #
7526 # Expected arguments
7527 # $arg - The first (and only) argument in the argument list
7528 #
7529 # Return values
7530 # The return value of the function
7531  
7532 my ($self, $arg) = @_;
7533  
7534 # Local variables
7535 my ($obj, $substr);
7536  
7537 # (No improper arguments to check)
7538  
7539 # Evaluate the function and return the value
7540 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7541  
7542 # The notification list is empty, so return an empty string
7543 return '';
7544  
7545 } else {
7546  
7547 # Get the current notification
7548 $obj = $self->scriptObj->ivIndex(
7549 'notificationList',
7550 $self->scriptObj->currentNotification,
7551 );
7552  
7553 if (! $obj->dataList) {
7554  
7555 # No additional data to return
7556 return '';
7557  
7558 } else {
7559  
7560 # If a regex matching a line is in the form (...|...|...), with each ... containing
7561 # its own substrings, ->dataList will contain lots of 'undef' values from
7562 # the ... portions that didn't match the line
7563 # We can't return the 'undef' because it will cause an Axbasic 'Undefined function
7564 # error'. Therefore, return an empty string instead
7565 $substr = $obj->ivPop('dataList');
7566 if (defined $substr) {
7567 return $substr
7568 } else {
7569 return '';
7570 }
7571 }
7572 }
7573 }
7574 }
7575  
7576 { package Language::Axbasic::Function::Intrinsic::String::ifaceselect;
7577  
7578 use strict;
7579 use warnings;
7580 use diagnostics;
7581  
7582 use Glib qw(TRUE FALSE);
7583  
7584 @Language::Axbasic::Function::Intrinsic::String::ifaceselect::ISA = qw(
7585 Language::Axbasic::Function::Intrinsic::String
7586 );
7587  
7588 # Ifaceselect$ (number)
7589  
7590 ##################
7591 # Methods
7592  
7593 sub evaluate {
7594  
7595 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7596 #
7597 # Expected arguments
7598 # $arg - The first (and only) argument in the argument list
7599 #
7600 # Return values
7601 # The return value of the function
7602  
7603 my ($self, $arg) = @_;
7604  
7605 # Local variables
7606 my ($obj, $substr);
7607  
7608 # (No improper arguments to check)
7609  
7610 # Evaluate the function and return the value
7611 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7612  
7613 # The notification list is empty, so return an empty string
7614 return '';
7615  
7616 } else {
7617  
7618 # Get the current notification
7619 $obj = $self->scriptObj->ivIndex(
7620 'notificationList',
7621 $self->scriptObj->currentNotification,
7622 );
7623  
7624 if (! $obj->dataList) {
7625  
7626 # No additional data to return
7627 return '';
7628  
7629 } else {
7630  
7631 # If a regex matching a line is in the form (...|...|...), with each ... containing
7632 # its own substrings, ->dataList will contain lots of 'undef' values from
7633 # the ... portions that didn't match the line
7634 # We can't return the 'undef' because it will cause an Axbasic 'Undefined function
7635 # error'. Therefore, return an empty string instead
7636 $substr = $obj->ivIndex('dataList', ($arg - 1));
7637 if (defined $substr) {
7638 return $substr
7639 } else {
7640 return '';
7641 }
7642 }
7643 }
7644 }
7645 }
7646  
7647 { package Language::Axbasic::Function::Intrinsic::String::ifaceshift;
7648  
7649 use strict;
7650 use warnings;
7651 use diagnostics;
7652  
7653 use Glib qw(TRUE FALSE);
7654  
7655 @Language::Axbasic::Function::Intrinsic::String::ifaceshift::ISA = qw(
7656 Language::Axbasic::Function::Intrinsic::String
7657 );
7658  
7659 # Ifaceshift$ ()
7660  
7661 ##################
7662 # Methods
7663  
7664 sub evaluate {
7665  
7666 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7667 #
7668 # Expected arguments
7669 # $arg - The first (and only) argument in the argument list
7670 #
7671 # Return values
7672 # The return value of the function
7673  
7674 my ($self, $arg) = @_;
7675  
7676 # Local variables
7677 my ($obj, $substr);
7678  
7679 # (No improper arguments to check)
7680  
7681 # Evaluate the function and return the value
7682 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7683  
7684 # The notification list is empty, so return an empty string
7685 return '';
7686  
7687 } else {
7688  
7689 # Get the current notification
7690 $obj = $self->scriptObj->ivIndex(
7691 'notificationList',
7692 $self->scriptObj->currentNotification,
7693 );
7694  
7695 if (! $obj->dataList) {
7696  
7697 # No additional data to return
7698 return '';
7699  
7700 } else {
7701  
7702 # If a regex matching a line is in the form (...|...|...), with each ... containing
7703 # its own substrings, ->dataList will contain lots of 'undef' values from
7704 # the ... portions that didn't match the line
7705 # We can't return the 'undef' because it will cause an Axbasic 'Undefined function
7706 # error'. Therefore, return an empty string instead
7707 $substr = $obj->ivShift('dataList');
7708 if (defined $substr) {
7709 return $substr
7710 } else {
7711 return '';
7712 }
7713 }
7714 }
7715 }
7716 }
7717  
7718 { package Language::Axbasic::Function::Intrinsic::String::ifacetext;
7719  
7720 use strict;
7721 use warnings;
7722 use diagnostics;
7723  
7724 use Glib qw(TRUE FALSE);
7725  
7726 @Language::Axbasic::Function::Intrinsic::String::ifacetext::ISA = qw(
7727 Language::Axbasic::Function::Intrinsic::String
7728 );
7729  
7730 # Ifacetext$ ()
7731  
7732 ##################
7733 # Methods
7734  
7735 sub evaluate {
7736  
7737 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7738 #
7739 # Expected arguments
7740 # $arg - The first (and only) argument in the argument list
7741 #
7742 # Return values
7743 # The return value of the function
7744  
7745 my ($self, $arg) = @_;
7746  
7747 # Local variables
7748 my $obj;
7749  
7750 # (No improper arguments to check)
7751  
7752 # Evaluate the function and return the value
7753 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7754  
7755 # The notification list is empty, so return an empty string
7756 return '';
7757  
7758 } else {
7759  
7760 # Get the current notification
7761 $obj = $self->scriptObj->ivIndex(
7762 'notificationList',
7763 $self->scriptObj->currentNotification,
7764 );
7765  
7766 # Return the cause for the fired interface
7767 return $obj->fireBecause;
7768 }
7769 }
7770 }
7771  
7772 { package Language::Axbasic::Function::Intrinsic::String::ifacetype;
7773  
7774 use strict;
7775 use warnings;
7776 use diagnostics;
7777  
7778 use Glib qw(TRUE FALSE);
7779  
7780 @Language::Axbasic::Function::Intrinsic::String::ifacetype::ISA = qw(
7781 Language::Axbasic::Function::Intrinsic::String
7782 );
7783  
7784 # Ifacetype$ ()
7785  
7786 ##################
7787 # Methods
7788  
7789 sub evaluate {
7790  
7791 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7792 #
7793 # Expected arguments
7794 # $arg - The first (and only) argument in the argument list
7795 #
7796 # Return values
7797 # The return value of the function
7798  
7799 my ($self, $arg) = @_;
7800  
7801 # Local variables
7802 my $obj;
7803  
7804 # (No improper arguments to check)
7805  
7806 # Evaluate the function and return the value
7807 if (! $self->scriptObj->notificationList || $self->scriptObj->currentNotification < 0) {
7808  
7809 # The notification list is empty, so return an empty string
7810 return '';
7811  
7812 } else {
7813  
7814 # Get the current notification
7815 $obj = $self->scriptObj->ivIndex(
7816 'notificationList',
7817 $self->scriptObj->currentNotification,
7818 );
7819  
7820 # Return its category
7821 return $obj->category;
7822 }
7823 }
7824 }
7825  
7826 { package Language::Axbasic::Function::Intrinsic::String::popup;
7827  
7828 use strict;
7829 use warnings;
7830 use diagnostics;
7831  
7832 use Glib qw(TRUE FALSE);
7833  
7834 @Language::Axbasic::Function::Intrinsic::String::popup::ISA = qw(
7835 Language::Axbasic::Function::Intrinsic::String
7836 );
7837  
7838 # Popup$ (type, text, response)
7839  
7840 ##################
7841 # Methods
7842  
7843 sub evaluate {
7844  
7845 # Called by LA::Expression::Function->evaluate (using arguments in the form 'SSS')
7846 #
7847 # Expected arguments
7848 # @args - The list of arguments supplied to the function
7849 #
7850 # Return values
7851 # The return value of the function
7852  
7853 my ($self, @args) = @_;
7854  
7855 # Local variables
7856 my ($type, $response, $choice);
7857  
7858 # (No improper arguments to check)
7859  
7860 # Evaluate the function and return the value
7861  
7862 # Check that the type is one of the values permitted by GA::Generic::Win->showMsgDialogue
7863 # and, if not, use a default type
7864 $type = $args[0];
7865 if (
7866 $type ne 'info' && $type ne 'warning' && $type ne 'error' && $type ne 'question'
7867 ) {
7868 $type = 'info';
7869 }
7870  
7871 # Substitute a hyphen for any underlines or spaces in the response
7872 $response = $args[2];
7873 $response =~ s/_/-/;
7874 $response =~ s/\s/-/;
7875 # Check that the response is one of the values permitted by
7876 # GA::Generic::Win->showMsgDialogue and, if not, use a default respone
7877 if (
7878 $response ne 'none' && $response ne 'ok' && $response ne 'close'
7879 && $response ne 'cancel' && $response ne 'yes-no' && $response ne 'ok-cancel'
7880 ) {
7881 $response = 'ok';
7882 }
7883  
7884 # Open a 'dialogue' window to prompt the user
7885 $choice = $self->scriptObj->session->mainWin->showMsgDialogue(
7886 $self->scriptObj->name, # Use the script name as the window's title
7887 $type,
7888 $args[1],
7889 $response,
7890 );
7891  
7892 if (! $choice || $choice eq 'delete-event') {
7893 return "";
7894 } else {
7895 return $choice;
7896 }
7897 }
7898 }
7899  
7900 { package Language::Axbasic::Function::Intrinsic::String::scriptname;
7901  
7902 use strict;
7903 use warnings;
7904 use diagnostics;
7905  
7906 use Glib qw(TRUE FALSE);
7907  
7908 @Language::Axbasic::Function::Intrinsic::String::scriptname::ISA = qw(
7909 Language::Axbasic::Function::Intrinsic::String
7910 );
7911  
7912 # Scriptname$ ()
7913  
7914 ##################
7915 # Methods
7916  
7917 sub evaluate {
7918  
7919 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7920 #
7921 # Expected arguments
7922 # $arg - The first (and only) argument in the argument list
7923 #
7924 # Return values
7925 # The return value of the function
7926  
7927 my ($self, $arg) = @_;
7928  
7929 # Local variables
7930 my $obj;
7931  
7932 # (No improper arguments to check)
7933  
7934 # Evaluate the function and return the value
7935 return $self->scriptObj->name;
7936 }
7937 }
7938  
7939 { package Language::Axbasic::Function::Intrinsic::String::showprofile;
7940  
7941 use strict;
7942 use warnings;
7943 use diagnostics;
7944  
7945 use Glib qw(TRUE FALSE);
7946  
7947 @Language::Axbasic::Function::Intrinsic::String::showprofile::ISA = qw(
7948 Language::Axbasic::Function::Intrinsic::String
7949 );
7950  
7951 # Showprofile$ ()
7952  
7953 ##################
7954 # Methods
7955  
7956 sub evaluate {
7957  
7958 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
7959 #
7960 # Expected arguments
7961 # $arg - The first (and only) argument in the argument list
7962 #
7963 # Return values
7964 # The return value of the function
7965  
7966 my ($self, $arg) = @_;
7967  
7968 # (No improper arguments to check)
7969  
7970 # Evaluate the function and return the value
7971  
7972 # A value of 'undef' means 'use the current world'
7973 if (! defined $self->scriptObj->useProfile) {
7974  
7975 return $self->scriptObj->session->currentWorld->name;
7976  
7977 } else {
7978  
7979 return $self->scriptObj->useProfile;
7980 }
7981 }
7982 }
7983  
7984 { package Language::Axbasic::Function::Intrinsic::String::unabbrevdir;
7985  
7986 use strict;
7987 use warnings;
7988 use diagnostics;
7989  
7990 use Glib qw(TRUE FALSE);
7991  
7992 @Language::Axbasic::Function::Intrinsic::String::unabbrevdir::ISA = qw(
7993 Language::Axbasic::Function::Intrinsic::String
7994 );
7995  
7996 # Unabbrevdir$ ()
7997  
7998 ##################
7999 # Methods
8000  
8001 sub evaluate {
8002  
8003 # Called by LA::Expression::Function->evaluate (using arguments in the form '')
8004 #
8005 # Expected arguments
8006 # $arg - The first (and only) argument in the argument list
8007 #
8008 # Return values
8009 # The return value of the function
8010  
8011 my ($self, $arg) = @_;
8012  
8013 # (No improper arguments to check)
8014  
8015 # Evaluate the function and return the value
8016 return $self->scriptObj->session->currentDict->unabbrevDir($arg);
8017 }
8018 }
8019  
8020 # Package must return a true value
8021 1