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

filter: Statementstmt 0.0% 0 / 7521 Branchbran 0.0% 0 / 2964 Conditioncond 0.0% 0 / 828 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 971 Podpod 0.0% 0 / 334 totaltotal 0.0% 0 / 12618 CC 1483 SCAR 43.5
CC
1483
Cov
0%
parse
930.0
implement
812.0
implement
650.0
CRAP 77.5
1 # Copyright (C) 2011-2022 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::Statement, based on Language::Basic by Amir Karger
16  
17 { package Language::Axbasic::Statement;
18  
19 use strict;
20 use warnings;
21 use diagnostics;
22  
23 use Glib qw(TRUE FALSE);
24  
25 @Language::Axbasic::Statement::ISA = qw(
26 Language::Axbasic
27 );
28  
29 # Sub-classes
30 {
31 package Language::Axbasic::Statement::addalias;
32 package Language::Axbasic::Statement::addcongauge;
33 package Language::Axbasic::Statement::addconstatus;
34 package Language::Axbasic::Statement::addgauge;
35 package Language::Axbasic::Statement::addhook;
36 package Language::Axbasic::Statement::addmacro;
37 package Language::Axbasic::Statement::addstatus;
38 package Language::Axbasic::Statement::addtimer;
39 package Language::Axbasic::Statement::addtrig;
40 package Language::Axbasic::Statement::beep;
41 package Language::Axbasic::Statement::break;
42 package Language::Axbasic::Statement::bypass;
43 package Language::Axbasic::Statement::call;
44 package Language::Axbasic::Statement::case;
45 package Language::Axbasic::Statement::client;
46 package Language::Axbasic::Statement::cls;
47 package Language::Axbasic::Statement::close;
48 package Language::Axbasic::Statement::closewin;
49 package Language::Axbasic::Statement::data;
50 package Language::Axbasic::Statement::debug;
51 package Language::Axbasic::Statement::def;
52 package Language::Axbasic::Statement::delalias;
53 package Language::Axbasic::Statement::delgauge;
54 package Language::Axbasic::Statement::delhook;
55 package Language::Axbasic::Statement::deliface;
56 package Language::Axbasic::Statement::delmacro;
57 package Language::Axbasic::Statement::delstatus;
58 package Language::Axbasic::Statement::deltimer;
59 package Language::Axbasic::Statement::deltrig;
60 package Language::Axbasic::Statement::dim;
61 package Language::Axbasic::Statement::do;
62 package Language::Axbasic::Statement::else;
63 package Language::Axbasic::Statement::emptywin;
64 package Language::Axbasic::Statement::end;
65 package Language::Axbasic::Statement::erase;
66 package Language::Axbasic::Statement::error;
67 package Language::Axbasic::Statement::exit;
68 package Language::Axbasic::Statement::flashwin;
69 package Language::Axbasic::Statement::for;
70 package Language::Axbasic::Statement::global;
71 package Language::Axbasic::Statement::gosub;
72 package Language::Axbasic::Statement::goto;
73 package Language::Axbasic::Statement::help;
74 package Language::Axbasic::Statement::if;
75 package Language::Axbasic::Statement::input;
76 package Language::Axbasic::Statement::let;
77 package Language::Axbasic::Statement::local;
78 package Language::Axbasic::Statement::login;
79 package Language::Axbasic::Statement::loop;
80 package Language::Axbasic::Statement::move;
81 package Language::Axbasic::Statement::multi;
82 package Language::Axbasic::Statement::next;
83 package Language::Axbasic::Statement::nextiface;
84 package Language::Axbasic::Statement::on;
85 package Language::Axbasic::Statement::open;
86 package Language::Axbasic::Statement::openentry;
87 package Language::Axbasic::Statement::openwin;
88 package Language::Axbasic::Statement::option;
89 package Language::Axbasic::Statement::paintwin;
90 package Language::Axbasic::Statement::pause;
91 package Language::Axbasic::Statement::peek;
92 package Language::Axbasic::Statement::peekequals;
93 package Language::Axbasic::Statement::peekexists;
94 package Language::Axbasic::Statement::peekfind;
95 package Language::Axbasic::Statement::peekfirst;
96 package Language::Axbasic::Statement::peekget;
97 package Language::Axbasic::Statement::peekindex;
98 package Language::Axbasic::Statement::peekkeys;
99 package Language::Axbasic::Statement::peeklast;
100 package Language::Axbasic::Statement::peekmatch;
101 package Language::Axbasic::Statement::peeknumber;
102 package Language::Axbasic::Statement::peekpairs;
103 package Language::Axbasic::Statement::peekshow;
104 package Language::Axbasic::Statement::peekvalues;
105 package Language::Axbasic::Statement::perl;
106 package Language::Axbasic::Statement::play;
107 package Language::Axbasic::Statement::poke;
108 package Language::Axbasic::Statement::pokedec;
109 package Language::Axbasic::Statement::pokedelete;
110 package Language::Axbasic::Statement::pokedechash;
111 package Language::Axbasic::Statement::pokeempty;
112 package Language::Axbasic::Statement::pokefalse;
113 package Language::Axbasic::Statement::pokeinc;
114 package Language::Axbasic::Statement::pokeinchash;
115 package Language::Axbasic::Statement::pokeint;
116 package Language::Axbasic::Statement::pokeadd;
117 package Language::Axbasic::Statement::pokedivide;
118 package Language::Axbasic::Statement::pokeminus;
119 package Language::Axbasic::Statement::pokemultiply;
120 package Language::Axbasic::Statement::pokeplus;
121 package Language::Axbasic::Statement::pokepop;
122 package Language::Axbasic::Statement::pokepush;
123 package Language::Axbasic::Statement::pokereplace;
124 package Language::Axbasic::Statement::pokeset;
125 package Language::Axbasic::Statement::pokeshift;
126 package Language::Axbasic::Statement::poketrue;
127 package Language::Axbasic::Statement::pokeundef;
128 package Language::Axbasic::Statement::pokeunshift;
129 package Language::Axbasic::Statement::pop;
130 package Language::Axbasic::Statement::print;
131 package Language::Axbasic::Statement::profile;
132 package Language::Axbasic::Statement::push;
133 package Language::Axbasic::Statement::randomize;
134 package Language::Axbasic::Statement::read;
135 package Language::Axbasic::Statement::redim;
136 package Language::Axbasic::Statement::relay;
137 package Language::Axbasic::Statement::rem;
138 package Language::Axbasic::Statement::reset;
139 package Language::Axbasic::Statement::restore;
140 package Language::Axbasic::Statement::return;
141 package Language::Axbasic::Statement::revpath;
142 package Language::Axbasic::Statement::select;
143 package Language::Axbasic::Statement::send;
144 package Language::Axbasic::Statement::setalias;
145 package Language::Axbasic::Statement::setgauge;
146 package Language::Axbasic::Statement::sethook;
147 package Language::Axbasic::Statement::setmacro;
148 package Language::Axbasic::Statement::setstatus;
149 package Language::Axbasic::Statement::settimer;
150 package Language::Axbasic::Statement::settrig;
151 package Language::Axbasic::Statement::shift;
152 package Language::Axbasic::Statement::skipiface;
153 package Language::Axbasic::Statement::sort;
154 package Language::Axbasic::Statement::sortcase;
155 package Language::Axbasic::Statement::sortcaser;
156 package Language::Axbasic::Statement::sortr;
157 package Language::Axbasic::Statement::speak;
158 package Language::Axbasic::Statement::speed;
159 package Language::Axbasic::Statement::stop;
160 package Language::Axbasic::Statement::sub;
161 package Language::Axbasic::Statement::titlewin;
162 package Language::Axbasic::Statement::unflashwin;
163 package Language::Axbasic::Statement::unshift;
164 package Language::Axbasic::Statement::until;
165 package Language::Axbasic::Statement::waitactive;
166 package Language::Axbasic::Statement::waitalive;
167 package Language::Axbasic::Statement::waitarrive;
168 package Language::Axbasic::Statement::waitdead;
169 package Language::Axbasic::Statement::waitep;
170 package Language::Axbasic::Statement::waitgp;
171 package Language::Axbasic::Statement::waithp;
172 package Language::Axbasic::Statement::waitmp;
173 package Language::Axbasic::Statement::waitnextxp;
174 package Language::Axbasic::Statement::waitnotactive;
175 package Language::Axbasic::Statement::waitpassout;
176 package Language::Axbasic::Statement::waitscript;
177 package Language::Axbasic::Statement::waitsleep;
178 package Language::Axbasic::Statement::waitsp;
179 package Language::Axbasic::Statement::waittask;
180 package Language::Axbasic::Statement::waittotalxp;
181 package Language::Axbasic::Statement::waittrig;
182 package Language::Axbasic::Statement::waitxp;
183 package Language::Axbasic::Statement::warning;
184 package Language::Axbasic::Statement::while;
185 package Language::Axbasic::Statement::write;
186 package Language::Axbasic::Statement::writewin;
187 }
188  
189 ##################
190 # Constructors
191  
192 sub new {
193  
194 # Called by LA::Line->parse (or by the ->parse function of another LA::Statement::xxx
195 # object)
196 # The class that handles the parsing of a single Axbasic statement
197 # This function blesses itself, then calls $self->refine to decide what kind of statement it
198 # is (PRINT, LET, DATA, etc)
199 # $self->refine creates a LA::Statement::<keyword> object, where <keyword> is the first
200 # keyword in the statement (matches an element in LA::Token->keywordList). <keyword> is
201 # set to the implied LET for a statement beginning with a variable.
202 # This function then returns the blessed reference of the LA::Statement::<keyword> object (a
203 # subclass which inherits from this one)
204 #
205 # Expected arguments
206 # $scriptObj - Blessed reference of the parent LA::Script
207 # $lineObj - Blessed reference of the calling LA::Line
208 # $tokenGroupObj - Blessed reference of the line's LA::TokenGroup
209 #
210 # Optional arguments
211 # $lineNumOk - Set to 'line_num_ok' when called by LA::Statement::if, in situations
212 # like 'IF ... THEN 20' in which case, this statement knows that the
213 # 'THEN 20' part should be parsed as 'THEN GOTO 20'. Otherwise, set to
214 # 'undef'
215 #
216 # Return values
217 # 'undef' on improper arguments, or if the statement can't be parsed at all (i.e. doesn't
218 # begin with a keyword, including an implied LET), or begins with a 'weak' keyword
219 # like STEP (matching a key in LA::Script->weakKeywordHash)
220 # Blessed reference to the newly-created object on success
221  
222 my ($class, $scriptObj, $lineObj, $tokenGroupObj, $lineNumOk, $check) = @_;
223  
224 # Check for improper arguments
225 if (
226 ! defined $class || ! defined $scriptObj || ! defined $lineObj
227 || ! defined $tokenGroupObj || (defined $lineNumOk && $lineNumOk ne 'line_num_ok')
228 || defined $check
229 ) {
230 return $axmud::CLIENT->writeImproper($class . '->new', @_);
231 }
232  
233 # Setup
234 my $self = {
235 _objName => $class, # Name Axbasic objects after their class
236 _objClass => $class,
237 _parentFile => undef, # No parent file object
238 _parentWorld => undef, # No parent file object
239 _privFlag => TRUE, # All IVs are private
240  
241 # Perl object components
242 # ----------------------
243  
244 # The parent LA::Script
245 scriptObj => $scriptObj,
246 # Blessed reference of the calling LA::Line
247 lineObj => $lineObj,
248 # Blessed reference of the line's token group
249 tokenGroupObj => $tokenGroupObj,
250  
251 # IVs
252 # ----
253  
254 # What kind of statement this is (set to <keyword> by the subclass)
255 keyword => undef,
256 # For keywords that are a synonym of another (e.g., SLEEP is a synonym of PAUSE) and for
257 # keywords that share an LA::Statement with another (e.g. ADDCONGAUGE shares code
258 # with ADDGAUGE), the keyword that was actually used when deciding which class of
259 # LA::Statement:: object to use
260 # For all other keywords, $self->keyword is the same as $self->modKeyword
261 modKeyword => undef,
262 # The statement's status: 0 being parsed/implemented, 1 parsed/implemented, 2 parsed but
263 # caused an error
264 status => 0,
265  
266 # Set by LA::Line->parse - blessed reference of the next statement in a single line, to
267 # be executed after this one (e.g. the 'print "hello" : print 'there" ' contains two
268 # statements)
269 nextStatement => undef,
270  
271 # The call to ->parse can sometimes create data which must be stored until the call to
272 # ->implement (if there is one). This data is stored in either of these two variables
273 parseDataList => [],
274 parseDataHash => {},
275  
276 # Defined if this statement is a 'then' statement, so that 'then 20' can be parsed as
277 # 'then goto 20'
278 lineNumOk => $lineNumOk,
279 };
280  
281 bless $self, $class;
282  
283 # Create the subclass object
284 if (! $self->refine()) {
285  
286 return undef;
287 }
288  
289 # Return the subclass object, if it was created
290 return $self;
291 }
292  
293 sub refine {
294  
295 # Called by $self->new to bless a sub-class (see the comments for $self-new)
296 # Reads the keyword the statement starts with - which might be an implied LET - and uses it
297 # to bless the sub-class
298 #
299 # Expected arguments
300 # (none besides $self)
301 #
302 # Return values
303 # 'undef' on improper arguments, or if there is an error
304 # Otherwise returns the blessed reference of the subclass
305  
306 my ($self, $check) = @_;
307  
308 # Local variables
309 my ($token, $subClass, $keyword, $modKeyword);
310  
311 # Check for improper arguments
312 if (defined $check) {
313  
314 return $axmud::CLIENT->writeImproper($self->_objClass . '->refine', @_);
315 }
316  
317 # Get the first token from the statement
318 $token = $self->tokenGroupObj->lookAhead();
319 if (! defined $token) {
320  
321 if (! $self->tokenGroupObj->shortCommentFlag) {
322  
323 return $self->scriptObj->setDebug(
324 'Empty statement error',
325 $self->_objClass . '->refine',
326 );
327  
328 } else {
329  
330 # First token on the line was ! (short comment token). Treat it like a REM
331 # statement
332 $keyword = 'rem';
333 }
334  
335 # If the first token is a recognised Axbasic keyword...
336 } elsif ($token->category eq 'keyword') {
337  
338 # Check that it's not a weak keyword like STEP which isn't allowed to begin a statement
339 if ($self->scriptObj->ivExists('weakKeywordHash', $token->tokenText)) {
340  
341 return $self->scriptObj->setError(
342 'statements_cannot_start_with_keyword_STRING',
343 $self->_objClass . '->refine',
344 'STRING', $token->tokenText,
345 );
346  
347 } else {
348  
349 # Remove the token containing the keyword from the token group's token list
350 # (->lookAhead has already returned a defined value, so there's no need to check
351 # the return value of ->shiftToken)
352 $self->tokenGroupObj->shiftToken();
353 # Set $keyword to the keyword itself
354 $keyword = $token->tokenText;
355  
356 # Check if this keyword is a synonym of another (e.g., SLEEP is a synonym of PAUSE)
357 # or if the keyword shares an LA::Statement with another (e.g. ADDCONGAUGE
358 # shares code with ADDGAUGE)
359 if ($self->scriptObj->ivExists('equivKeywordHash', $keyword)) {
360  
361 $modKeyword = $self->scriptObj->ivShow('equivKeywordHash', $keyword);
362 }
363 }
364  
365 # If the first token is a comment...
366 } elsif ($token->category eq 'comment') {
367  
368 $keyword = 'rem';
369  
370 # If the first token is an implied 'let' keyword...
371 } elsif ($token->category eq 'identifier') {
372  
373 # Are we allowed to use implied LETs?
374 if (
375 $self->scriptObj->ivShow('optionStatementHash', 'nolet')
376 || $self->scriptObj->executionMode eq 'line_num'
377 ) {
378 $keyword = 'let';
379  
380 } else {
381  
382 return $self->scriptObj->setError(
383 'syntax_error',
384 $self->_objClass . '->refine',
385 );
386 }
387  
388 # If we're in a NEXT clause of an IF statement...
389 } elsif (
390 $self->lineNumOk
391 && $token->category eq 'numeric_constant'
392 && $token->tokenText =~ /^\d+$/
393 ) {
394 $keyword = 'goto';
395  
396 } else {
397  
398 # Statement doesn't start with a keyword, comment or variable
399 return $self->scriptObj->setError(
400 'syntax_error',
401 $self->_objClass . '->refine',
402 );
403 }
404  
405 # Decide which sub-class to use
406 if (! $modKeyword) {
407  
408 $modKeyword = $keyword;
409 }
410  
411 $subClass = 'Language::Axbasic::Statement::' . $modKeyword;
412  
413 # Bless the subclass object into existence, replacing the blessed reference of the calling
414 # LA::Statement object (as explained in the comments for $self->new)
415 bless $self, $subClass;
416  
417 # Store the statement type
418 $self->ivPoke('keyword', $keyword);
419 $self->ivPoke('modKeyword', $modKeyword);
420  
421 return $self;
422 }
423  
424 ##################
425 # Methods
426  
427 sub parse {
428  
429 # This generic ->parse function does nothing (it is inherited by LA::Statement::rem which
430 # doesn't have its own ->parse method)
431  
432 my ($self, $check) = @_;
433  
434 # Check for improper arguments
435 if (defined $check) {
436  
437 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
438 }
439  
440 # Do nothing
441 return 1;
442 }
443  
444 sub implement {
445  
446 # This generic ->implement function does nothing (it is inherited by LA::Statement::rem
447 # which doesn't have its own ->parse method)
448  
449 my ($self, $check) = @_;
450  
451 # Check for improper arguments
452 if (defined $check) {
453  
454 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
455 }
456  
457 # Do nothing
458 return 1;
459 }
460  
461 # Functions used by POKE... and PEEK... statements
462  
463 sub parsePeek {
464  
465 # Called by $self->parse for all PEEK... statements (including PEEK itself)
466 #
467 # Expected arguments
468 # (none besides $self)
469 #
470 # Optional arguments
471 # $forceFlag - Set to TRUE for statements like PEEKKEYS, which use an Axbasic array
472 # variable regardless of whether the statement is in the form
473 # 'PEEKKEYS var = string' or 'PEEKKEYS ARRAY var = string'. Set to FALSE
474 # (or 'undef') for all other PEEK... statements
475 # $extraFlag - Set to TRUE for statements like PEEKINDEX, which use an extra argument
476 # at the end of the statement, which must be extracted and stored
477 #
478 # Return values
479 # 'undef' on improper arguments or if there is an error
480 # 1 otherwise
481  
482 my ($self, $forceFlag, $extraFlag, $check) = @_;
483  
484 # Local variables
485 my ($token, $arrayFlag, $varName, $varObj, $expression, $extraExp);
486  
487 # Check for improper arguments
488 if (defined $check) {
489  
490 return $axmud::CLIENT->writeImproper($self->_objClass . '->parsePeek', @_);
491 }
492  
493 # Extract the optional ARRAY keyword
494 $token = $self->tokenGroupObj->shiftMatchingToken('array');
495 if ($token || $forceFlag) {
496 $arrayFlag = TRUE;
497 } else {
498 $arrayFlag = FALSE;
499 }
500  
501 # Extract a token comprising a whole variable identifier (e.g. A, a$, array)
502 $token = $self->tokenGroupObj->shiftTokenIfCategory('identifier');
503 if (! defined $token) {
504  
505 return $self->scriptObj->setError(
506 'missing_or_illegal_variable',
507 $self->_objClass . '->parse',
508 );
509  
510 } else {
511  
512 $varName = $token->tokenText;
513  
514 # Look up the LA::Variable. Use the local variable, if it exists. Otherwise use the
515 # global variable, if it exists. Otherwise, create a global variable
516 # (If the user wants to PEEK a Perl list/hash into an Axbasic array that's a local
517 # variable, they can use a DIM LOCAL statement before this one)
518 if (! $arrayFlag) {
519  
520 $self->scriptObj->set_declareMode('peek_scalar');
521 $varObj = Language::Axbasic::Variable->lookup($self->scriptObj, $varName);
522  
523 } else {
524  
525 # If it's an array, ->lookup expects a LA::Expression::Arglist; but we only need to
526 # supply it with a defined value
527 $self->scriptObj->set_declareMode('peek_array');
528 $varObj = Language::Axbasic::Variable->lookup(
529 $self->scriptObj,
530 $varName,
531 'fake_arg_list'
532 );
533 }
534  
535 $self->scriptObj->set_declareMode('default');
536  
537 if (! $varObj) {
538  
539 # This shouldn't happen...
540 return $self->scriptObj->setError(
541 'syntax_error',
542 $self->_objClass . '->parse',
543 );
544 }
545 }
546  
547 # Extract the assignment operator
548 if (! defined $self->tokenGroupObj->shiftTokenIfCategory('assignment_operator')) {
549  
550 return $self->scriptObj->setError(
551 'missing_assignment_operator',
552 $self->_objClass . '->parse',
553 );
554 }
555  
556 # The next token is either an expression representing an Axmud internal variable (a scalar,
557 # e.g. "current.world.name"; an array, e.g. "current.world.statusFormatList"; or a hash,
558 # e.g. "current.world.currencyHash")
559 $token = $self->tokenGroupObj->lookAhead();
560 if (! defined $token) {
561  
562 return $self->scriptObj->setError(
563 'syntax_error',
564 $self->_objClass . '->parse',
565 );
566  
567 } else {
568  
569 $expression = Language::Axbasic::Expression::Arithmetic->new(
570 $self->scriptObj,
571 $self->tokenGroupObj,
572 );
573  
574 if (! defined $expression) {
575  
576 return $self->scriptObj->setError(
577 'missing_or_illegal_expression',
578 $self->_objClass . '->parse',
579 );
580 }
581 }
582  
583 # Save the array flag, variable object and expression object so $self->implement can use
584 # them, if it is called
585 $self->ivAdd('parseDataHash', 'array_flag', $arrayFlag);
586 $self->ivAdd('parseDataHash', 'var_name', $varName);
587 $self->ivAdd('parseDataHash', 'expression', $expression);
588  
589 if ($extraFlag) {
590  
591 # This statement uses further, which must be extracted
592 # Extract the comma
593 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
594  
595 return $self->scriptObj->setError(
596 'syntax_error',
597 $self->_objClass . '->parse',
598 );
599 }
600  
601 # Extract the extra expression
602 $token = $self->tokenGroupObj->lookAhead();
603 if (! defined $token) {
604  
605 return $self->scriptObj->setError(
606 'syntax_error',
607 $self->_objClass . '->parse',
608 );
609  
610 } else {
611  
612 $extraExp = Language::Axbasic::Expression::Arithmetic->new(
613 $self->scriptObj,
614 $self->tokenGroupObj,
615 );
616  
617 if (! defined $extraExp) {
618  
619 return $self->scriptObj->setError(
620 'missing_or_illegal_expression',
621 $self->_objClass . '->parse',
622 );
623 }
624 }
625  
626 # Save the extra expression object so $self->implement can use it, if it is called
627 $self->ivAdd('parseDataHash', 'extra_exp', $extraExp);
628 }
629  
630 # There should be nothing after the expression
631 if (defined $self->tokenGroupObj->lookAhead()) {
632  
633 return $self->scriptObj->setError(
634 'unexpected_keywords,_operators_or_expressions',
635 $self->_objClass . '->parse',
636 );
637 }
638  
639 # Initial parsing complete
640 return 1;
641 }
642  
643 sub parsePoke {
644  
645 # Called by $self->parse for many POKE... statements (but not POKE itself)
646 #
647 # Expected arguments
648 # (none besides $self)
649 #
650 # Optional arguments
651 # $number - The number of expressions to extract, after the first (compulsory) one. An
652 # integer, 0 or above (or 'undef' to extract no optional expressions)
653 # $max - The maximum number or expressions to extract, after the first (compulsory)
654 # one. If defined, $number must be defined too, and $number represents
655 # the minimum. Set to 'undef' if the maximum number is the same as the
656 # minimum (or if no optional expressions are to be extracted)
657 #
658 # Return values
659 # 'undef' on improper arguments or if there is an error
660 # 1 otherwise
661  
662 my ($self, $number, $max, $check) = @_;
663  
664 # Local variables
665 my (
666 $token, $varExp,
667 @expList,
668 );
669  
670 # Check for improper arguments
671 if (defined $check) {
672  
673 return $axmud::CLIENT->writeImproper($self->_objClass . '->parsePoke', @_);
674 }
675  
676 # The first token is either an expression representing an Axmud internal variable (a scalar,
677 # e.g. "current.world.name"; an array, e.g. "current.world.statusFormatList"; or a hash,
678 # e.g. "current.world.currencyHash")
679 $token = $self->tokenGroupObj->lookAhead();
680 if (! defined $token) {
681  
682 return $self->scriptObj->setError(
683 'syntax_error',
684 $self->_objClass . '->parse',
685 );
686  
687 } else {
688  
689 $varExp = Language::Axbasic::Expression::Arithmetic->new(
690 $self->scriptObj,
691 $self->tokenGroupObj,
692 );
693  
694 if (! defined $varExp) {
695  
696 return $self->scriptObj->setError(
697 'missing_or_illegal_expression',
698 $self->_objClass . '->parse',
699 );
700 }
701 }
702  
703 # (Extract expressions, even if the minimum is 0 and the maximum is 1)
704 if ($number || $max) {
705  
706 if (! defined $max) {
707  
708 # Minimum and maximum number of expressions is the same
709 $max = $number;
710  
711 } elsif ($number > $max) {
712  
713 # Emergency failsafe to prevent infinite loops
714 $number = $max;
715 }
716  
717 # Extract expressions until there are none left
718 OUTER: for (my $count = 1; $count <= $max; $count++) {
719  
720 my $expression;
721  
722 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
723  
724 if ($count > $number) {
725  
726 # We have at least the minimum number of expressions we need
727 last OUTER;
728  
729 } else {
730  
731 return $self->scriptObj->setError(
732 'syntax error',
733 $self->_objClass . '->parse',
734 );
735 }
736 }
737  
738 $expression = Language::Axbasic::Expression::Arithmetic->new(
739 $self->scriptObj,
740 $self->tokenGroupObj,
741 );
742  
743 if (! defined $expression) {
744  
745 return $self->scriptObj->setError(
746 'missing_or_illegal_expression',
747 $self->_objClass . '->parse',
748 );
749  
750 } else {
751  
752 push (@expList, $expression);
753 }
754 }
755 }
756  
757 # There are no further expressions to extract
758 if (! $self->tokenGroupObj->testStatementEnd()) {
759  
760 return $self->scriptObj->setError(
761 'unexpected_keywords,_operators_or_expressions',
762 $self->_objClass . '->parse',
763 );
764 }
765  
766 # Save the expressions so $self->implement can use them, if it is called
767 $self->ivAdd('parseDataHash', 'var_exp', $varExp);
768 $self->ivPoke('parseDataList', @expList);
769  
770 # Initial parsing complete
771 return 1;
772 }
773  
774 sub fetchVar {
775  
776 # Called by $self->parse for most PEEK... statements (including PEEK itself)
777 # Looks up an Axbasic scalar variable or array, calling $self->scriptObj->setError if the
778 # variable can't be found
779 #
780 # Expected arguments
781 # $statement - The statement keyword, e.g. 'PEEK'
782 # $varName - The name of the variable, e.g. 'var$'
783 #
784 # Optional arguments
785 # $arrayFlag - Flag set to TRUE if the ARRAY keyword was also used (e.g. PEEK ARRAY); set
786 # to FALSE (or 'undef') if not
787 #
788 # Return values
789 # 'undef' on improper arguments or the variable can't be found
790 # Otherwise, returns the LA::Variable object
791  
792 my ($self, $statement, $varName, $arrayFlag, $check) = @_;
793  
794 # Local variables
795 my $varObj;
796  
797 # Check for improper arguments
798 if (! defined $statement || ! defined $varName || defined $check) {
799  
800 return $axmud::CLIENT->writeImproper($self->_objClass . '->fetchVar', @_);
801 }
802  
803 # Look up the LA::Variable
804 if (! $arrayFlag) {
805  
806 $varObj = Language::Axbasic::Variable->lookup($self->scriptObj, $varName);
807  
808 } else {
809  
810 # If it's an array, ->lookup expects a LA::Expression::Arglist; but we only need to
811 # supply it with a defined value
812 $varObj = Language::Axbasic::Variable->lookup(
813 $self->scriptObj,
814 $varName,
815 'fake_arg_list'
816 );
817 }
818  
819 if (! $varObj) {
820  
821 # This shouldn't happen...
822 return $self->scriptObj->setError(
823 $statement . '_operation_failure',
824 $self->_objClass . '->implement',
825 );
826  
827 } else {
828  
829 return $varObj;
830 }
831 }
832  
833 sub importAsScalar {
834  
835 # Called by $self->parse for all PEEK... statements (including PEEK itself)
836 # Sets the value of an Axbasic scalar variable, converting Perl 'undef' to an Axbasic string
837 # or numeric value, as required
838 #
839 # Expected arguments
840 # $varObj - A LA::Variable::Array object
841 #
842 # Optional arguments
843 # $scalar - A value to store in the Axbasic scalar variable (may be 'undef')
844  
845 my ($self, $varObj, $scalar) = @_;
846  
847 # Check for improper arguments
848 if (! defined $varObj) {
849  
850 return $axmud::CLIENT->writeImproper($self->_objClass . '->importAsScalar', @_);
851 }
852  
853 # Perl 'undef' values are converted to Axbasic strings "<<undef>>" or the number 0
854 if (defined $scalar) {
855 $varObj->set($scalar);
856 } elsif (ref($varObj) =~ m/Numeric/) {
857 $varObj->set(0);
858 } else {
859 $varObj->set('<<undef>>');
860 }
861  
862 # Do nothing
863 return 1;
864 }
865  
866 sub importAsArray {
867  
868 # Called by $self->parse for all PEEK... statements (including PEEK itself)
869 # Replaces the contents of an Axbasic array variable with a Perl list, redimensioning the
870 # array as required
871 #
872 # Expected arguments
873 # $varObj - A LA::Variable::Array object
874 #
875 # Optional arguments
876 # @array - A list of values to put into the Axbasic array (can be an empty list)
877  
878 my ($self, $varObj, @array) = @_;
879  
880 # Local variables
881 my (
882 $count,
883 @cellList,
884 );
885  
886 # Check for improper arguments
887 if (! defined $varObj) {
888  
889 return $axmud::CLIENT->writeImproper($self->_objClass . '->importAsArray', @_);
890 }
891  
892 # Re-dimension the array to match the size of @array (and to make sure it has only one
893 # dimension)
894 $varObj->dimension(0, (scalar @array) - 1);
895  
896 # Set each variable in the Axbasic array to match the values of the elements in the Axmud
897 # list/hash
898 @cellList = $varObj->cellList;
899 # The first item in LA::Variable::Array->cellList is the lower bound, which we already
900 # know is 0 (so we can dispense with it)
901 shift @cellList;
902 # (But the first element of @array that we want is, of course, element 0)
903 $count = -1;
904  
905 foreach my $arrayVar (@cellList) {
906  
907 $count++;
908  
909 # Perl 'undef' values are converted to Axbasic strings "<<undef>>" or the number 0
910 if (defined $array[$count]) {
911 $arrayVar->set($array[$count]);
912 } elsif (ref($varObj) =~ m/Numeric/) {
913 $arrayVar->set(0);
914 } else {
915 $arrayVar->set("<<undef>>");
916 }
917 }
918  
919 # Do nothing
920 return 1;
921 }
922  
923 # Functions used by SETTRIG, etc statements
924  
925 sub parseSetInterface {
926  
927 # Called by $self->parse for the SETTRIG, SETALIAS, SETMACRO, SETTIMER and SETHOOK
928 # statements
929 #
930 # Expected arguments
931 # (none besides $self)
932 #
933 # Return values
934 # 'undef' on improper arguments or if there is an error
935 # 1 otherwise
936  
937 my ($self, $check) = @_;
938  
939 # Local variables
940 my ($stimulusExp, $newScriptExp, $token);
941  
942 # Check for improper arguments
943 if (defined $check) {
944  
945 return $axmud::CLIENT->writeImproper($self->_objClass . '->parseSetInterface', @_);
946 }
947  
948 # Convert the stimulus string into an expression
949 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
950 $self->scriptObj,
951 $self->tokenGroupObj,
952 );
953  
954 if (! defined $stimulusExp) {
955  
956 return $self->scriptObj->setError(
957 'missing_or_illegal_expression',
958 $self->_objClass . '->parse',
959 );
960 }
961  
962 # Get the new script name, if specified
963 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
964  
965 $token = $self->tokenGroupObj->lookAhead();
966 if (defined $token) {
967  
968 $newScriptExp = Language::Axbasic::Expression::Arithmetic->new(
969 $self->scriptObj,
970 $self->tokenGroupObj,
971 );
972  
973 if (! defined $newScriptExp) {
974  
975 return $self->scriptObj->setError(
976 'missing_or_illegal_expression',
977 $self->_objClass . '->parse',
978 );
979 }
980 }
981 }
982  
983 # Check that nothing follows the expression(s)
984 if (! $self->tokenGroupObj->testStatementEnd()) {
985  
986 return $self->scriptObj->setError(
987 'unexpected_keywords,_operators_or_expressions',
988 $self->_objClass . '->parse',
989 );
990 }
991  
992 # Store the expression(s), so $self->implement can retrieve them
993 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
994 $self->ivAdd('parseDataHash', 'new_script', $newScriptExp);
995  
996 # Parsing complete
997 return 1;
998 }
999  
1000 # Functions used by WAITTRIG, etc statements
1001  
1002 sub parseWaitInterface {
1003  
1004 # Called by LA::Statement::waittrig->parse (and also by WAITALIAS, WAITMACRO, WAITTIMER and
1005 # WAITHOOK ->parse functions)
1006 #
1007 # Expected arguments
1008 # (none besides $self)
1009 #
1010 # Return values
1011 # 'undef' on improper arguments or if there is an error
1012 # 1 otherwise
1013  
1014 my ($self, $check) = @_;
1015  
1016 # Local variables
1017 my ($stimulusExp, $timeoutExp);
1018  
1019 # Check for improper arguments
1020 if (defined $check) {
1021  
1022 return $axmud::CLIENT->writeImproper($self->_objClass . '->parseWaitInterface', @_);
1023 }
1024  
1025 # Convert the pattern string into an expression
1026 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1027 $self->scriptObj,
1028 $self->tokenGroupObj,
1029 );
1030  
1031 if (! defined $stimulusExp) {
1032  
1033 return $self->scriptObj->setError(
1034 'missing_or_illegal_expression',
1035 $self->_objClass . '->parse',
1036 );
1037 }
1038  
1039 # Get the timeout, if specified, and convert it into an expression
1040 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1041  
1042 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
1043 $self->scriptObj,
1044 $self->tokenGroupObj,
1045 );
1046  
1047 if (! defined $timeoutExp) {
1048  
1049 return $self->scriptObj->setError(
1050 'missing_or_illegal_expression',
1051 $self->_objClass . '->parse',
1052 );
1053 }
1054 }
1055  
1056 # Check that nothing follows the expression(s)
1057 if (! $self->tokenGroupObj->testStatementEnd()) {
1058  
1059 return $self->scriptObj->setError(
1060 'unexpected_keywords,_operators_or_expressions',
1061 $self->_objClass . '->parse',
1062 );
1063 }
1064  
1065 # Store the expression(s), so $self->implement can retrieve them
1066 $self->ivAdd('parseDataHash', 'pattern', $stimulusExp);
1067 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
1068  
1069 # Parsing complete
1070 return 1;
1071 }
1072  
1073 sub implementWaitInterface {
1074  
1075 # Called by LA::Statement::waittrig->implement (and also by WAITALIAS, WAITMACRO, WAITTIMER
1076 # and WAITHOOK ->implement functions)
1077 #
1078 # Expected arguments
1079 # $interfaceType - 'trigger', 'alias', 'macro', 'timer or 'hook'
1080 #
1081 # Return values
1082 # 'undef' on improper arguments or if there is an error
1083 # 1 otherwise
1084  
1085 my ($self, $interfaceType, $check) = @_;
1086  
1087 # Local variables
1088 my ($stimulusExp, $stimulus, $timeoutExp, $timeout, $interfaceObj);
1089  
1090 # Check for improper arguments
1091 if (! defined $interfaceType || defined $check) {
1092  
1093 return $axmud::CLIENT->writeImproper($self->_objClass . '->implementWaitInterface', @_);
1094 }
1095  
1096 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
1097 if (! $self->scriptObj->parentTask) {
1098  
1099 # Implementation complete. Execution resumes from the next statement
1100 return 1;
1101 }
1102  
1103 # Otherwise, retrieve the argument(s) stored by $self->parse
1104 $stimulusExp = $self->ivShow('parseDataHash', 'pattern');
1105 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
1106  
1107 # Evaluate the expression(s)
1108 $stimulus = $stimulusExp->evaluate();
1109  
1110 if (defined $timeoutExp) {
1111  
1112 $timeout = $timeoutExp->evaluate();
1113  
1114 if (! ($timeout =~ /^\d+$/)) {
1115  
1116 return $self->scriptObj->setError(
1117 'invalid_integer',
1118 $self->_objClass . '->implement',
1119 );
1120  
1121 } elsif ($timeout < 1) {
1122  
1123 return $self->scriptObj->setError(
1124 'number_NUM_out_of_range',
1125 $self->_objClass . '->implement',
1126 'NUM', $timeout,
1127 );
1128 }
1129 }
1130  
1131 # Create the interface, which will call a function in this script's parent task when it
1132 # fires
1133 $interfaceObj = $self->scriptObj->session->createDependentInterface(
1134 $interfaceType,
1135 $stimulus,
1136 $self->scriptObj->parentTask,
1137 'interfaceWaitSeen',
1138 'temporary',
1139 1,
1140 );
1141  
1142 if (defined $interfaceObj) {
1143  
1144 # Add this interface to the list of interfaces created during the execution of the
1145 # Axbasic script
1146 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
1147 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
1148  
1149 # Mark this script as paused
1150 $self->scriptObj->set_scriptStatus('paused');
1151 # Tell the task that it's waiting for an interface, so that the interface can be
1152 # deleted, the first time it fires...
1153 $self->scriptObj->parentTask->ivPoke('waitForInterface', $interfaceObj->name);
1154 # ...and then begin the pause
1155 if (defined $timeoutExp) {
1156  
1157 $self->scriptObj->parentTask->pauseUntil(
1158 ($self->scriptObj->session->sessionTime + $timeout),
1159 );
1160  
1161 } else {
1162  
1163 $self->scriptObj->parentTask->pauseUntil();
1164 }
1165  
1166 } else {
1167  
1168 # Store the fact that creation of the interface failed
1169 $self->scriptObj->set_depInterfaceName(undef);
1170 }
1171  
1172 # Implementation complete
1173 return 1;
1174 }
1175  
1176 ##################
1177 # Accessors - set
1178  
1179 sub set_nextStatement {
1180  
1181 # Returns 'undef' on improper arguments
1182 # Returns 1 on success
1183  
1184 my ($self, $obj, $check) = @_;
1185  
1186 # Check for improper arguments
1187 if (defined $check) {
1188  
1189 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_nextStatement', @_);
1190 }
1191  
1192 # Update IVs
1193 $self->ivPoke('nextStatement', $obj);
1194  
1195 return 1;
1196 }
1197  
1198 sub add_parseDataHash {
1199  
1200 # Returns 'undef' on improper arguments
1201 # Returns 1 on success
1202  
1203 my ($self, $string, $obj, $check) = @_;
1204  
1205 # Check for improper arguments
1206 if (! defined $string || ! defined $obj || defined $check) {
1207  
1208 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_parseDataHash', @_);
1209 }
1210  
1211 # Update IVs
1212 $self->ivAdd('parseDataHash', $string, $obj);
1213  
1214 return 1;
1215 }
1216  
1217 sub push_parseDataList {
1218  
1219 # Returns 'undef' on improper arguments
1220 # Returns 1 on success
1221  
1222 my ($self, $obj, $check) = @_;
1223  
1224 # Check for improper arguments
1225 if (! defined $obj || defined $check) {
1226  
1227 return $axmud::CLIENT->writeImproper($self->_objClass . '->push_parseDataList', @_);
1228 }
1229  
1230 # Update IVs
1231 $self->ivPush('parseDataList', $obj);
1232  
1233 return 1;
1234 }
1235  
1236 ##################
1237 # Accessors - get
1238  
1239 sub scriptObj
1240 { $_[0]->{scriptObj} }
1241 sub lineObj
1242 { $_[0]->{lineObj} }
1243 sub tokenGroupObj
1244 { $_[0]->{tokenGroupObj} }
1245  
1246 sub keyword
1247 { $_[0]->{keyword} }
1248 sub modKeyword
1249 { $_[0]->{modKeyword} }
1250 sub status
1251 { $_[0]->{status} }
1252  
1253 sub nextStatement
1254 { $_[0]->{nextStatement} }
1255  
1256 sub parseDataList
1257 { my $self = shift; return @{$self->{parseDataList}}; }
1258 sub parseDataHash
1259 { my $self = shift; return %{$self->{parseDataHash}}; }
1260  
1261 sub lineNumOk
1262 { $_[0]->{lineNumOk} }
1263 }
1264  
1265 { package Language::Axbasic::Statement::addalias;
1266  
1267 use strict;
1268 use warnings;
1269 use diagnostics;
1270  
1271 use Glib qw(TRUE FALSE);
1272  
1273 @Language::Axbasic::Statement::addalias::ISA = qw(
1274 Language::Axbasic
1275 Language::Axbasic::Statement
1276 );
1277  
1278 # ADDALIAS expression , expression [ , expression ]
1279  
1280 ##################
1281 # Methods
1282  
1283 sub parse {
1284  
1285 # Called by LA::Line->parse directly after a call to LA::Statement->new
1286 #
1287 # Expected arguments
1288 # (none besides $self)
1289 #
1290 # Return values
1291 # 'undef' on improper arguments or if there is an error
1292 # 1 otherwise
1293  
1294 my ($self, $check) = @_;
1295  
1296 # Local variables
1297 my ($stimulusExp, $responseExp, $nameExp, $token);
1298  
1299 # Check for improper arguments
1300 if (defined $check) {
1301  
1302 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1303 }
1304  
1305 # Convert the stimulus and response strings into expressions
1306 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1307 $self->scriptObj,
1308 $self->tokenGroupObj,
1309 );
1310  
1311 if (! defined $stimulusExp) {
1312  
1313 return $self->scriptObj->setError(
1314 'missing_or_illegal_expression',
1315 $self->_objClass . '->parse',
1316 );
1317 }
1318  
1319 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1320  
1321 return $self->scriptObj->setError(
1322 'syntax_error',
1323 $self->_objClass . '->parse',
1324 );
1325 }
1326  
1327 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
1328 $self->scriptObj,
1329 $self->tokenGroupObj,
1330 );
1331  
1332 if (! defined $responseExp) {
1333  
1334 return $self->scriptObj->setError(
1335 'missing_or_illegal_expression',
1336 $self->_objClass . '->parse',
1337 );
1338 }
1339  
1340 # Get the alias name, if specified
1341 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1342  
1343 $token = $self->tokenGroupObj->lookAhead();
1344 if (defined $token) {
1345  
1346 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
1347 $self->scriptObj,
1348 $self->tokenGroupObj,
1349 );
1350  
1351 if (! defined $nameExp) {
1352  
1353 return $self->scriptObj->setError(
1354 'missing_or_illegal_expression',
1355 $self->_objClass . '->parse',
1356 );
1357 }
1358 }
1359 }
1360  
1361 # Check that nothing follows the expressions
1362 if (! $self->tokenGroupObj->testStatementEnd()) {
1363  
1364 return $self->scriptObj->setError(
1365 'unexpected_keywords,_operators_or_expressions',
1366 $self->_objClass . '->parse',
1367 );
1368 }
1369  
1370 # Store the expressions, so $self->implement can retrieve them
1371 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
1372 $self->ivAdd('parseDataHash', 'response', $responseExp);
1373 # (If the third expession wasn't specified, $name will be 'undef'
1374 $self->ivAdd('parseDataHash', 'name', $nameExp);
1375  
1376 # Parsing complete
1377 return 1;
1378 }
1379  
1380 sub implement {
1381  
1382 # Called by LA::Line->implement directly after a call to $self->parse
1383 #
1384 # Expected arguments
1385 # (none besides $self)
1386 #
1387 # Return values
1388 # 'undef' on improper arguments or if there is an error
1389 # 1 otherwise
1390  
1391 my ($self, $check) = @_;
1392  
1393 # Local variables
1394 my (
1395 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
1396 );
1397  
1398 # Check for improper arguments
1399 if (defined $check) {
1400  
1401 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1402 }
1403  
1404 # Retrieve the arguments stored by $self->parse
1405 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
1406 $responseExp = $self->ivShow('parseDataHash', 'response');
1407 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
1408  
1409 # Evaluate each expression
1410 $stimulus = $stimulusExp->evaluate();
1411 $response = $responseExp->evaluate();
1412 if (defined $nameExp) {
1413  
1414 $name = $nameExp->evaluate();
1415 }
1416  
1417 # Specify which profile to use
1418 if (defined $self->scriptObj->useProfile) {
1419 $profile = $self->scriptObj->useProfile;
1420 } else {
1421 $profile = $self->scriptObj->session->currentWorld->name;
1422 }
1423  
1424 # Prepare the client command
1425 $string = 'addalias -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
1426 if ($name) {
1427  
1428 $string .= ' -n <' . $name . '>';
1429 }
1430  
1431 # Send the command
1432 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
1433  
1434 # Alias created successfully. Update the LA::Script IVs
1435 if (! $name) {
1436  
1437 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
1438 # specified
1439 $name = $stimulus;
1440 }
1441  
1442 $self->scriptObj->push_indepInterfaceList($name, $profile, 'alias');
1443 $self->scriptObj->set_indepInterfaceName($name);
1444  
1445 } else {
1446  
1447 # Store the fact that creation of the alias failed
1448 $self->scriptObj->set_indepInterfaceName(undef);
1449 }
1450  
1451 # Implementation complete
1452 return 1;
1453 }
1454 }
1455  
1456 { package Language::Axbasic::Statement::addgauge;
1457  
1458 use strict;
1459 use warnings;
1460 use diagnostics;
1461  
1462 use Glib qw(TRUE FALSE);
1463  
1464 @Language::Axbasic::Statement::addgauge::ISA = qw(
1465 Language::Axbasic
1466 Language::Axbasic::Statement
1467 );
1468  
1469 # ADDGAUGE expression , expression [ , expression ] [ , expression ] [ , expression ]
1470 # ADDCONGAUGE expression , expression [ , expression ] [ , expression ] [ , expression ]
1471  
1472 ##################
1473 # Methods
1474  
1475 sub parse {
1476  
1477 # Called by LA::Line->parse directly after a call to LA::Statement->new
1478 #
1479 # Expected arguments
1480 # (none besides $self)
1481 #
1482 # Return values
1483 # 'undef' on improper arguments or if there is an error
1484 # 1 otherwise
1485  
1486 my ($self, $check) = @_;
1487  
1488 # Local variables
1489 my ($numberExp, $labelExp, $fullColExp, $emptyColExp, $labelColExp, $token);
1490  
1491 # Check for improper arguments
1492 if (defined $check) {
1493  
1494 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1495 }
1496  
1497 # Convert the compulsory arguments into expressions
1498 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
1499 $self->scriptObj,
1500 $self->tokenGroupObj,
1501 );
1502  
1503 if (! defined $numberExp) {
1504  
1505 return $self->scriptObj->setError(
1506 'missing_or_illegal_expression',
1507 $self->_objClass . '->parse',
1508 );
1509 }
1510  
1511 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1512  
1513 return $self->scriptObj->setError(
1514 'syntax_error',
1515 $self->_objClass . '->parse',
1516 );
1517 }
1518  
1519 $labelExp = Language::Axbasic::Expression::Arithmetic->new(
1520 $self->scriptObj,
1521 $self->tokenGroupObj,
1522 );
1523  
1524 if (! defined $labelExp) {
1525  
1526 return $self->scriptObj->setError(
1527 'missing_or_illegal_expression',
1528 $self->_objClass . '->parse',
1529 );
1530 }
1531  
1532 # Get the optional arguments, if specified
1533 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1534  
1535 $token = $self->tokenGroupObj->lookAhead();
1536 if (defined $token) {
1537  
1538 $fullColExp = Language::Axbasic::Expression::Arithmetic->new(
1539 $self->scriptObj,
1540 $self->tokenGroupObj,
1541 );
1542  
1543 if (! defined $fullColExp) {
1544  
1545 return $self->scriptObj->setError(
1546 'missing_or_illegal_expression',
1547 $self->_objClass . '->parse',
1548 );
1549 }
1550 }
1551 }
1552  
1553 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1554  
1555 $token = $self->tokenGroupObj->lookAhead();
1556 if (defined $token) {
1557  
1558 $emptyColExp = Language::Axbasic::Expression::Arithmetic->new(
1559 $self->scriptObj,
1560 $self->tokenGroupObj,
1561 );
1562  
1563 if (! defined $emptyColExp) {
1564  
1565 return $self->scriptObj->setError(
1566 'missing_or_illegal_expression',
1567 $self->_objClass . '->parse',
1568 );
1569 }
1570 }
1571 }
1572  
1573 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1574  
1575 $token = $self->tokenGroupObj->lookAhead();
1576 if (defined $token) {
1577  
1578 $labelColExp = Language::Axbasic::Expression::Arithmetic->new(
1579 $self->scriptObj,
1580 $self->tokenGroupObj,
1581 );
1582  
1583 if (! defined $labelColExp) {
1584  
1585 return $self->scriptObj->setError(
1586 'missing_or_illegal_expression',
1587 $self->_objClass . '->parse',
1588 );
1589 }
1590 }
1591 }
1592  
1593 # Check that nothing follows the expressions
1594 if (! $self->tokenGroupObj->testStatementEnd()) {
1595  
1596 return $self->scriptObj->setError(
1597 'unexpected_keywords,_operators_or_expressions',
1598 $self->_objClass . '->parse',
1599 );
1600 }
1601  
1602 # Store the expressions, so $self->implement can retrieve them
1603 $self->ivAdd('parseDataHash', 'number', $numberExp);
1604 $self->ivAdd('parseDataHash', 'label', $labelExp);
1605 $self->ivAdd('parseDataHash', 'full_col', $fullColExp); # 'undef' if not specified
1606 $self->ivAdd('parseDataHash', 'empty_col', $emptyColExp); # 'undef' if not specified
1607 $self->ivAdd('parseDataHash', 'label_col', $labelColExp); # 'undef' if not specified
1608  
1609 # Parsing complete
1610 return 1;
1611 }
1612  
1613 sub implement {
1614  
1615 # Called by LA::Line->implement directly after a call to $self->parse
1616 #
1617 # Expected arguments
1618 # (none besides $self)
1619 #
1620 # Return values
1621 # 'undef' on improper arguments or if there is an error
1622 # 1 otherwise
1623  
1624 my ($self, $check) = @_;
1625  
1626 # Local variables
1627 my (
1628 $numberExp, $labelExp, $fullColExp, $emptyColExp, $labelColExp, $number, $label,
1629 $fullCol, $emptyCol, $labelCol, $addFlag,
1630 );
1631  
1632 # Check for improper arguments
1633 if (defined $check) {
1634  
1635 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1636 }
1637  
1638 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
1639 if (! $self->scriptObj->parentTask) {
1640  
1641 # Implementation complete. Execution resumes from the next statement
1642 return 1;
1643 }
1644  
1645 # Retrieve the arguments stored by $self->parse
1646 $numberExp = $self->ivShow('parseDataHash', 'number');
1647 $labelExp = $self->ivShow('parseDataHash', 'label');
1648 $fullColExp = $self->ivShow('parseDataHash', 'full_col'); # May be 'undef'
1649 $emptyColExp = $self->ivShow('parseDataHash', 'empty_col'); # May be 'undef'
1650 $labelColExp = $self->ivShow('parseDataHash', 'label_col'); # May be 'undef'
1651  
1652 # Evaluate each expression
1653 $number = $numberExp->evaluate();
1654 $label = $labelExp->evaluate();
1655 if (defined $fullColExp) {
1656  
1657 $fullCol = $fullColExp->evaluate();
1658 }
1659  
1660 if (defined $emptyColExp) {
1661  
1662 $emptyCol = $emptyColExp->evaluate();
1663 }
1664  
1665 if (defined $labelColExp) {
1666  
1667 $labelCol = $labelColExp->evaluate();
1668 }
1669  
1670 # Check that the gauge number and label are valid. $number must be an integer, >= 0
1671 if ($number =~ m/\D/ || $number < 0) {
1672  
1673 return $self->scriptObj->setError(
1674 'invalid_gauge_number',
1675 $self->_objClass . '->implement',
1676 );
1677 }
1678  
1679 # Tell the Script task to add the gauge
1680 if ($self->keyword eq 'addcongauge') {
1681 $addFlag = TRUE;
1682 } else {
1683 $addFlag = FALSE;
1684 }
1685  
1686 $self->scriptObj->parentTask->addGauge(
1687 $number,
1688 $label,
1689 $addFlag,
1690 $fullCol,
1691 $emptyCol,
1692 $labelCol,
1693 );
1694  
1695 # Implementation complete
1696 return 1;
1697 }
1698 }
1699  
1700 { package Language::Axbasic::Statement::addstatus;
1701  
1702 use strict;
1703 use warnings;
1704 use diagnostics;
1705  
1706 use Glib qw(TRUE FALSE);
1707  
1708 @Language::Axbasic::Statement::addstatus::ISA = qw(
1709 Language::Axbasic
1710 Language::Axbasic::Statement
1711 );
1712  
1713 # ADDSTATUS expression , expression
1714 # ADDCONSTATUS expression , expression
1715  
1716 ##################
1717 # Methods
1718  
1719 sub parse {
1720  
1721 # Called by LA::Line->parse directly after a call to LA::Statement->new
1722 #
1723 # Expected arguments
1724 # (none besides $self)
1725 #
1726 # Return values
1727 # 'undef' on improper arguments or if there is an error
1728 # 1 otherwise
1729  
1730 my ($self, $check) = @_;
1731  
1732 # Local variables
1733 my ($numberExp, $labelExp, $token);
1734  
1735 # Check for improper arguments
1736 if (defined $check) {
1737  
1738 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1739 }
1740  
1741 # Convert the compulsory arguments into expressions
1742 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
1743 $self->scriptObj,
1744 $self->tokenGroupObj,
1745 );
1746  
1747 if (! defined $numberExp) {
1748  
1749 return $self->scriptObj->setError(
1750 'missing_or_illegal_expression',
1751 $self->_objClass . '->parse',
1752 );
1753 }
1754  
1755 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1756  
1757 return $self->scriptObj->setError(
1758 'syntax_error',
1759 $self->_objClass . '->parse',
1760 );
1761 }
1762  
1763 $labelExp = Language::Axbasic::Expression::Arithmetic->new(
1764 $self->scriptObj,
1765 $self->tokenGroupObj,
1766 );
1767  
1768 if (! defined $labelExp) {
1769  
1770 return $self->scriptObj->setError(
1771 'missing_or_illegal_expression',
1772 $self->_objClass . '->parse',
1773 );
1774 }
1775  
1776 # Check that nothing follows the expressions
1777 if (! $self->tokenGroupObj->testStatementEnd()) {
1778  
1779 return $self->scriptObj->setError(
1780 'unexpected_keywords,_operators_or_expressions',
1781 $self->_objClass . '->parse',
1782 );
1783 }
1784  
1785 # Store the expressions, so $self->implement can retrieve them
1786 $self->ivAdd('parseDataHash', 'number', $numberExp);
1787 $self->ivAdd('parseDataHash', 'label', $labelExp);
1788  
1789 # Parsing complete
1790 return 1;
1791 }
1792  
1793 sub implement {
1794  
1795 # Called by LA::Line->implement directly after a call to $self->parse
1796 #
1797 # Expected arguments
1798 # (none besides $self)
1799 #
1800 # Return values
1801 # 'undef' on improper arguments or if there is an error
1802 # 1 otherwise
1803  
1804 my ($self, $check) = @_;
1805  
1806 # Local variables
1807 my ($numberExp, $labelExp, $number, $label, $addFlag);
1808  
1809 # Check for improper arguments
1810 if (defined $check) {
1811  
1812 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1813 }
1814  
1815 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
1816 if (! $self->scriptObj->parentTask) {
1817  
1818 # Implementation complete. Execution resumes from the next statement
1819 return 1;
1820 }
1821  
1822 # Retrieve the arguments stored by $self->parse
1823 $numberExp = $self->ivShow('parseDataHash', 'number');
1824 $labelExp = $self->ivShow('parseDataHash', 'label');
1825  
1826 # Evaluate each expression
1827 $number = $numberExp->evaluate();
1828 $label = $labelExp->evaluate();
1829  
1830 # Check that the status bar number and label are valid. $number must be an integer, >= 0
1831 if ($number =~ m/\D/ || $number < 0) {
1832  
1833 return $self->scriptObj->setError(
1834 'invalid_status_bar_number',
1835 $self->_objClass . '->implement',
1836 );
1837 }
1838  
1839 # Tell the Script task to add the status bar
1840 if ($self->keyword eq 'addconstatus') {
1841 $addFlag = TRUE;
1842 } else {
1843 $addFlag = FALSE;
1844 }
1845  
1846 $self->scriptObj->parentTask->addStatusBar(
1847 $number,
1848 $label,
1849 $addFlag,
1850 );
1851  
1852 # Implementation complete
1853 return 1;
1854 }
1855 }
1856  
1857 { package Language::Axbasic::Statement::addhook;
1858  
1859 use strict;
1860 use warnings;
1861 use diagnostics;
1862  
1863 use Glib qw(TRUE FALSE);
1864  
1865 @Language::Axbasic::Statement::addhook::ISA = qw(
1866 Language::Axbasic
1867 Language::Axbasic::Statement
1868 );
1869  
1870 # ADDHOOK expression , expression [ , expression ]
1871  
1872 ##################
1873 # Methods
1874  
1875 sub parse {
1876  
1877 # Called by LA::Line->parse directly after a call to LA::Statement->new
1878 #
1879 # Expected arguments
1880 # (none besides $self)
1881 #
1882 # Return values
1883 # 'undef' on improper arguments or if there is an error
1884 # 1 otherwise
1885  
1886 my ($self, $check) = @_;
1887  
1888 # Local variables
1889 my ($stimulusExp, $responseExp, $nameExp, $token);
1890  
1891 # Check for improper arguments
1892 if (defined $check) {
1893  
1894 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1895 }
1896  
1897 # Convert the stimulus and response strings into expressions
1898 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1899 $self->scriptObj,
1900 $self->tokenGroupObj,
1901 );
1902  
1903 if (! defined $stimulusExp) {
1904  
1905 return $self->scriptObj->setError(
1906 'missing_or_illegal_expression',
1907 $self->_objClass . '->parse',
1908 );
1909 }
1910  
1911 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1912  
1913 return $self->scriptObj->setError(
1914 'syntax_error',
1915 $self->_objClass . '->parse',
1916 );
1917 }
1918  
1919 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
1920 $self->scriptObj,
1921 $self->tokenGroupObj,
1922 );
1923  
1924 if (! defined $responseExp) {
1925  
1926 return $self->scriptObj->setError(
1927 'missing_or_illegal_expression',
1928 $self->_objClass . '->parse',
1929 );
1930 }
1931  
1932 # Get the hook name, if specified
1933 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1934  
1935 $token = $self->tokenGroupObj->lookAhead();
1936 if (defined $token) {
1937  
1938 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
1939 $self->scriptObj,
1940 $self->tokenGroupObj,
1941 );
1942  
1943 if (! defined $nameExp) {
1944  
1945 return $self->scriptObj->setError(
1946 'missing_or_illegal_expression',
1947 $self->_objClass . '->parse',
1948 );
1949 }
1950 }
1951 }
1952  
1953 # Check that nothing follows the expressions
1954 if (! $self->tokenGroupObj->testStatementEnd()) {
1955  
1956 return $self->scriptObj->setError(
1957 'unexpected_keywords,_operators_or_expressions',
1958 $self->_objClass . '->parse',
1959 );
1960 }
1961  
1962 # Store the expressions, so $self->implement can retrieve them
1963 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
1964 $self->ivAdd('parseDataHash', 'response', $responseExp);
1965 # (If the third expession wasn't specified, $name will be 'undef'
1966 $self->ivAdd('parseDataHash', 'name', $nameExp);
1967  
1968 # Parsing complete
1969 return 1;
1970 }
1971  
1972 sub implement {
1973  
1974 # Called by LA::Line->implement directly after a call to $self->parse
1975 #
1976 # Expected arguments
1977 # (none besides $self)
1978 #
1979 # Return values
1980 # 'undef' on improper arguments or if there is an error
1981 # 1 otherwise
1982  
1983 my ($self, $check) = @_;
1984  
1985 # Local variables
1986 my (
1987 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
1988 );
1989  
1990 # Check for improper arguments
1991 if (defined $check) {
1992  
1993 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1994 }
1995  
1996 # Retrieve the arguments stored by $self->parse
1997 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
1998 $responseExp = $self->ivShow('parseDataHash', 'response');
1999 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2000  
2001 # Evaluate each expression
2002 $stimulus = $stimulusExp->evaluate();
2003 $response = $responseExp->evaluate();
2004 if (defined $nameExp) {
2005  
2006 $name = $nameExp->evaluate();
2007 }
2008  
2009 # Specify which profile to use
2010 if (defined $self->scriptObj->useProfile) {
2011 $profile = $self->scriptObj->useProfile;
2012 } else {
2013 $profile = $self->scriptObj->session->currentWorld->name;
2014 }
2015  
2016 # Prepare the client command
2017 $string = 'addhook -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2018 if ($name) {
2019  
2020 $string .= ' -n <' . $name . '>';
2021 }
2022  
2023 # Send the command
2024 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2025  
2026 # Hook created successfully. Update the LA::Script IVs
2027 if (! $name) {
2028  
2029 # GenericCommand->addHookEtc uses the stimulus as a name, if no name is specified
2030 $name = $stimulus;
2031 }
2032  
2033 $self->scriptObj->push_indepInterfaceList($name, $profile, 'hook');
2034 $self->scriptObj->set_indepInterfaceName($name);
2035  
2036  
2037 } else {
2038  
2039 # Store the fact that creation of the hook failed
2040 $self->scriptObj->set_indepInterfaceName(undef);
2041 }
2042  
2043 # Implementation complete
2044 return 1;
2045 }
2046 }
2047  
2048 { package Language::Axbasic::Statement::addmacro;
2049  
2050 use strict;
2051 use warnings;
2052 use diagnostics;
2053  
2054 use Glib qw(TRUE FALSE);
2055  
2056 @Language::Axbasic::Statement::addmacro::ISA = qw(
2057 Language::Axbasic
2058 Language::Axbasic::Statement
2059 );
2060  
2061 # ADDMACRO expression , expression [ , expression ]
2062  
2063 ##################
2064 # Methods
2065  
2066 sub parse {
2067  
2068 # Called by LA::Line->parse directly after a call to LA::Statement->new
2069 #
2070 # Expected arguments
2071 # (none besides $self)
2072 #
2073 # Return values
2074 # 'undef' on improper arguments or if there is an error
2075 # 1 otherwise
2076  
2077 my ($self, $check) = @_;
2078  
2079 # Local variables
2080 my ($stimulusExp, $responseExp, $nameExp, $token);
2081  
2082 # Check for improper arguments
2083 if (defined $check) {
2084  
2085 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2086 }
2087  
2088 # Convert the stimulus and response strings into expressions
2089 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
2090 $self->scriptObj,
2091 $self->tokenGroupObj,
2092 );
2093  
2094 if (! defined $stimulusExp) {
2095  
2096 return $self->scriptObj->setError(
2097 'missing_or_illegal_expression',
2098 $self->_objClass . '->parse',
2099 );
2100 }
2101  
2102 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2103  
2104 return $self->scriptObj->setError(
2105 'syntax_error',
2106 $self->_objClass . '->parse',
2107 );
2108 }
2109  
2110 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
2111 $self->scriptObj,
2112 $self->tokenGroupObj,
2113 );
2114  
2115 if (! defined $responseExp) {
2116  
2117 return $self->scriptObj->setError(
2118 'missing_or_illegal_expression',
2119 $self->_objClass . '->parse',
2120 );
2121 }
2122  
2123 # Get the macro name, if specified
2124 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2125  
2126 $token = $self->tokenGroupObj->lookAhead();
2127 if (defined $token) {
2128  
2129 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
2130 $self->scriptObj,
2131 $self->tokenGroupObj,
2132 );
2133  
2134 if (! defined $nameExp) {
2135  
2136 return $self->scriptObj->setError(
2137 'missing_or_illegal_expression',
2138 $self->_objClass . '->parse',
2139 );
2140 }
2141 }
2142 }
2143  
2144 # Check that nothing follows the expressions
2145 if (! $self->tokenGroupObj->testStatementEnd()) {
2146  
2147 return $self->scriptObj->setError(
2148 'unexpected_keywords,_operators_or_expressions',
2149 $self->_objClass . '->parse',
2150 );
2151 }
2152  
2153 # Store the expressions, so $self->implement can retrieve them
2154 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
2155 $self->ivAdd('parseDataHash', 'response', $responseExp);
2156 # (If the third expession wasn't specified, $name will be 'undef'
2157 $self->ivAdd('parseDataHash', 'name', $nameExp);
2158  
2159 # Parsing complete
2160 return 1;
2161 }
2162  
2163 sub implement {
2164  
2165 # Called by LA::Line->implement directly after a call to $self->parse
2166 #
2167 # Expected arguments
2168 # (none besides $self)
2169 #
2170 # Return values
2171 # 'undef' on improper arguments or if there is an error
2172 # 1 otherwise
2173  
2174 my ($self, $check) = @_;
2175  
2176 # Local variables
2177 my (
2178 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
2179 );
2180  
2181 # Check for improper arguments
2182 if (defined $check) {
2183  
2184 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2185 }
2186  
2187 # Retrieve the arguments stored by $self->parse
2188 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
2189 $responseExp = $self->ivShow('parseDataHash', 'response');
2190 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2191  
2192 # Evaluate each expression
2193 $stimulus = $stimulusExp->evaluate();
2194 $response = $responseExp->evaluate();
2195 if (defined $nameExp) {
2196  
2197 $name = $nameExp->evaluate();
2198 }
2199  
2200 # Specify which profile to use
2201 if (defined $self->scriptObj->useProfile) {
2202 $profile = $self->scriptObj->useProfile;
2203 } else {
2204 $profile = $self->scriptObj->session->currentWorld->name;
2205 }
2206  
2207 # Prepare the client command
2208 $string = 'addmacro -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2209 if ($name) {
2210  
2211 $string .= ' -n <' . $name . '>';
2212 }
2213  
2214 # Send the command
2215 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2216  
2217 # Macro created successfully. Update the LA::Script IVs
2218 if (! $name) {
2219  
2220 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
2221 # specified
2222 $name = $stimulus;
2223 }
2224  
2225 $self->scriptObj->push_indepInterfaceList($name, $profile, 'macro');
2226 $self->scriptObj->set_indepInterfaceName($name);
2227  
2228 } else {
2229  
2230 # Store the fact that creation of the macro failed
2231 $self->scriptObj->set_indepInterfaceName(undef);
2232 }
2233  
2234 # Implementation complete
2235 return 1;
2236 }
2237 }
2238  
2239 { package Language::Axbasic::Statement::addtimer;
2240  
2241 use strict;
2242 use warnings;
2243 use diagnostics;
2244  
2245 use Glib qw(TRUE FALSE);
2246  
2247 @Language::Axbasic::Statement::addtimer::ISA = qw(
2248 Language::Axbasic
2249 Language::Axbasic::Statement
2250 );
2251  
2252 # ADDTIMER expression , expression [ , expression ]
2253  
2254 ##################
2255 # Methods
2256  
2257 sub parse {
2258  
2259 # Called by LA::Line->parse directly after a call to LA::Statement->new
2260 #
2261 # Expected arguments
2262 # (none besides $self)
2263 #
2264 # Return values
2265 # 'undef' on improper arguments or if there is an error
2266 # 1 otherwise
2267  
2268 my ($self, $check) = @_;
2269  
2270 # Local variables
2271 my ($stimulusExp, $responseExp, $nameExp, $token);
2272  
2273 # Check for improper arguments
2274 if (defined $check) {
2275  
2276 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2277 }
2278  
2279 # Convert the interval and action strings into expressions
2280 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
2281 $self->scriptObj,
2282 $self->tokenGroupObj,
2283 );
2284  
2285 if (! defined $stimulusExp) {
2286  
2287 return $self->scriptObj->setError(
2288 'missing_or_illegal_expression',
2289 $self->_objClass . '->parse',
2290 );
2291 }
2292  
2293 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2294  
2295 return $self->scriptObj->setError(
2296 'syntax_error',
2297 $self->_objClass . '->parse',
2298 );
2299 }
2300  
2301 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
2302 $self->scriptObj,
2303 $self->tokenGroupObj,
2304 );
2305  
2306 if (! defined $responseExp) {
2307  
2308 return $self->scriptObj->setError(
2309 'missing_or_illegal_expression',
2310 $self->_objClass . '->parse',
2311 );
2312 }
2313  
2314 # Get the timer name, if specified
2315 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2316  
2317 $token = $self->tokenGroupObj->lookAhead();
2318 if (defined $token) {
2319  
2320 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
2321 $self->scriptObj,
2322 $self->tokenGroupObj,
2323 );
2324  
2325 if (! defined $nameExp) {
2326  
2327 return $self->scriptObj->setError(
2328 'missing_or_illegal_expression',
2329 $self->_objClass . '->parse',
2330 );
2331 }
2332 }
2333 }
2334  
2335 # Check that nothing follows the expressions
2336 if (! $self->tokenGroupObj->testStatementEnd()) {
2337  
2338 return $self->scriptObj->setError(
2339 'unexpected_keywords,_operators_or_expressions',
2340 $self->_objClass . '->parse',
2341 );
2342 }
2343  
2344 # Store the expressions, so $self->implement can retrieve them
2345 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
2346 $self->ivAdd('parseDataHash', 'response', $responseExp);
2347 # (If the third expession wasn't specified, $name will be 'undef'
2348 $self->ivAdd('parseDataHash', 'name', $nameExp);
2349  
2350 # Parsing complete
2351 return 1;
2352 }
2353  
2354 sub implement {
2355  
2356 # Called by LA::Line->implement directly after a call to $self->parse
2357 #
2358 # Expected arguments
2359 # (none besides $self)
2360 #
2361 # Return values
2362 # 'undef' on improper arguments or if there is an error
2363 # 1 otherwise
2364  
2365 my ($self, $check) = @_;
2366  
2367 # Local variables
2368 my (
2369 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
2370 );
2371  
2372 # Check for improper arguments
2373 if (defined $check) {
2374  
2375 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2376 }
2377  
2378 # Retrieve the arguments stored by $self->parse
2379 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
2380 $responseExp = $self->ivShow('parseDataHash', 'response');
2381 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2382  
2383 # Evaluate each expression
2384 $stimulus = $stimulusExp->evaluate();
2385 $response = $responseExp->evaluate();
2386 if (defined $nameExp) {
2387  
2388 $name = $nameExp->evaluate();
2389 }
2390  
2391 # Specify which profile to use
2392 if (defined $self->scriptObj->useProfile) {
2393 $profile = $self->scriptObj->useProfile;
2394 } else {
2395 $profile = $self->scriptObj->session->currentWorld->name;
2396 }
2397  
2398 # Prepare the client command
2399 $string = 'addtimer -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2400 if ($name) {
2401  
2402 $string .= ' -n <' . $name . '>';
2403 }
2404  
2405 # Send the command
2406 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2407  
2408 # Timer created successfully. Update the LA::Script IVs
2409 if (! $name) {
2410  
2411 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
2412 # specified
2413 $name = $stimulus;
2414 }
2415  
2416 $self->scriptObj->push_indepInterfaceList($name, $profile, 'timer');
2417 $self->scriptObj->set_indepInterfaceName($name);
2418  
2419 } else {
2420  
2421 # Store the fact that creation of the timer failed
2422 $self->scriptObj->set_indepInterfaceName(undef);
2423 }
2424  
2425 # Implementation complete
2426 return 1;
2427 }
2428 }
2429  
2430 { package Language::Axbasic::Statement::addtrig;
2431  
2432 use strict;
2433 use warnings;
2434 use diagnostics;
2435  
2436 use Glib qw(TRUE FALSE);
2437  
2438 @Language::Axbasic::Statement::addtrig::ISA = qw(
2439 Language::Axbasic
2440 Language::Axbasic::Statement
2441 );
2442  
2443 # ADDTRIG expression , expression [ , expression ]
2444  
2445 ##################
2446 # Methods
2447  
2448 sub parse {
2449  
2450 # Called by LA::Line->parse directly after a call to LA::Statement->new
2451 #
2452 # Expected arguments
2453 # (none besides $self)
2454 #
2455 # Return values
2456 # 'undef' on improper arguments or if there is an error
2457 # 1 otherwise
2458  
2459 my ($self, $check) = @_;
2460  
2461 # Local variables
2462 my ($stimulusExp, $responseExp, $nameExp, $token);
2463  
2464 # Check for improper arguments
2465 if (defined $check) {
2466  
2467 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2468 }
2469  
2470 # Convert the pattern and action strings into expressions
2471 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
2472 $self->scriptObj,
2473 $self->tokenGroupObj,
2474 );
2475  
2476 if (! defined $stimulusExp) {
2477  
2478 return $self->scriptObj->setError(
2479 'missing_or_illegal_expression',
2480 $self->_objClass . '->parse',
2481 );
2482 }
2483  
2484 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2485  
2486 return $self->scriptObj->setError(
2487 'syntax_error',
2488 $self->_objClass . '->parse',
2489 );
2490 }
2491  
2492 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
2493 $self->scriptObj,
2494 $self->tokenGroupObj,
2495 );
2496  
2497 if (! defined $responseExp) {
2498  
2499 return $self->scriptObj->setError(
2500 'missing_or_illegal_expression',
2501 $self->_objClass . '->parse',
2502 );
2503 }
2504  
2505 # Get the trigger name, if specified
2506 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2507  
2508 $token = $self->tokenGroupObj->lookAhead();
2509 if (defined $token) {
2510  
2511 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
2512 $self->scriptObj,
2513 $self->tokenGroupObj,
2514 );
2515  
2516 if (! defined $nameExp) {
2517  
2518 return $self->scriptObj->setError(
2519 'missing_or_illegal_expression',
2520 $self->_objClass . '->parse',
2521 );
2522 }
2523 }
2524 }
2525  
2526 # Check that nothing follows the expressions
2527 if (! $self->tokenGroupObj->testStatementEnd()) {
2528  
2529 return $self->scriptObj->setError(
2530 'unexpected_keywords,_operators_or_expressions',
2531 $self->_objClass . '->parse',
2532 );
2533 }
2534  
2535 # Store the expressions, so $self->implement can retrieve them
2536 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
2537 $self->ivAdd('parseDataHash', 'response', $responseExp);
2538 # (If the third expession wasn't specified, $name will be 'undef'
2539 $self->ivAdd('parseDataHash', 'name', $nameExp);
2540  
2541 # Parsing complete
2542 return 1;
2543 }
2544  
2545 sub implement {
2546  
2547 # Called by LA::Line->implement directly after a call to $self->parse
2548 #
2549 # Expected arguments
2550 # (none besides $self)
2551 #
2552 # Return values
2553 # 'undef' on improper arguments or if there is an error
2554 # 1 otherwise
2555  
2556 my ($self, $check) = @_;
2557  
2558 # Local variables
2559 my (
2560 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
2561 );
2562  
2563 # Check for improper arguments
2564 if (defined $check) {
2565  
2566 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2567 }
2568  
2569 # Retrieve the arguments stored by $self->parse
2570 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
2571 $responseExp = $self->ivShow('parseDataHash', 'response');
2572 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2573  
2574 # Evaluate each expression
2575 $stimulus = $stimulusExp->evaluate();
2576 $response = $responseExp->evaluate();
2577 if (defined $nameExp) {
2578  
2579 $name = $nameExp->evaluate();
2580 }
2581  
2582 # Specify which profile to use
2583 if (defined $self->scriptObj->useProfile) {
2584 $profile = $self->scriptObj->useProfile;
2585 } else {
2586 $profile = $self->scriptObj->session->currentWorld->name;
2587 }
2588  
2589 # Prepare the client command
2590 $string = 'addtrigger -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2591 if ($name) {
2592  
2593 $string .= ' -n <' . $name . '>';
2594 }
2595  
2596 # Send the command
2597 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2598  
2599 # Trigger created successfully. Update the LA::Script IVs
2600 if (! $name) {
2601  
2602 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
2603 # specified
2604 $name = $stimulus;
2605 }
2606  
2607 $self->scriptObj->push_indepInterfaceList($name, $profile, 'trigger');
2608 $self->scriptObj->set_indepInterfaceName($name);
2609  
2610 } else {
2611  
2612 # Store the fact that creation of the trigger failed
2613 $self->scriptObj->set_indepInterfaceName(undef);
2614 }
2615  
2616 # Implementation complete
2617 return 1;
2618 }
2619 }
2620  
2621 { package Language::Axbasic::Statement::beep;
2622  
2623 use strict;
2624 use warnings;
2625 use diagnostics;
2626  
2627 use Glib qw(TRUE FALSE);
2628  
2629 @Language::Axbasic::Statement::beep::ISA = qw(
2630 Language::Axbasic
2631 Language::Axbasic::Statement
2632 );
2633  
2634 # BEEP
2635  
2636 ##################
2637 # Methods
2638  
2639 sub parse {
2640  
2641 # Called by LA::Line->parse directly after a call to LA::Statement->new
2642 #
2643 # Expected arguments
2644 # (none besides $self)
2645 #
2646 # Return values
2647 # 'undef' on improper arguments or if there is an error
2648 # 1 otherwise
2649  
2650 my ($self, $check) = @_;
2651  
2652 # Check for improper arguments
2653 if (defined $check) {
2654  
2655 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2656 }
2657  
2658 # BEEP statements always appear on their own
2659 if (! $self->tokenGroupObj->testStatementEnd()) {
2660  
2661 return $self->scriptObj->setError(
2662 'unexpected_keywords,_operators_or_expressions',
2663 $self->_objClass . '->parse',
2664 );
2665 }
2666  
2667 # Parsing complete
2668 return 1;
2669 }
2670  
2671 sub implement {
2672  
2673 # Called by LA::Line->implement directly after a call to $self->parse
2674 #
2675 # Expected arguments
2676 # (none besides $self)
2677 #
2678 # Return values
2679 # 'undef' on improper arguments or if there is an error
2680 # 1 otherwise
2681  
2682 my ($self, $check) = @_;
2683  
2684 # Check for improper arguments
2685 if (defined $check) {
2686  
2687 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2688 }
2689  
2690 # Check that the sound effect exists
2691 if (
2692 ! $axmud::CLIENT->ivExists('customSoundHash', 'beep')
2693 || ! $axmud::CLIENT->ivShow('customSoundHash', 'beep')
2694 ) {
2695 return $self->scriptObj->setError(
2696 'beep_not_available',
2697 $self->_objClass . '->implement',
2698 );
2699  
2700 } else {
2701  
2702 # Play the sound effect (if allowed)
2703 $axmud::CLIENT->playSound('beep');
2704 }
2705  
2706 # Implementation complete
2707 return 1;
2708 }
2709 }
2710  
2711 { package Language::Axbasic::Statement::break;
2712  
2713 use strict;
2714 use warnings;
2715 use diagnostics;
2716  
2717 use Glib qw(TRUE FALSE);
2718  
2719 @Language::Axbasic::Statement::break::ISA = qw(
2720 Language::Axbasic
2721 Language::Axbasic::Statement
2722 );
2723  
2724 # BREAK
2725  
2726 ##################
2727 # Methods
2728  
2729 sub parse {
2730  
2731 # Called by LA::Line->parse directly after a call to LA::Statement->new
2732 #
2733 # Expected arguments
2734 # (none besides $self)
2735 #
2736 # Return values
2737 # 'undef' on improper arguments or if there is an error
2738 # 1 otherwise
2739  
2740 my ($self, $check) = @_;
2741  
2742 # Check for improper arguments
2743 if (defined $check) {
2744  
2745 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2746 }
2747  
2748 # BREAK statements always appear on their own
2749 if (! $self->tokenGroupObj->testStatementEnd()) {
2750  
2751 return $self->scriptObj->setError(
2752 'unexpected_keywords,_operators_or_expressions',
2753 $self->_objClass . '->parse',
2754 );
2755 }
2756  
2757 # Parsing complete
2758 return 1;
2759 }
2760  
2761 sub implement {
2762  
2763 # Called by LA::Line->implement directly after a call to $self->parse
2764 #
2765 # Expected arguments
2766 # (none besides $self)
2767 #
2768 # Return values
2769 # 'undef' on improper arguments or if there is an error
2770 # 1 otherwise
2771  
2772 my ($self, $check) = @_;
2773  
2774 # Check for improper arguments
2775 if (defined $check) {
2776  
2777 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2778 }
2779  
2780 # If the Axbasic script is being run from within an Axmud task, pause execution until the
2781 # next task loop. Otherwise, do nothing
2782 if ($self->scriptObj->parentTask) {
2783  
2784 $self->scriptObj->set_scriptStatus('paused');
2785  
2786 # Reset the number of steps to take, before taking an automatic pause
2787 $self->scriptObj->set_stepCount(0);
2788 }
2789  
2790 # Implementation complete
2791 return 1;
2792 }
2793 }
2794  
2795 { package Language::Axbasic::Statement::bypass;
2796  
2797 use strict;
2798 use warnings;
2799 use diagnostics;
2800  
2801 use Glib qw(TRUE FALSE);
2802  
2803 @Language::Axbasic::Statement::bypass::ISA = qw(
2804 Language::Axbasic
2805 Language::Axbasic::Statement
2806 );
2807  
2808 # BYPASS expression
2809  
2810 ##################
2811 # Methods
2812  
2813 sub parse {
2814  
2815 # Called by LA::Line->parse directly after a call to LA::Statement->new
2816 #
2817 # Expected arguments
2818 # (none besides $self)
2819 #
2820 # Return values
2821 # 'undef' on improper arguments or if there is an error
2822 # 1 otherwise
2823  
2824 my ($self, $check) = @_;
2825  
2826 # Local variables
2827 my $expression;
2828  
2829 # Check for improper arguments
2830 if (defined $check) {
2831  
2832 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2833 }
2834  
2835 # Get the expression and store it for ->implement to use
2836 $expression = Language::Axbasic::Expression::Arithmetic->new(
2837 $self->scriptObj,
2838 $self->tokenGroupObj,
2839 );
2840  
2841 if (! defined $expression) {
2842  
2843 return $self->scriptObj->setError(
2844 'missing_or_illegal_expression',
2845 $self->_objClass . '->parse',
2846 );
2847  
2848 } else {
2849  
2850 $self->ivAdd('parseDataHash', 'expression', $expression);
2851 }
2852  
2853 # There should be nothing after the expression
2854 if (! $self->tokenGroupObj->testStatementEnd()) {
2855  
2856 return $self->scriptObj->setError(
2857 'unexpected_keywords,_operators_or_expressions',
2858 $self->_objClass . '->parse',
2859 );
2860 }
2861  
2862 # Parsing complete
2863 return 1;
2864 }
2865  
2866 sub implement {
2867  
2868 # Called by LA::Line->implement directly after a call to $self->parse
2869 #
2870 # Expected arguments
2871 # (none besides $self)
2872 #
2873 # Return values
2874 # 'undef' on improper arguments or if there is an error
2875 # 1 otherwise
2876  
2877 my ($self, $check) = @_;
2878  
2879 # Local variables
2880 my ($expression, $string);
2881  
2882 # Check for improper arguments
2883 if (defined $check) {
2884  
2885 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2886 }
2887  
2888 # Retrieve the expression to be written
2889 $expression = $self->ivShow('parseDataHash', 'expression');
2890 # Evaluate the expression to get a scalar value
2891 $string = $expression->evaluate();
2892  
2893 # Execute the expression as a bypass command
2894 $self->scriptObj->session->worldCmd($string, undef, undef, TRUE);
2895  
2896 # Implementation complete
2897 return 1;
2898 }
2899 }
2900  
2901 { package Language::Axbasic::Statement::call;
2902  
2903 use strict;
2904 use warnings;
2905 use diagnostics;
2906  
2907 use Glib qw(TRUE FALSE);
2908  
2909 @Language::Axbasic::Statement::call::ISA = qw(
2910 Language::Axbasic
2911 Language::Axbasic::Statement
2912 );
2913  
2914 # CALL subroutine-name
2915 # CALL subroutine-name ( [ expression [ , expression ... ] ] )
2916  
2917 ##################
2918 # Methods
2919  
2920 sub parse {
2921  
2922 # Called by LA::Line->parse directly after a call to LA::Statement->new
2923 #
2924 # Expected arguments
2925 # (none besides $self)
2926 #
2927 # Optional arguments
2928 # $letStatement - When this function is called from within a LET statement,
2929 # i.e. 'LET a$ = CALL func_name (arg$)', which LET statement called
2930 # this one
2931 #
2932 # Return values
2933 # 'undef' on improper arguments or if there is an error
2934 # 1 otherwise
2935  
2936 my ($self, $letStatement, $check) = @_;
2937  
2938 # Local variables
2939 my ($subNameToken, $subName, $argListObj);
2940  
2941 # Check for improper arguments
2942 if (defined $check) {
2943  
2944 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2945 }
2946  
2947 # If $letStatement was specified, use it
2948 if ($letStatement) {
2949  
2950 $self = $letStatement;
2951 }
2952  
2953 # The 'call' keyword is not available in primitive numbering mode
2954 if ($self->scriptObj->executionMode ne 'no_line_num') {
2955  
2956 return $self->scriptObj->setError(
2957 'statement_not_available_with_line_numbers',
2958 $self->_objClass . '->parse',
2959 );
2960 }
2961  
2962 # Check there's a subroutine name to be got...
2963 if (defined $self->tokenGroupObj->testStatementEnd()) {
2964  
2965 return $self->scriptObj->setError(
2966 'unspecified_subroutine',
2967 $self->_objClass . '->parse',
2968 );
2969 }
2970  
2971 # Get the subroutine name
2972 $subNameToken = $self->tokenGroupObj->shiftToken();
2973 if (! defined $subNameToken) {
2974  
2975 return $self->scriptObj->setError(
2976 'unspecified_subroutine',
2977 $self->_objClass . '->parse',
2978 );
2979 }
2980  
2981 # Get an argument list. The TRUE argument means that an empty token group is treated
2982 # the same an empty arglist, in this case (e.g. 'CALL hello ()' and 'CALL hello' are both
2983 # acceptable)
2984 $argListObj = Language::Axbasic::Expression::ArgList->new(
2985 $self->scriptObj,
2986 $self->tokenGroupObj,
2987 TRUE,
2988 );
2989  
2990 if (! defined $argListObj) {
2991  
2992 return $self->scriptObj->setError(
2993 'missing_or_invalid_argument_list',
2994 $self->_objClass . '->parse',
2995 );
2996 }
2997  
2998 # Check that there is nothing after the list of arguments (except for the statement
2999 # separator, : )
3000 if (! $self->tokenGroupObj->testStatementEnd()) {
3001  
3002 return $self->scriptObj->setError(
3003 'unexpected_keywords,_operators_or_expressions',
3004 $self->_objClass . '->parse',
3005 );
3006 }
3007  
3008 # Store the subroutine name and its argument list for ->implement to use
3009 $self->ivAdd('parseDataHash', 'sub_name', $subNameToken->tokenText);
3010 $self->ivAdd('parseDataHash', 'arg_list_obj', $argListObj);
3011  
3012 # Parsing complete
3013 return 1;
3014 }
3015  
3016 sub implement {
3017  
3018 # Called by LA::Line->implement directly after a call to $self->parse
3019 #
3020 # Expected arguments
3021 # (none besides $self)
3022 #
3023 # Optional arguments
3024 # $letStatement - When this function is called from within a LET statement,
3025 # i.e. 'LET a$ = CALL func_name (arg$)', which LET statement called
3026 # this one
3027 #
3028 # Return values
3029 # 'undef' on improper arguments
3030 # 1 otherwise
3031  
3032 my ($self, $letStatement, $check) = @_;
3033  
3034 # Local variables
3035 my (
3036 $returnVar, $subName, $argListObj, $subObj, $declareStatement,
3037 @callArgList, @subArgList,
3038 );
3039  
3040 # Check for improper arguments
3041 if (defined $check) {
3042  
3043 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3044 }
3045  
3046 # If $letStatement was specified, use it
3047 if ($letStatement) {
3048  
3049 $self = $letStatement;
3050 # The subroutine's return value must be assigned to this variable
3051 $returnVar = $self->ivShow('parseDataHash', 'call_var');
3052 }
3053  
3054 # Retrieve the variables stored by ->parse
3055 $subName = $self->ivShow('parseDataHash', 'sub_name');
3056 $argListObj = $self->ivShow('parseDataHash', 'arg_list_obj');
3057  
3058 # Check that a subroutine with the same name has been declared
3059 if (! $self->scriptObj->ivExists('subNameHash', $subName)) {
3060  
3061 return $self->scriptObj->setError(
3062 'no_such_function_or_subroutine',
3063 $self->_objClass . '->implement',
3064 );
3065  
3066 } else {
3067  
3068 $subObj = $self->scriptObj->ivShow('subNameHash', $subName);
3069 }
3070  
3071 # We need to check that the arguments specified in the CALL statement are of the same
3072 # number, and of the same type, as the arguments specified in the subroutine declaration
3073 @callArgList = $argListObj->argList;
3074 @subArgList = $subObj->argListObj->argList;
3075  
3076 # Check that there are the right number of arguments
3077 if ((scalar @callArgList) != (scalar @subArgList)) {
3078  
3079 return $self->scriptObj->setError(
3080 'wrong_number_of_arguments',
3081 $self->_objClass . '->implement',
3082 );
3083 }
3084  
3085 # Check that each argument is of the right type
3086 if (@callArgList) {
3087  
3088 for (my $count = 0; $count < scalar @callArgList; $count++) {
3089  
3090 my $value = $callArgList[$count]->evaluate();
3091  
3092 if (
3093 ref($subArgList[$count]) =~ m/Numeric/
3094 && ! Scalar::Util::looks_like_number($value)
3095 ) {
3096 return $self->scriptObj->setError(
3097 'type_mismatch_error',
3098 $self->_objClass . '->implement',
3099 );
3100 }
3101 }
3102 }
3103  
3104 # Make sure the subroutine's local variable and code block stores are empty
3105 $subObj->set_localScalarHash();
3106 $subObj->set_localArrayHash();
3107 $subObj->set_blockStackList();
3108 # Set the variable that will be assigned the subroutine's return value
3109 if ($returnVar) {
3110  
3111 $subObj->set_returnVar($returnVar);
3112  
3113 } else {
3114  
3115 # Empty a variable from any previous call
3116 $subObj->set_returnVar(undef);
3117 }
3118  
3119 # Evaluate each argument in the CALL statement's argument list, then create local variables
3120 # in the subroutine initialised with those values
3121 if (@callArgList) {
3122  
3123 for (my $count = 0; $count < scalar @callArgList; $count++) {
3124  
3125 my ($callArg, $value, $subArg);
3126  
3127 $callArg = $callArgList[$count];
3128 $value = $callArg->evaluate();
3129  
3130 $subArg = $subArgList[$count];
3131 $subArg->variable->set($value);
3132  
3133 # Initialise local variable $subArg->varName (e.g. name$) with $value
3134 $subObj->add_localScalar($subArg->varName, $subArg);
3135 }
3136 }
3137  
3138 # Execution will shortly at the first statement after the SUB declaration statement
3139 $declareStatement = $subObj->declareStatement;
3140  
3141 # The next statement to execute is the statement after that
3142 if (defined $declareStatement->nextStatement) {
3143  
3144 # LA::Script->nextStatement is currently set to this statement; continue execution
3145 # as if this were the SUB statement
3146 $self->scriptObj->set_nextStatement($declareStatement);
3147  
3148 } else {
3149  
3150 $self->scriptObj->set_nextStatement(undef);
3151 $self->scriptObj->set_nextLine($declareStatement->lineObj->procLineNum + 1);
3152 }
3153  
3154 # At the end of the subroutine, execution will continue at the first statement after this
3155 # one
3156 $subObj->set_callStatement($self);
3157  
3158 # Add this subroutine to the script's subroutine stack
3159 $self->scriptObj->pushSubStack($subObj);
3160  
3161 # Implementation complete
3162 return 1;
3163 }
3164 }
3165  
3166 { package Language::Axbasic::Statement::case;
3167  
3168 use strict;
3169 use warnings;
3170 use diagnostics;
3171  
3172 use Glib qw(TRUE FALSE);
3173  
3174 @Language::Axbasic::Statement::case::ISA = qw(
3175 Language::Axbasic
3176 Language::Axbasic::Statement
3177 );
3178  
3179 # CASE constant [ , constant ...]
3180 # CASE ELSE
3181  
3182 ##################
3183 # Methods
3184  
3185 sub parse {
3186  
3187 # Called by LA::Line->parse directly after a call to LA::Statement->new
3188 #
3189 # Expected arguments
3190 # (none besides $self)
3191 #
3192 # Return values
3193 # 'undef' on improper arguments or if there is an error
3194 # 1 otherwise
3195  
3196 my ($self, $check) = @_;
3197  
3198 # Local variables
3199 my ($subObj, $selectStatement);
3200  
3201 # Check for improper arguments
3202 if (defined $check) {
3203  
3204 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3205 }
3206  
3207 # The 'case' keyword is not available in primitive numbering mode
3208 if ($self->scriptObj->executionMode ne 'no_line_num') {
3209  
3210 return $self->scriptObj->setError(
3211 'statement_not_available_with_line_numbers',
3212 $self->_objClass . '->parse',
3213 );
3214 }
3215  
3216 # Get the SELECT CASE statement which starts this code block
3217 $subObj = $self->scriptObj->returnCurrentSub();
3218 if (! $subObj->selectStackList) {
3219  
3220 return $self->scriptObj->setError(
3221 'CASE_statement_without_matching_SELECT_CASE',
3222 $self->_objClass . '->parse',
3223 );
3224  
3225 } else {
3226  
3227 # The matching SELECT CASE statement is the last one in the stack
3228 $selectStatement = $subObj->pop_selectStackList();
3229 }
3230  
3231 if ($self->tokenGroupObj->shiftMatchingToken('else')) {
3232  
3233 # CASE ELSE statement
3234  
3235 # If the SELECT CASE statement has already seen a CASE ELSE, it's an error
3236 if (defined $selectStatement->ivShow('parseDataHash', 'case_else_statement')) {
3237  
3238 return $self->scriptObj->setError(
3239 'multiple_CASE_ELSE_statements_in_SELECT_block',
3240 $self->_objClass . '->parse',
3241 );
3242  
3243 } else {
3244  
3245 # Inform the SELECT CASE statement where its CASE ELSE statement is
3246 $selectStatement->add_parseDataHash('case_else_statement', $self);
3247 }
3248  
3249 } else {
3250  
3251 # CASE constant [ , constant ...] statement
3252  
3253 # Read the constants, one by one, and store them
3254 do {
3255  
3256 my $expression = Language::Axbasic::Expression::Constant->new(
3257 $self->scriptObj,
3258 $self->tokenGroupObj,
3259 );
3260  
3261 if (! defined $expression) {
3262  
3263 return $self->scriptObj->setError(
3264 'missing_or_illegal_constant',
3265 $self->_objClass . '->parse',
3266 );
3267  
3268 } else {
3269  
3270 $self->ivPush('parseDataList', $expression->evaluate);
3271 }
3272  
3273 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
3274  
3275 # Add this statement to the SELECT CASE statement's list of CASE statements
3276 $selectStatement->push_parseDataList($self);
3277 }
3278  
3279 # Store the SELECT CASE statement so this statement's ->implement can use it
3280 $self->ivAdd('parseDataHash', 'select_statement', $selectStatement);
3281 # Re-insert the SELECT CASE statement back into its stack
3282 $subObj->push_selectStackList($selectStatement);
3283  
3284 # Parsing complete
3285 return 1;
3286 }
3287  
3288 sub implement {
3289  
3290 # Called by LA::Line->implement directly after a call to $self->parse
3291 #
3292 # Expected arguments
3293 # (none besides $self)
3294 #
3295 # Return values
3296 # 'undef' on improper arguments or if there is an error
3297 # 1 otherwise
3298  
3299 my ($self, $check) = @_;
3300  
3301 # Local variables
3302 my ($selectStatement, $endSelectStatement, $subObj, $topStatement);
3303  
3304 # Check for improper arguments
3305 if (defined $check) {
3306  
3307 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3308 }
3309  
3310 # Retrieve the SELECT CASE statement which starts this code block
3311 $selectStatement = $self->ivShow('parseDataHash', 'select_statement');
3312 # Get the matching END SELECT statement
3313 $endSelectStatement = $selectStatement->ivShow('parseDataHash', 'end_select_statement');
3314  
3315 # This SELECT CASE..CASE..END SELECT code block has now finished
3316 $subObj = $self->scriptObj->returnCurrentSub();
3317 $subObj->pop_selectStackList();
3318  
3319 # Execution continues at the next statement after END SELECT
3320 if (defined $endSelectStatement->nextStatement) {
3321  
3322 $self->scriptObj->set_nextStatement($endSelectStatement->nextStatement);
3323  
3324 } else {
3325  
3326 # The case statement was the last (or only) statement on the line: use the next line
3327 $self->scriptObj->set_nextLine($endSelectStatement->lineObj->procLineNum + 1);
3328 }
3329  
3330 # Remove this code block from the standard code block stack.
3331 if (! $subObj->blockStackList) {
3332  
3333 return $self->scriptObj->setError(
3334 'CASE_statement_without_matching_SELECT_CASE',
3335 $self->_objClass . '->implement',
3336 );
3337  
3338 } else {
3339  
3340 $topStatement = $subObj->pop_blockStackList();
3341  
3342 # The statement at the top of the stack must be a WHILE statement, not another kind of
3343 # code block
3344 if ($topStatement->keyword ne 'select') {
3345  
3346 return $self->scriptObj->setError(
3347 'CASE_statement_without_matching_SELECT_CASE',
3348 $self->_objClass . '->implement',
3349 );
3350 }
3351 }
3352  
3353 # Implementation complete
3354 return 1;
3355 }
3356 }
3357  
3358 { package Language::Axbasic::Statement::client;
3359  
3360 use strict;
3361 use warnings;
3362 use diagnostics;
3363  
3364 use Glib qw(TRUE FALSE);
3365  
3366 @Language::Axbasic::Statement::client::ISA = qw(
3367 Language::Axbasic
3368 Language::Axbasic::Statement
3369 );
3370  
3371 # CLIENT expression
3372  
3373 ##################
3374 # Methods
3375  
3376 sub parse {
3377  
3378 # Called by LA::Line->parse directly after a call to LA::Statement->new
3379 #
3380 # Expected arguments
3381 # (none besides $self)
3382 #
3383 # Return values
3384 # 'undef' on improper arguments or if there is an error
3385 # 1 otherwise
3386  
3387 my ($self, $check) = @_;
3388  
3389 # Local variables
3390 my $expression;
3391  
3392 # Check for improper arguments
3393 if (defined $check) {
3394  
3395 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3396 }
3397  
3398 # Get the expression and store it for ->implement to use
3399 $expression = Language::Axbasic::Expression::Arithmetic->new(
3400 $self->scriptObj,
3401 $self->tokenGroupObj,
3402 );
3403  
3404 if (! defined $expression) {
3405  
3406 return $self->scriptObj->setError(
3407 'missing_or_illegal_expression',
3408 $self->_objClass . '->parse',
3409 );
3410  
3411 } else {
3412  
3413 $self->ivAdd('parseDataHash', 'expression', $expression);
3414 }
3415  
3416 # There should be nothing after the expression
3417 if (! $self->tokenGroupObj->testStatementEnd()) {
3418  
3419 return $self->scriptObj->setError(
3420 'unexpected_keywords,_operators_or_expressions',
3421 $self->_objClass . '->parse',
3422 );
3423 }
3424  
3425 # Parsing complete
3426 return 1;
3427 }
3428  
3429 sub implement {
3430  
3431 # Called by LA::Line->implement directly after a call to $self->parse
3432 #
3433 # Expected arguments
3434 # (none besides $self)
3435 #
3436 # Return values
3437 # 'undef' on improper arguments or if there is an error
3438 # 1 otherwise
3439  
3440 my ($self, $check) = @_;
3441  
3442 # Local variables
3443 my ($expression, $cmd);
3444  
3445 # Check for improper arguments
3446 if (defined $check) {
3447  
3448 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3449 }
3450  
3451 # Retrieve the expression to be played
3452 $expression = $self->ivShow('parseDataHash', 'expression');
3453 # Evaluate the expression to get a client command
3454 $cmd = $expression->evaluate();
3455  
3456 # Execute the client command
3457 $self->scriptObj->session->pseudoCmd($cmd, $self->scriptObj->pseudoCmdMode);
3458  
3459 # Implementation complete
3460 return 1;
3461 }
3462 }
3463  
3464 { package Language::Axbasic::Statement::cls;
3465  
3466 use strict;
3467 use warnings;
3468 use diagnostics;
3469  
3470 use Glib qw(TRUE FALSE);
3471  
3472 @Language::Axbasic::Statement::cls::ISA = qw(
3473 Language::Axbasic
3474 Language::Axbasic::Statement
3475 );
3476  
3477 # CLS
3478  
3479 ##################
3480 # Methods
3481  
3482 sub parse {
3483  
3484 # Called by LA::Line->parse directly after a call to LA::Statement->new
3485 #
3486 # Expected arguments
3487 # (none besides $self)
3488 #
3489 # Return values
3490 # 'undef' on improper arguments or if there is an error
3491 # 1 otherwise
3492  
3493 my ($self, $check) = @_;
3494  
3495 # Local variables
3496 my ($expression);
3497  
3498 # Check for improper arguments
3499 if (defined $check) {
3500  
3501 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3502 }
3503  
3504 # EMPTYWIN statements always appear on their own
3505 if (! $self->tokenGroupObj->testStatementEnd()) {
3506  
3507 return $self->scriptObj->setError(
3508 'unexpected_keywords,_operators_or_expressions',
3509 $self->_objClass . '->parse',
3510 );
3511 }
3512  
3513 # Parsing complete
3514 return 1;
3515 }
3516  
3517 sub implement {
3518  
3519 # Called by LA::Line->implement directly after a call to $self->parse
3520 #
3521 # Expected arguments
3522 # (none besides $self)
3523 #
3524 # Return values
3525 # 'undef' on improper arguments or if there is an error
3526 # 1 otherwise
3527  
3528 my ($self, $check) = @_;
3529  
3530 # Local variables
3531  
3532 # Check for improper arguments
3533 if (defined $check) {
3534  
3535 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3536 }
3537  
3538 # If the Axbasic script is being run from within an Axmud task and the task window is open,
3539 # empty it. Otherwise, do nothing
3540 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
3541  
3542 # Clears a task window's default tab
3543 $self->scriptObj->parentTask->clearBuffer();
3544 }
3545  
3546 # Implementation complete
3547 return 1;
3548 }
3549 }
3550  
3551 { package Language::Axbasic::Statement::close;
3552  
3553 use strict;
3554 use warnings;
3555 use diagnostics;
3556  
3557 use Glib qw(TRUE FALSE);
3558  
3559 @Language::Axbasic::Statement::close::ISA = qw(
3560 Language::Axbasic
3561 Language::Axbasic::Statement
3562 );
3563  
3564 # CLOSE #channel
3565  
3566 ##################
3567 # Methods
3568  
3569 sub parse {
3570  
3571 # Called by LA::Line->parse directly after a call to LA::Statement->new
3572 #
3573 # Expected arguments
3574 # (none besides $self)
3575 #
3576 # Return values
3577 # 'undef' on improper arguments or if there is an error
3578 # 1 otherwise
3579  
3580 my ($self, $check) = @_;
3581  
3582 # Local variables
3583 my ($channelToken, $channel, $nameFlag);
3584  
3585 # Check for improper arguments
3586 if (defined $check) {
3587  
3588 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3589 }
3590  
3591 # Get the channel token. For CLOSE statements, it must not include a colon at the end
3592 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
3593 if (! defined $channelToken || $channelToken->tokenText =~ m/\:$/) {
3594  
3595 return $self->scriptObj->setError(
3596 'syntax_error',
3597 $self->_objClass . '->parse',
3598 );
3599  
3600 } else {
3601  
3602 # Store the channel number
3603 $channelToken->tokenText =~ m/([0-9]+)/;
3604 $channel = $1;
3605  
3606 # True BASIC specifies that the channel must be in the range 1-999; same range used by
3607 # Axbasic
3608 if ($channel < 1 || $channel > 999) {
3609  
3610 return $self->scriptObj->setError(
3611 'file_channel_NUM_out_of_range',
3612 $self->_objClass . '->parse',
3613 'NUM', $channel,
3614 );
3615  
3616 } else {
3617  
3618 $self->ivAdd('parseDataHash', 'channel', $channel);
3619 }
3620 }
3621  
3622 # Check that nothing follows the file channel
3623 if (! $self->tokenGroupObj->testStatementEnd()) {
3624  
3625 return $self->scriptObj->setError(
3626 'unexpected_keywords,_operators_or_expressions',
3627 $self->_objClass . '->parse',
3628 );
3629 }
3630  
3631 # Parsing complete
3632 return 1;
3633 }
3634  
3635 sub implement {
3636  
3637 # Called by LA::Line->implement directly after a call to $self->parse
3638 #
3639 # Expected arguments
3640 # (none besides $self)
3641 #
3642 # Return values
3643 # 'undef' on improper arguments or if there is an error
3644 # 1 otherwise
3645  
3646 my ($self, $check) = @_;
3647  
3648 # Local variables
3649 my ($channel, $channelObj);
3650  
3651 # Check for improper arguments
3652 if (defined $check) {
3653  
3654 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3655 }
3656  
3657 # Retrieve the variables stored by ->parse
3658 $channel = $self->ivShow('parseDataHash', 'channel');
3659  
3660 # Check that the file channel exists
3661 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
3662  
3663 return $self->scriptObj->setError(
3664 'file_channel_NUM_not_open',
3665 $self->_objClass . '->implement',
3666 'NUM', $channel,
3667 );
3668  
3669 } else {
3670  
3671 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
3672 }
3673  
3674 # Update the LA::Script IVs
3675 $self->scriptObj->del_fileChannel($channelObj);
3676  
3677 # Close the filehandle
3678 if (! close ($channelObj->fileHandle)) {
3679  
3680 return $self->scriptObj->setError(
3681 'failed_to_close_file',
3682 $self->_objClass . '->implement',
3683 );
3684 }
3685  
3686 # Implementation complete
3687 return 1;
3688 }
3689 }
3690  
3691 { package Language::Axbasic::Statement::closewin;
3692  
3693 use strict;
3694 use warnings;
3695 use diagnostics;
3696  
3697 use Glib qw(TRUE FALSE);
3698  
3699 @Language::Axbasic::Statement::closewin::ISA = qw(
3700 Language::Axbasic
3701 Language::Axbasic::Statement
3702 );
3703  
3704 # CLOSEWIN
3705  
3706 ##################
3707 # Methods
3708  
3709 sub parse {
3710  
3711 # Called by LA::Line->parse directly after a call to LA::Statement->new
3712 #
3713 # Expected arguments
3714 # (none besides $self)
3715 #
3716 # Return values
3717 # 'undef' on improper arguments or if there is an error
3718 # 1 otherwise
3719  
3720 my ($self, $check) = @_;
3721  
3722 # Local variables
3723 my ($expression);
3724  
3725 # Check for improper arguments
3726 if (defined $check) {
3727  
3728 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3729 }
3730  
3731 # CLOSEWIN statements always appear on their own
3732 if (! $self->tokenGroupObj->testStatementEnd()) {
3733  
3734 return $self->scriptObj->setError(
3735 'unexpected_keywords,_operators_or_expressions',
3736 $self->_objClass . '->parse',
3737 );
3738 }
3739  
3740 # Parsing complete
3741 return 1;
3742 }
3743  
3744 sub implement {
3745  
3746 # Called by LA::Line->implement directly after a call to $self->parse
3747 #
3748 # Expected arguments
3749 # (none besides $self)
3750 #
3751 # Return values
3752 # 'undef' on improper arguments or if there is an error
3753 # 1 otherwise
3754  
3755 my ($self, $check) = @_;
3756  
3757 # Local variables
3758  
3759 # Check for improper arguments
3760 if (defined $check) {
3761  
3762 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3763 }
3764  
3765 # If the Axbasic script is being run from within an Axmud task and the task window is open,
3766 # close it. Otherwise, do nothing
3767 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
3768  
3769 # Close the task window
3770 $self->scriptObj->parentTask->closeWin();
3771 }
3772  
3773 # Implementation complete
3774 return 1;
3775 }
3776 }
3777  
3778 { package Language::Axbasic::Statement::data;
3779  
3780 use strict;
3781 use warnings;
3782 use diagnostics;
3783  
3784 use Glib qw(TRUE FALSE);
3785  
3786 @Language::Axbasic::Statement::data::ISA = qw(
3787 Language::Axbasic
3788 Language::Axbasic::Statement
3789 );
3790  
3791 # DATA constant [ , constant ... ]
3792  
3793 ##################
3794 # Methods
3795  
3796 sub parse {
3797  
3798 # Called by LA::Line->parse directly after a call to LA::Statement->new
3799 #
3800 # Expected arguments
3801 # (none besides $self)
3802 #
3803 # Return values
3804 # 'undef' on improper arguments or if there is an error
3805 # 1 otherwise
3806  
3807 my ($self, $check) = @_;
3808  
3809 # Local variables
3810 my $expression;
3811  
3812 # Check for improper arguments
3813 if (defined $check) {
3814  
3815 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3816 }
3817  
3818 # The rest of the statement is a list of things to add to the script's global data list
3819 # - the things can be retrieved later on by the 'read' statement
3820 do {
3821  
3822 $expression = Language::Axbasic::Expression::Constant->new(
3823 $self->scriptObj,
3824 $self->tokenGroupObj,
3825 );
3826  
3827 if (! defined $expression) {
3828  
3829 return $self->scriptObj->setError(
3830 'missing_or_illegal_constant',
3831 $self->_objClass . '->parse',
3832 );
3833  
3834 } else {
3835  
3836 # One copy of the constant goes in a permanent list...
3837 $self->scriptObj->push_globalDataList($expression);
3838 # ...and another copy goes into a list from which items are removed by each
3839 # successive 'read' statement
3840 $self->scriptObj->push_readDataList($expression);
3841 }
3842  
3843 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
3844  
3845 # Parsing complete
3846 return 1;
3847 }
3848  
3849 # sub implement {} # No ->implement method necessary
3850 }
3851  
3852 { package Language::Axbasic::Statement::debug;
3853  
3854 use strict;
3855 use warnings;
3856 use diagnostics;
3857  
3858 use Glib qw(TRUE FALSE);
3859  
3860 @Language::Axbasic::Statement::debug::ISA = qw(
3861 Language::Axbasic
3862 Language::Axbasic::Statement
3863 );
3864  
3865 # DEBUG expression
3866  
3867 ##################
3868 # Methods
3869  
3870 sub parse {
3871  
3872 # Called by LA::Line->parse directly after a call to LA::Statement->new
3873 #
3874 # Expected arguments
3875 # (none besides $self)
3876  
3877 # Return values
3878 # 'undef' on improper arguments or if there is an error
3879 # 1 otherwise
3880  
3881 my ($self, $check) = @_;
3882  
3883 # Local variables
3884 my $expression;
3885  
3886 # Check for improper arguments
3887 if (defined $check) {
3888  
3889 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3890 }
3891  
3892 # Get the expression and store it for ->implement to use
3893 $expression = Language::Axbasic::Expression::Arithmetic->new(
3894 $self->scriptObj,
3895 $self->tokenGroupObj,
3896 );
3897  
3898 if (! defined $expression) {
3899  
3900 return $self->scriptObj->setError(
3901 'missing_or_illegal_expression',
3902 $self->_objClass . '->parse',
3903 );
3904  
3905 } else {
3906  
3907 $self->ivAdd('parseDataHash', 'expression', $expression);
3908 }
3909  
3910 # There should be nothing after the expression
3911 if (! $self->tokenGroupObj->testStatementEnd()) {
3912  
3913 return $self->scriptObj->setError(
3914 'unexpected_keywords,_operators_or_expressions',
3915 $self->_objClass . '->parse',
3916 );
3917 }
3918  
3919 # Parsing complete
3920 return 1;
3921 }
3922  
3923 sub implement {
3924  
3925 # Called by LA::Line->implement directly after a call to $self->parse
3926 #
3927 # Expected arguments
3928 # (none besides $self)
3929 #
3930 # Return values
3931 # 'undef' on improper arguments or if there is an error
3932 # 1 otherwise
3933  
3934 my ($self, $check) = @_;
3935  
3936 # Local variables
3937 my ($expression, $string);
3938  
3939 # Check for improper arguments
3940 if (defined $check) {
3941  
3942 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3943 }
3944  
3945 # Retrieve the expression to be written
3946 $expression = $self->ivShow('parseDataHash', 'expression');
3947 # Evaluate the expression to get a scalar value
3948 $string = $expression->evaluate();
3949  
3950 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
3951 # the error message appears on a new line
3952 if ($self->scriptObj->column != 0) {
3953  
3954 $self->scriptObj->session->writeText('', 'after');
3955 $self->scriptObj->set_column(0);
3956 }
3957  
3958 # Write the error message to the 'main' window
3959 $self->scriptObj->session->writeDebug($string);
3960  
3961 # Implementation complete
3962 return 1;
3963 }
3964 }
3965  
3966 { package Language::Axbasic::Statement::def;
3967  
3968 use strict;
3969 use warnings;
3970 use diagnostics;
3971  
3972 use Glib qw(TRUE FALSE);
3973  
3974 @Language::Axbasic::Statement::def::ISA = qw(
3975 Language::Axbasic
3976 Language::Axbasic::Statement
3977 );
3978  
3979 # DEF function-name ( variable-name [ , variable-name ... ] ) = expression
3980  
3981 ##################
3982 # Methods
3983  
3984 sub parse {
3985  
3986 # Called by LA::Line->parse directly after a call to LA::Statement->new
3987 #
3988 # Expected arguments
3989 # (none besides $self)
3990 #
3991 # Return values
3992 # 'undef' on improper arguments or if there is an error
3993 # 1 otherwise
3994  
3995 my ($self, $check) = @_;
3996  
3997 # Local variables
3998 my ($funcExpression, $funcObj, $expression);
3999  
4000 # Check for improper arguments
4001 if (defined $check) {
4002  
4003 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4004 }
4005  
4006 # The function name, and its arguments, consist of all the tokens up until the equals
4007 # Call LA::Expression::Function->new with an extra argument so it knows not to complain
4008 # about an unknown function
4009 $funcExpression = Language::Axbasic::Expression::Function->new(
4010 $self->scriptObj,
4011 $self->tokenGroupObj,
4012 'defining_flag',
4013 );
4014  
4015 if (! defined $funcExpression) {
4016  
4017 return $self->scriptObj->setError(
4018 'bad_function_definition',
4019 $self->_objClass . '->parse',
4020 );
4021 }
4022  
4023 if (! $self->tokenGroupObj->shiftTokenIfCategory('assignment_operator')) {
4024  
4025 return $self->scriptObj->setError(
4026 'missing_assignment_operator',
4027 $self->_objClass . '->parse',
4028 );
4029 }
4030  
4031 # We don't actually want the LA::Expression, just the LA::Function object we've declared
4032 $funcObj = $funcExpression->funcObj;
4033  
4034 # Read the function definition
4035 $expression = Language::Axbasic::Expression::Arithmetic->new(
4036 $self->scriptObj,
4037 $self->tokenGroupObj,
4038 );
4039  
4040 if (! defined $expression) {
4041  
4042 return $self->scriptObj->setError(
4043 'bad_function_definition',
4044 $self->_objClass . '->parse',
4045 );
4046 }
4047  
4048 # Now actually define the function (tell it how many arguments, and of which type, it has)
4049 $funcObj->set_defFuncExp($expression);
4050 # Save the function object (it doesn't appear to be retrieved by any other part of the
4051 # Axbasic code)
4052 $self->ivAdd('parseDataHash', 'func_obj', $funcObj);
4053  
4054 # Parsing complete
4055 return 1;
4056 }
4057  
4058 # sub implement {} # No ->implement method - function definition happens at parse time
4059 }
4060  
4061 { package Language::Axbasic::Statement::delalias;
4062  
4063 use strict;
4064 use warnings;
4065 use diagnostics;
4066  
4067 use Glib qw(TRUE FALSE);
4068  
4069 @Language::Axbasic::Statement::delalias::ISA = qw(
4070 Language::Axbasic
4071 Language::Axbasic::Statement
4072 );
4073  
4074 # DELALIAS expression
4075  
4076 ##################
4077 # Methods
4078  
4079 sub parse {
4080  
4081 # Called by LA::Line->parse directly after a call to LA::Statement->new
4082 # when the first token in the statement is the keyword 'delalias'
4083 #
4084 # Expected arguments
4085 # (none besides $self)
4086 #
4087 # Return values
4088 # 'undef' on improper arguments or if there is an error
4089 # 1 otherwise
4090  
4091 my ($self, $check) = @_;
4092  
4093 # Local variables
4094 my $nameExp;
4095  
4096 # Check for improper arguments
4097 if (defined $check) {
4098  
4099 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4100 }
4101  
4102 # Convert the name string into an expression
4103 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4104 $self->scriptObj,
4105 $self->tokenGroupObj,
4106 );
4107  
4108 if (! defined $nameExp) {
4109  
4110 return $self->scriptObj->setError(
4111 'missing_or_illegal_expression',
4112 $self->_objClass . '->parse',
4113 );
4114 }
4115  
4116 # Check that nothing follows the expression
4117 if (! $self->tokenGroupObj->testStatementEnd()) {
4118  
4119 return $self->scriptObj->setError(
4120 'unexpected_keywords,_operators_or_expressions',
4121 $self->_objClass . '->parse',
4122 );
4123 }
4124  
4125 # Store the expression, so $self->implement can retrieve it
4126 $self->ivAdd('parseDataHash', 'name', $nameExp);
4127  
4128 # Parsing complete
4129 return 1;
4130 }
4131  
4132 sub implement {
4133  
4134 # Called by LA::Line->implement directly after a call to $self->parse
4135 #
4136 # Expected arguments
4137 # (none besides $self)
4138 #
4139 # Return values
4140 # 'undef' on improper arguments or if there is an error
4141 # 1 otherwise
4142  
4143 my ($self, $check) = @_;
4144  
4145 # Local variables
4146 my (
4147 $nameExp, $name, $profile,
4148 @interfaceList, @newList,
4149 );
4150  
4151 # Check for improper arguments
4152 if (defined $check) {
4153  
4154 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4155 }
4156  
4157 # Retrieve the argument stored by $self->parse
4158 $nameExp = $self->ivShow('parseDataHash', 'name');
4159 # Evaluate the expression
4160 $name = $nameExp->evaluate();
4161  
4162 # Specify which profile to use
4163 if (defined $self->scriptObj->useProfile) {
4164 $profile = $self->scriptObj->useProfile;
4165 } else {
4166 $profile = $self->scriptObj->session->currentWorld->name;
4167 }
4168  
4169 # Send the command
4170 if (
4171 $self->scriptObj->session->pseudoCmd(
4172 'deletealias <' . $name . '> -d ' . $profile,
4173 $self->scriptObj->pseudoCmdMode,
4174 )
4175 ) {
4176 # Update the LA::Script's IVs
4177 @interfaceList = $self->scriptObj->indepInterfaceList;
4178 if (@interfaceList) {
4179  
4180 do {
4181 my ($tempName, $tempProfile, $tempCategory);
4182  
4183 $tempName = shift @interfaceList;
4184 $tempProfile = shift @interfaceList;
4185 $tempCategory = shift @interfaceList;
4186  
4187 if ($tempName ne $name || $tempProfile ne $profile) {
4188  
4189 # This isn't the interface just deleted - reinstate it in the list
4190 push (@newList, $tempName, $tempProfile, $tempCategory);
4191 }
4192  
4193 } until (! @interfaceList);
4194  
4195 # Replace the list, missing the alias we've removed
4196 $self->scriptObj->set_indepInterfaceList(@newList);
4197 }
4198  
4199 if ($self->scriptObj->indepInterfaceName eq $name) {
4200  
4201 $self->scriptObj->set_indepInterfaceName(undef);
4202 }
4203  
4204 } else {
4205  
4206 # Store the fact that creation of the alias failed
4207 $self->scriptObj->set_indepInterfaceName(undef);
4208 }
4209  
4210 # Implementation complete
4211 return 1;
4212 }
4213 }
4214  
4215 { package Language::Axbasic::Statement::delgauge;
4216  
4217 use strict;
4218 use warnings;
4219 use diagnostics;
4220  
4221 use Glib qw(TRUE FALSE);
4222  
4223 @Language::Axbasic::Statement::delgauge::ISA = qw(
4224 Language::Axbasic
4225 Language::Axbasic::Statement
4226 );
4227  
4228 # DELGAUGE expression
4229  
4230 ##################
4231 # Methods
4232  
4233 sub parse {
4234  
4235 # Called by LA::Line->parse directly after a call to LA::Statement->new
4236 #
4237 # Expected arguments
4238 # (none besides $self)
4239 #
4240 # Return values
4241 # 'undef' on improper arguments or if there is an error
4242 # 1 otherwise
4243  
4244 my ($self, $check) = @_;
4245  
4246 # Local variables
4247 my $numberExp;
4248  
4249 # Check for improper arguments
4250 if (defined $check) {
4251  
4252 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4253 }
4254  
4255 # Convert the number into an expression
4256 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
4257 $self->scriptObj,
4258 $self->tokenGroupObj,
4259 );
4260  
4261 if (! defined $numberExp) {
4262  
4263 return $self->scriptObj->setError(
4264 'missing_or_illegal_expression',
4265 $self->_objClass . '->parse',
4266 );
4267 }
4268  
4269 # Check that nothing follows the expression
4270 if (! $self->tokenGroupObj->testStatementEnd()) {
4271  
4272 return $self->scriptObj->setError(
4273 'unexpected_keywords,_operators_or_expressions',
4274 $self->_objClass . '->parse',
4275 );
4276 }
4277  
4278 # Store the expression, so $self->implement can retrieve it
4279 $self->ivAdd('parseDataHash', 'number', $numberExp);
4280  
4281 # Parsing complete
4282 return 1;
4283 }
4284  
4285 sub implement {
4286  
4287 # Called by LA::Line->implement directly after a call to $self->parse
4288 #
4289 # Expected arguments
4290 # (none besides $self)
4291 #
4292 # Return values
4293 # 'undef' on improper arguments or if there is an error
4294 # 1 otherwise
4295  
4296 my ($self, $check) = @_;
4297  
4298 # Local variables
4299 my ($numberExp, $number);
4300  
4301 # Check for improper arguments
4302 if (defined $check) {
4303  
4304 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4305 }
4306  
4307 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
4308 if (! $self->scriptObj->parentTask) {
4309  
4310 # Implementation complete. Execution resumes from the next statement
4311 return 1;
4312 }
4313  
4314 # Retrieve the argument stored by $self->parse
4315 $numberExp = $self->ivShow('parseDataHash', 'number');
4316 # Evaluate the expression
4317 $number = $numberExp->evaluate();
4318  
4319 # $number must be an integer, >= 0 (but it doesn't need to be a gauge number which has
4320 # actually been created with an ADDGAUGE or ADDCONGAUGE statement)
4321 if ($number =~ m/\D/ || $number < 0) {
4322  
4323 return $self->scriptObj->setError(
4324 'invalid_gauge_number',
4325 $self->_objClass . '->implement',
4326 );
4327 }
4328  
4329 # Tell the Script task to delete the gauge
4330 $self->scriptObj->parentTask->deleteGauge($number);
4331  
4332 # Implementation complete
4333 return 1;
4334 }
4335 }
4336  
4337 { package Language::Axbasic::Statement::delhook;
4338  
4339 use strict;
4340 use warnings;
4341 use diagnostics;
4342  
4343 use Glib qw(TRUE FALSE);
4344  
4345 @Language::Axbasic::Statement::delhook::ISA = qw(
4346 Language::Axbasic
4347 Language::Axbasic::Statement
4348 );
4349  
4350 # DELHOOK expression
4351  
4352 ##################
4353 # Methods
4354  
4355 sub parse {
4356  
4357 # Called by LA::Line->parse directly after a call to LA::Statement->new
4358 #
4359 # Expected arguments
4360 # (none besides $self)
4361 #
4362 # Return values
4363 # 'undef' on improper arguments or if there is an error
4364 # 1 otherwise
4365  
4366 my ($self, $check) = @_;
4367  
4368 # Local variables
4369 my ($nameExp);
4370  
4371 # Check for improper arguments
4372 if (defined $check) {
4373  
4374 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4375 }
4376  
4377 # Convert the name string into an expression
4378 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4379 $self->scriptObj,
4380 $self->tokenGroupObj,
4381 );
4382  
4383 if (! defined $nameExp) {
4384  
4385 return $self->scriptObj->setError(
4386 'missing_or_illegal_expression',
4387 $self->_objClass . '->parse',
4388 );
4389 }
4390  
4391 # Check that nothing follows the expression
4392 if (! $self->tokenGroupObj->testStatementEnd()) {
4393  
4394 return $self->scriptObj->setError(
4395 'unexpected_keywords,_operators_or_expressions',
4396 $self->_objClass . '->parse',
4397 );
4398 }
4399  
4400 # Store the expression, so $self->implement can retrieve it
4401 $self->ivAdd('parseDataHash', 'name', $nameExp);
4402  
4403 # Parsing complete
4404 return 1;
4405 }
4406  
4407 sub implement {
4408  
4409 # Called by LA::Line->implement directly after a call to $self->parse
4410 #
4411 # Expected arguments
4412 # (none besides $self)
4413 #
4414 # Return values
4415 # 'undef' on improper arguments or if there is an error
4416 # 1 otherwise
4417  
4418 my ($self, $check) = @_;
4419  
4420 # Local variables
4421 my (
4422 $nameExp, $name, $profile,
4423 @interfaceList, @newList,
4424 );
4425  
4426 # Check for improper arguments
4427 if (defined $check) {
4428  
4429 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4430 }
4431  
4432 # Retrieve the argument stored by $self->parse
4433 $nameExp = $self->ivShow('parseDataHash', 'name');
4434 # Evaluate the expression
4435 $name = $nameExp->evaluate();
4436  
4437 # Specify which profile to use
4438 if (defined $self->scriptObj->useProfile) {
4439 $profile = $self->scriptObj->useProfile;
4440 } else {
4441 $profile = $self->scriptObj->session->currentWorld->name;
4442 }
4443  
4444 # Send the command
4445 if (
4446 $self->scriptObj->session->pseudoCmd(
4447 'deletehook <' . $name . '> -d ' . $profile,
4448 $self->scriptObj->pseudoCmdMode,
4449 )
4450 ) {
4451 # Update the LA::Script's IVs
4452 @interfaceList = $self->scriptObj->indepInterfaceList;
4453 if (@interfaceList) {
4454  
4455 do {
4456  
4457 my ($tempName, $tempProfile, $tempCategory);
4458  
4459 $tempName = shift @interfaceList;
4460 $tempProfile = shift @interfaceList;
4461 $tempCategory = shift @interfaceList;
4462  
4463 if ($tempName ne $name || $tempProfile ne $profile) {
4464  
4465 # This isn't the interface just deleted - reinstate it in the list
4466 push (@newList, $tempName, $tempProfile, $tempCategory);
4467 }
4468  
4469 } until (! @interfaceList);
4470  
4471 # Replace the list, missing the hook we've removed
4472 $self->scriptObj->set_indepInterfaceList(@newList);
4473 }
4474  
4475 if ($self->scriptObj->indepInterfaceName eq $name) {
4476  
4477 $self->scriptObj->set_indepInterfaceName(undef);
4478 }
4479  
4480 } else {
4481  
4482 # Store the fact that creation of the hook failed
4483 $self->scriptObj->set_indepInterfaceName(undef);
4484 }
4485  
4486 # Implementation complete
4487 return 1;
4488 }
4489 }
4490  
4491 { package Language::Axbasic::Statement::deliface;
4492  
4493 use strict;
4494 use warnings;
4495 use diagnostics;
4496  
4497 use Glib qw(TRUE FALSE);
4498  
4499 @Language::Axbasic::Statement::deliface::ISA = qw(
4500 Language::Axbasic
4501 Language::Axbasic::Statement
4502 );
4503  
4504 # DELIFACE expression
4505  
4506 ##################
4507 # Methods
4508  
4509 sub parse {
4510  
4511 # Called by LA::Line->parse directly after a call to LA::Statement->new
4512 #
4513 # Expected arguments
4514 # (none besides $self)
4515 #
4516 # Return values
4517 # 'undef' on improper arguments or if there is an error
4518 # 1 otherwise
4519  
4520 my ($self, $check) = @_;
4521  
4522 # Local variables
4523 my $nameExp;
4524  
4525 # Check for improper arguments
4526 if (defined $check) {
4527  
4528 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4529 }
4530  
4531 # Convert the name string into an expression
4532 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4533 $self->scriptObj,
4534 $self->tokenGroupObj,
4535 );
4536  
4537 if (! defined $nameExp) {
4538  
4539 return $self->scriptObj->setError(
4540 'missing_or_illegal_expression',
4541 $self->_objClass . '->parse',
4542 );
4543 }
4544  
4545 # Check that nothing follows the expression
4546 if (! $self->tokenGroupObj->testStatementEnd()) {
4547  
4548 return $self->scriptObj->setError(
4549 'unexpected_keywords,_operators_or_expressions',
4550 $self->_objClass . '->parse',
4551 );
4552 }
4553  
4554 # Store the expression, so $self->implement can retrieve it
4555 $self->ivAdd('parseDataHash', 'name', $nameExp);
4556  
4557 # Parsing complete
4558 return 1;
4559 }
4560  
4561 sub implement {
4562  
4563 # Called by LA::Line->implement directly after a call to $self->parse
4564 #
4565 # Expected arguments
4566 # (none besides $self)
4567 #
4568 # Return values
4569 # 'undef' on improper arguments or if there is an error
4570 # 1 otherwise
4571  
4572 my ($self, $check) = @_;
4573  
4574 # Local variables
4575 my (
4576 $nameExp, $name, $obj,
4577 @interfaceList, @newList,
4578 );
4579  
4580 # Check for improper arguments
4581 if (defined $check) {
4582  
4583 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4584 }
4585  
4586 # Retrieve the argument stored by $self->parse
4587 $nameExp = $self->ivShow('parseDataHash', 'name');
4588 # Evaluate the expression
4589 $name = $nameExp->evaluate();
4590  
4591 # Check that the interface still exists and, if not, don't try to delete it
4592 if ($self->scriptObj->session->ivExists('interfaceHash', $name)) {
4593  
4594 $obj = $self->scriptObj->session->ivShow('interfaceHash', $name);
4595  
4596 # Delete the interface
4597 $self->scriptObj->session->pseudoCmd(
4598 'delete' . $obj->category . ' -i <' . $name . '>',
4599 $self->scriptObj->pseudoCmdMode,
4600 );
4601  
4602 # Update the LA::Script's list of interfaces
4603 @interfaceList = $self->scriptObj->depInterfaceList;
4604 foreach my $otherObj (@interfaceList) {
4605  
4606 if ($otherObj ne $obj) {
4607  
4608 push (@newList, $otherObj);
4609 }
4610 }
4611  
4612 $self->scriptObj->set_depInterfaceList(@newList);
4613  
4614 # Update the accompanying IV, if necessary
4615 if (
4616 defined $self->scriptObj->depInterfaceName
4617 && $self->scriptObj->depInterfaceName eq $name
4618 ) {
4619 $self->scriptObj->set_depInterfaceName(undef);
4620 }
4621  
4622 # Now, if we've just deleted an interface created by (for example) a WAITTRIG statement
4623 # - and if the parent task is waiting for that trigger to fire - it will now be
4624 # waiting forever; so we need to tell the task to stop waiting
4625 if (
4626 $self->scriptObj->parentTask
4627 && defined $self->scriptObj->parentTask->waitForInterface
4628 && $self->scriptObj->parentTask->waitForInterface eq $name
4629 ) {
4630 # Tell the task that the interface has expired
4631 $self->scriptObj->parentTask->resetInterface($obj);
4632 }
4633 }
4634  
4635 # Implementation complete
4636 return 1;
4637 }
4638 }
4639  
4640 { package Language::Axbasic::Statement::delmacro;
4641  
4642 use strict;
4643 use warnings;
4644 use diagnostics;
4645  
4646 use Glib qw(TRUE FALSE);
4647  
4648 @Language::Axbasic::Statement::delmacro::ISA = qw(
4649 Language::Axbasic
4650 Language::Axbasic::Statement
4651 );
4652  
4653 # DELMACRO expression
4654  
4655 ##################
4656 # Methods
4657  
4658 sub parse {
4659  
4660 # Called by LA::Line->parse directly after a call to LA::Statement->new
4661 #
4662 # Expected arguments
4663 # (none besides $self)
4664 #
4665 # Return values
4666 # 'undef' on improper arguments or if there is an error
4667 # 1 otherwise
4668  
4669 my ($self, $check) = @_;
4670  
4671 # Local variables
4672 my $nameExp;
4673  
4674 # Check for improper arguments
4675 if (defined $check) {
4676  
4677 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4678 }
4679  
4680 # Convert the name string into an expression
4681 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4682 $self->scriptObj,
4683 $self->tokenGroupObj,
4684 );
4685  
4686 if (! defined $nameExp) {
4687  
4688 return $self->scriptObj->setError(
4689 'missing_or_illegal_expression',
4690 $self->_objClass . '->parse',
4691 );
4692 }
4693  
4694 # Check that nothing follows the expression
4695 if (! $self->tokenGroupObj->testStatementEnd()) {
4696  
4697 return $self->scriptObj->setError(
4698 'unexpected_keywords,_operators_or_expressions',
4699 $self->_objClass . '->parse',
4700 );
4701 }
4702  
4703 # Store the expression, so $self->implement can retrieve it
4704 $self->ivAdd('parseDataHash', 'name', $nameExp);
4705  
4706 # Parsing complete
4707 return 1;
4708 }
4709  
4710 sub implement {
4711  
4712 # Called by LA::Line->implement directly after a call to $self->parse when the
4713 # first token in the statement is the keyword 'delmacro'
4714 #
4715 # Expected arguments
4716 # (none besides $self)
4717 #
4718 # Return values
4719 # 'undef' on improper arguments or if there is an error
4720 # 1 otherwise
4721  
4722 my ($self, $check) = @_;
4723  
4724 # Local variables
4725 my (
4726 $nameExp, $name, $profile,
4727 @interfaceList, @newList,
4728 );
4729  
4730 # Check for improper arguments
4731 if (defined $check) {
4732  
4733 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4734 }
4735  
4736 # Retrieve the argument stored by $self->parse
4737 $nameExp = $self->ivShow('parseDataHash', 'name');
4738 # Evaluate the expression
4739 $name = $nameExp->evaluate();
4740  
4741 # Specify which profile to use
4742 if (defined $self->scriptObj->useProfile) {
4743 $profile = $self->scriptObj->useProfile;
4744 } else {
4745 $profile = $self->scriptObj->session->currentWorld->name;
4746 }
4747  
4748 # Send the command
4749 if (
4750 $self->scriptObj->session->pseudoCmd(
4751 'deletemacro <' . $name . '> -d ' . $profile,
4752 $self->scriptObj->pseudoCmdMode,
4753 )
4754 ) {
4755 # Update the LA::Script's IVs
4756 @interfaceList = $self->scriptObj->indepInterfaceList;
4757 if (@interfaceList) {
4758  
4759 do {
4760 my ($tempName, $tempProfile, $tempCategory);
4761  
4762 $tempName = shift @interfaceList;
4763 $tempProfile = shift @interfaceList;
4764 $tempCategory = shift @interfaceList;
4765  
4766 if ($tempName ne $name || $tempProfile ne $profile) {
4767  
4768 # This isn't the interface just deleted - reinstate it in the list
4769 push (@newList, $tempName, $tempProfile, $tempCategory);
4770 }
4771  
4772 } until (! @interfaceList);
4773  
4774 # Replace the list, missing the macro we've removed
4775 $self->scriptObj->set_indepInterfaceList(@newList);
4776 }
4777  
4778 if ($self->scriptObj->indepInterfaceName eq $name) {
4779  
4780 $self->scriptObj->set_indepInterfaceName(undef);
4781 }
4782  
4783 } else {
4784  
4785 # Store the fact that creation of the macro failed
4786 $self->scriptObj->set_indepInterfaceName(undef);
4787 }
4788  
4789 # Implementation complete
4790 return 1;
4791 }
4792 }
4793  
4794 { package Language::Axbasic::Statement::delstatus;
4795  
4796 use strict;
4797 use warnings;
4798 use diagnostics;
4799  
4800 use Glib qw(TRUE FALSE);
4801  
4802 @Language::Axbasic::Statement::delstatus::ISA = qw(
4803 Language::Axbasic
4804 Language::Axbasic::Statement
4805 );
4806  
4807 # DELSTATUS expression
4808  
4809 ##################
4810 # Methods
4811  
4812 sub parse {
4813  
4814 # Called by LA::Line->parse directly after a call to LA::Statement->new
4815 #
4816 # Expected arguments
4817 # (none besides $self)
4818 #
4819 # Return values
4820 # 'undef' on improper arguments or if there is an error
4821 # 1 otherwise
4822  
4823 my ($self, $check) = @_;
4824  
4825 # Local variables
4826 my $numberExp;
4827  
4828 # Check for improper arguments
4829 if (defined $check) {
4830  
4831 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4832 }
4833  
4834 # Convert the number into an expression
4835 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
4836 $self->scriptObj,
4837 $self->tokenGroupObj,
4838 );
4839  
4840 if (! defined $numberExp) {
4841  
4842 return $self->scriptObj->setError(
4843 'missing_or_illegal_expression',
4844 $self->_objClass . '->parse',
4845 );
4846 }
4847  
4848 # Check that nothing follows the expression
4849 if (! $self->tokenGroupObj->testStatementEnd()) {
4850  
4851 return $self->scriptObj->setError(
4852 'unexpected_keywords,_operators_or_expressions',
4853 $self->_objClass . '->parse',
4854 );
4855 }
4856  
4857 # Store the expression, so $self->implement can retrieve it
4858 $self->ivAdd('parseDataHash', 'number', $numberExp);
4859  
4860 # Parsing complete
4861 return 1;
4862 }
4863  
4864 sub implement {
4865  
4866 # Called by LA::Line->implement directly after a call to $self->parse
4867 #
4868 # Expected arguments
4869 # (none besides $self)
4870 #
4871 # Return values
4872 # 'undef' on improper arguments or if there is an error
4873 # 1 otherwise
4874  
4875 my ($self, $check) = @_;
4876  
4877 # Local variables
4878 my ($numberExp, $number);
4879  
4880 # Check for improper arguments
4881 if (defined $check) {
4882  
4883 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4884 }
4885  
4886 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
4887 if (! $self->scriptObj->parentTask) {
4888  
4889 # Implementation complete. Execution resumes from the next statement
4890 return 1;
4891 }
4892  
4893 # Retrieve the argument stored by $self->parse
4894 $numberExp = $self->ivShow('parseDataHash', 'number');
4895 # Evaluate the expression
4896 $number = $numberExp->evaluate();
4897  
4898 # $number must be an integer, >= 0 (but it doesn't need to be a status bar number which has
4899 # actually been created with an ADDSTATUS or ADDCONSTATUS statement)
4900 if ($number =~ m/\D/ || $number < 0) {
4901  
4902 return $self->scriptObj->setError(
4903 'invalid_status_bar_number',
4904 $self->_objClass . '->implement',
4905 );
4906 }
4907  
4908 # Tell the Script task to delete the status bar
4909 $self->scriptObj->parentTask->deleteStatusBar($number);
4910  
4911 # Implementation complete
4912 return 1;
4913 }
4914 }
4915  
4916 { package Language::Axbasic::Statement::deltimer;
4917  
4918 use strict;
4919 use warnings;
4920 use diagnostics;
4921  
4922 use Glib qw(TRUE FALSE);
4923  
4924 @Language::Axbasic::Statement::deltimer::ISA = qw(
4925 Language::Axbasic
4926 Language::Axbasic::Statement
4927 );
4928  
4929 # DELTIMER expression
4930  
4931 ##################
4932 # Methods
4933  
4934 sub parse {
4935  
4936 # Called by LA::Line->parse directly after a call to LA::Statement->new
4937 #
4938 # Expected arguments
4939 # (none besides $self)
4940 #
4941 # Return values
4942 # 'undef' on improper arguments or if there is an error
4943 # 1 otherwise
4944  
4945 my ($self, $check) = @_;
4946  
4947 # Local variables
4948 my ($nameExp);
4949  
4950 # Check for improper arguments
4951 if (defined $check) {
4952  
4953 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4954 }
4955  
4956 # Convert the name string into an expression
4957 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4958 $self->scriptObj,
4959 $self->tokenGroupObj,
4960 );
4961  
4962 if (! defined $nameExp) {
4963  
4964 return $self->scriptObj->setError(
4965 'missing_or_illegal_expression',
4966 $self->_objClass . '->parse',
4967 );
4968 }
4969  
4970 # Check that nothing follows the expression
4971 if (! $self->tokenGroupObj->testStatementEnd()) {
4972  
4973 return $self->scriptObj->setError(
4974 'unexpected_keywords,_operators_or_expressions',
4975 $self->_objClass . '->parse',
4976 );
4977 }
4978  
4979 # Store the expression, so $self->implement can retrieve it
4980 $self->ivAdd('parseDataHash', 'name', $nameExp);
4981  
4982 # Parsing complete
4983 return 1;
4984 }
4985  
4986 sub implement {
4987  
4988 # Called by LA::Line->implement directly after a call to $self->parse
4989 #
4990 # Expected arguments
4991 # (none besides $self)
4992 #
4993 # Return values
4994 # 'undef' on improper arguments or if there is an error
4995 # 1 otherwise
4996  
4997 my ($self, $check) = @_;
4998  
4999 # Local variables
5000 my (
5001 $nameExp, $name, $profile,
5002 @interfaceList, @newList,
5003 );
5004  
5005 # Check for improper arguments
5006 if (defined $check) {
5007  
5008 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5009 }
5010  
5011 # Retrieve the argument stored by $self->parse
5012 $nameExp = $self->ivShow('parseDataHash', 'name');
5013 # Evaluate the expression
5014 $name = $nameExp->evaluate();
5015  
5016 # Specify which profile to use
5017 if (defined $self->scriptObj->useProfile) {
5018 $profile = $self->scriptObj->useProfile;
5019 } else {
5020 $profile = $self->scriptObj->session->currentWorld->name;
5021 }
5022  
5023 # Send the command
5024 if (
5025 $self->scriptObj->session->pseudoCmd(
5026 'deletetimer <' . $name . '> -d ' . $profile,
5027 $self->scriptObj->pseudoCmdMode,
5028 )
5029 ) {
5030 # Update the LA::Script's IVs
5031 @interfaceList = $self->scriptObj->indepInterfaceList;
5032 if (@interfaceList) {
5033  
5034 do {
5035 my ($tempName, $tempProfile, $tempCategory);
5036  
5037 $tempName = shift @interfaceList;
5038 $tempProfile = shift @interfaceList;
5039 $tempCategory = shift @interfaceList;
5040  
5041 if ($tempName ne $name || $tempProfile ne $profile) {
5042  
5043 # This isn't the interface just deleted - reinstate it in the list
5044 push (@newList, $tempName, $tempProfile, $tempCategory);
5045 }
5046  
5047 } until (! @interfaceList);
5048  
5049 # Replace the list, missing the timer we've removed
5050 $self->scriptObj->set_indepInterfaceList(@newList);
5051 }
5052  
5053 if ($self->scriptObj->indepInterfaceName eq $name) {
5054  
5055 $self->scriptObj->set_indepInterfaceName(undef);
5056 }
5057  
5058 } else {
5059  
5060 # Store the fact that creation of the timer failed
5061 $self->scriptObj->set_indepInterfaceName(undef);
5062 }
5063  
5064 # Implementation complete
5065 return 1;
5066 }
5067 }
5068  
5069 { package Language::Axbasic::Statement::deltrig;
5070  
5071 use strict;
5072 use warnings;
5073 use diagnostics;
5074  
5075 use Glib qw(TRUE FALSE);
5076  
5077 @Language::Axbasic::Statement::deltrig::ISA = qw(
5078 Language::Axbasic
5079 Language::Axbasic::Statement
5080 );
5081  
5082 # DELTRIG expression
5083  
5084 ##################
5085 # Methods
5086  
5087 sub parse {
5088  
5089 # Called by LA::Line->parse directly after a call to LA::Statement->new
5090 #
5091 # Expected arguments
5092 # (none besides $self)
5093 #
5094 # Return values
5095 # 'undef' on improper arguments or if there is an error
5096 # 1 otherwise
5097  
5098 my ($self, $check) = @_;
5099  
5100 # Local variables
5101 my $nameExp;
5102  
5103 # Check for improper arguments
5104 if (defined $check) {
5105  
5106 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5107 }
5108  
5109 # Convert the name string into an expression
5110 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
5111 $self->scriptObj,
5112 $self->tokenGroupObj,
5113 );
5114  
5115 if (! defined $nameExp) {
5116  
5117 return $self->scriptObj->setError(
5118 'missing_or_illegal_expression',
5119 $self->_objClass . '->parse',
5120 );
5121 }
5122  
5123 # Check that nothing follows the expression
5124 if (! $self->tokenGroupObj->testStatementEnd()) {
5125  
5126 return $self->scriptObj->setError(
5127 'unexpected_keywords,_operators_or_expressions',
5128 $self->_objClass . '->parse',
5129 );
5130 }
5131  
5132 # Store the expression, so $self->implement can retrieve it
5133 $self->ivAdd('parseDataHash', 'name', $nameExp);
5134  
5135 # Parsing complete
5136 return 1;
5137 }
5138  
5139 sub implement {
5140  
5141 # Called by LA::Line->implement directly after a call to $self->parse
5142 #
5143 # Expected arguments
5144 # (none besides $self)
5145 #
5146 # Return values
5147 # 'undef' on improper arguments or if there is an error
5148 # 1 otherwise
5149  
5150 my ($self, $check) = @_;
5151  
5152 # Local variables
5153 my (
5154 $nameExp, $name, $profile,
5155 @interfaceList, @newList,
5156 );
5157  
5158 # Check for improper arguments
5159 if (defined $check) {
5160  
5161 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5162 }
5163  
5164 # Retrieve the argument stored by $self->parse
5165 $nameExp = $self->ivShow('parseDataHash', 'name');
5166 # Evaluate the expression
5167 $name = $nameExp->evaluate();
5168  
5169 # Specify which profile to use
5170 if (defined $self->scriptObj->useProfile) {
5171 $profile = $self->scriptObj->useProfile;
5172 } else {
5173 $profile = $self->scriptObj->session->currentWorld->name;
5174 }
5175  
5176 # Send the command
5177 if (
5178 $self->scriptObj->session->pseudoCmd(
5179 'deletetrigger <' . $name . '> -d ' . $profile,
5180 $self->scriptObj->pseudoCmdMode,
5181 )
5182 ) {
5183 # Update the LA::Script's IVs
5184 @interfaceList = $self->scriptObj->indepInterfaceList;
5185 if (@interfaceList) {
5186  
5187 do {
5188 my ($tempName, $tempProfile, $tempCategory);
5189  
5190 $tempName = shift @interfaceList;
5191 $tempProfile = shift @interfaceList;
5192 $tempCategory = shift @interfaceList;
5193  
5194 if ($tempName ne $name || $tempProfile ne $profile) {
5195  
5196 # This isn't the interface just deleted - reinstate it in the list
5197 push (@newList, $tempName, $tempProfile, $tempCategory);
5198 }
5199  
5200 } until (! @interfaceList);
5201  
5202 # Replace the list, missing the trigger we've removed
5203 $self->scriptObj->set_indepInterfaceList(@newList);
5204 }
5205  
5206 if ($self->scriptObj->indepInterfaceName eq $name) {
5207  
5208 $self->scriptObj->set_indepInterfaceName(undef);
5209 }
5210  
5211 } else {
5212  
5213 # Store the fact that creation of the trigger failed
5214 $self->scriptObj->set_indepInterfaceName(undef);
5215 }
5216  
5217 # Implementation complete
5218 return 1;
5219 }
5220 }
5221  
5222 { package Language::Axbasic::Statement::dim;
5223  
5224 use strict;
5225 use warnings;
5226 use diagnostics;
5227  
5228 use Glib qw(TRUE FALSE);
5229  
5230 @Language::Axbasic::Statement::dim::ISA = qw(
5231 Language::Axbasic
5232 Language::Axbasic::Statement
5233 );
5234  
5235 # DIM variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
5236 # DIM GLOBAL variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
5237 # DIM LOCAL variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
5238  
5239 ##################
5240 # Methods
5241  
5242 sub parse {
5243  
5244 # Called by LA::Line->parse directly after a call to LA::Statement->new
5245 #
5246 # Expected arguments
5247 # (none besides $self)
5248 #
5249 # Return values
5250 # 'undef' on improper arguments or if there is an error
5251 # 1 otherwise
5252  
5253 my ($self, $check) = @_;
5254  
5255 # Local variables
5256 my ($token, $specialFlag);
5257  
5258 # Check for improper arguments
5259 if (defined $check) {
5260  
5261 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5262 }
5263  
5264 # DIM GLOBAL statement
5265 $token = $self->tokenGroupObj->shiftMatchingToken('global');
5266 if (defined $token) {
5267  
5268 # Temporarily set the IV that allows undeclared global arrays to be created
5269 $self->scriptObj->set_declareMode('global_array');
5270  
5271 # Check for DIM GLOBAL LOCAL
5272 $token = $self->tokenGroupObj->shiftMatchingToken('local');
5273 if (defined $token) {
5274  
5275 return $self->scriptObj->setError(
5276 'unexpected_keywords,_operators_or_expressions',
5277 $self->_objClass . '->parse',
5278 );
5279 }
5280 }
5281  
5282 # DIM LOCAL statement
5283 $token = $self->tokenGroupObj->shiftMatchingToken('local');
5284 if (defined $token) {
5285  
5286 # Temporarily set the IV that allows undeclared local arrays to be created
5287 $self->scriptObj->set_declareMode('local_array');
5288  
5289 # Check for DIM LOCAL GLOBAL
5290 $token = $self->tokenGroupObj->shiftMatchingToken('global');
5291 if (defined $token) {
5292  
5293 return $self->scriptObj->setError(
5294 'unexpected_keywords,_operators_or_expressions',
5295 $self->_objClass . '->parse',
5296 );
5297 }
5298 }
5299  
5300 # Check there is at least one variable name (e.g. that we don't have a solo 'DIM' or
5301 # 'DIM GLOBAL' statement)
5302 if (! defined $self->tokenGroupObj->lookAhead()) {
5303  
5304 return $self->scriptObj->setError(
5305 'syntax_error',
5306 $self->_objClass . '->parse',
5307 );
5308 }
5309  
5310 if ($self->scriptObj->declareMode eq 'default') {
5311  
5312 # Temporarily set the IV that allows undeclared global arrays to be created
5313 $self->scriptObj->set_declareMode('global_array');
5314 }
5315  
5316 if ($self->scriptObj->executionMode eq 'line_num') {
5317  
5318 # In programmes with line numbers, we don't allow DIM .. (10 TO 20)
5319 $specialFlag = FALSE;
5320  
5321 } else {
5322  
5323 # A TRUE argument tells LA::Expression::Lvalue->new to attempt to extract an
5324 # LA::Expression::SpecialArgList, rather than an an LA::Expression::ArgList
5325 $specialFlag = TRUE;
5326 }
5327  
5328 # Process each array in turn (if several appear on the same line, they are separated by
5329 # commas)
5330 do {
5331  
5332 my $expression = Language::Axbasic::Expression::Lvalue->new(
5333 $self->scriptObj,
5334 $self->tokenGroupObj,
5335 $specialFlag,
5336 );
5337  
5338 if (! defined $expression) {
5339  
5340 return $self->scriptObj->setError(
5341 'missing_or_illegal_expression',
5342 $self->_objClass . '->parse',
5343 );
5344  
5345 } else {
5346  
5347 # Save the expression object so $self->implement can use it, if it is called
5348 $self->ivPush('parseDataList', $expression);
5349 }
5350  
5351 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
5352  
5353 # We're finished creating arrays
5354 $self->scriptObj->set_declareMode('default');
5355  
5356 # Parsing complete
5357 return 1;
5358 }
5359  
5360 sub implement {
5361  
5362 # Called by LA::Line->implement directly after a call to $self->parse
5363 #
5364 # Expected arguments
5365 # (none besides $self)
5366 #
5367 # Return values
5368 # 'undef' on improper arguments or if there is an error
5369 # 1 otherwise
5370  
5371 my ($self, $check) = @_;
5372  
5373 # Local variables
5374 my @expList;
5375  
5376 # Check for improper arguments
5377 if (defined $check) {
5378  
5379 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5380 }
5381  
5382 # Import the list of expressions saved by $self->parse
5383 @expList = $self->parseDataList;
5384  
5385 # Create each array, and set its dimensions
5386 foreach my $expression (@expList) {
5387  
5388 my (@upperList, @boundList, @flatList);
5389  
5390 # If the $expression appeared in a line like DIM var, rather than the correct
5391 # DIM var(10), then ->argListObj won't be defined
5392 if (! defined $expression->argListObj) {
5393  
5394 return $self->scriptObj->setError(
5395 'invalid_expression_in_DIM_statement',
5396 $self->_objClass . '->implement',
5397 );
5398 }
5399  
5400 if ($self->scriptObj->executionMode eq 'line_num') {
5401  
5402 # Set up the array. ->evaluate returns a list of upper bounds
5403 @upperList = $expression->argListObj->evaluate();
5404  
5405 # Convert that to a flat list in groups of two, in the form
5406 # (lower, upper, lower, upper...)
5407 # For programmes with line numbers, the lower bound is always 0 (see the explanatory
5408 # comments in LA::Variable::Array->new)
5409 # For any expression that could not be evaluated, an 'undef' value was placed in
5410 # @boundList, so we need to check for that too
5411 foreach my $value (@upperList) {
5412  
5413 if (! defined $value || $value =~ m/\D/) {
5414  
5415 return $self->scriptObj->setError(
5416 'invalid_bound_for_array_dimension',
5417 $self->_objClass . '->implement',
5418 );
5419  
5420 } else {
5421  
5422 push (@flatList, 0, $value);
5423 }
5424 }
5425  
5426 } else {
5427  
5428 # Set up the array. ->evaluate returns a list of list references. Each list
5429 # reference represents a dimension and specifies the bounds of that dimension;
5430 # either in the form (upper) or (lower, upper)
5431 @boundList = $expression->argListObj->evaluate();
5432  
5433 # Convert that to a flat list in groups of two, in the form
5434 # (lower, upper, lower, upper...)
5435 # For programmes without line numbers, we use 1 as the lower bound, if not
5436 # specified
5437 # For any expression that could not be evaluated, an 'undef' value was placed in
5438 # @boundList, so we need to check for that too
5439 foreach my $listRef (@boundList) {
5440  
5441 foreach my $value (@$listRef) {
5442  
5443 if (! defined $value || ! ($value =~ m/^[-]?\d+$/)) {
5444  
5445 return $self->scriptObj->setError(
5446 'invalid_bound_for_array_dimension',
5447 $self->_objClass . '->implement',
5448 );
5449 }
5450 }
5451  
5452 if (scalar (@$listRef) == 1) {
5453  
5454 # If the lower bound is not specified, it is 1; therefore in that case, the
5455 # upper bound cannot be less than 1)
5456 if ($$listRef[0] < 1) {
5457  
5458 return $self->scriptObj->setError(
5459 'invalid_bound_for_array_dimension',
5460 $self->_objClass . '->implement',
5461 );
5462  
5463 } else {
5464  
5465 push (@flatList, 1);
5466 }
5467 }
5468  
5469 push (@flatList, @$listRef);
5470 }
5471 }
5472  
5473 # Create the array
5474 $expression->varObj->dimension(@flatList);
5475 }
5476  
5477 # Implementation complete
5478 return 1;
5479 }
5480 }
5481  
5482 { package Language::Axbasic::Statement::do;
5483  
5484 use strict;
5485 use warnings;
5486 use diagnostics;
5487  
5488 use Glib qw(TRUE FALSE);
5489  
5490 @Language::Axbasic::Statement::do::ISA = qw(
5491 Language::Axbasic
5492 Language::Axbasic::Statement
5493 );
5494  
5495 # DO
5496  
5497 ##################
5498 # Methods
5499  
5500 sub parse {
5501  
5502 # Called by LA::Line->parse directly after a call to LA::Statement->new
5503 #
5504 # Expected arguments
5505 # (none besides $self)
5506 #
5507 # Return values
5508 # 'undef' on improper arguments or if there is an error
5509 # 1 otherwise
5510  
5511 my ($self, $check) = @_;
5512  
5513 # Local variables
5514 my $subObj;
5515  
5516 # Check for improper arguments
5517 if (defined $check) {
5518  
5519 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5520 }
5521  
5522 # The 'do' keyword is not available in primitive numbering mode
5523 if ($self->scriptObj->executionMode ne 'no_line_num') {
5524  
5525 return $self->scriptObj->setError(
5526 'statement_not_available_with_line_numbers',
5527 $self->_objClass . '->parse',
5528 );
5529 }
5530  
5531 # DO statements always appear on their own
5532 if (! $self->tokenGroupObj->testStatementEnd()) {
5533  
5534 return $self->scriptObj->setError(
5535 'unexpected_keywords,_operators_or_expressions',
5536 $self->_objClass . '->parse',
5537 );
5538 }
5539  
5540 # Add this DO statement to the DO code block stack for the current subroutine
5541 $subObj = $self->scriptObj->returnCurrentSub();
5542 $subObj->push_doStackList($self);
5543  
5544 # We don't know what the corresponding UNTIL statement is, yet
5545 $self->ivAdd('parseDataHash', 'until_statement', undef);
5546  
5547 # Parsing complete
5548 return 1;
5549 }
5550  
5551 sub implement {
5552  
5553 # Called by LA::Line->implement directly after a call to $self->parse
5554 #
5555 # Expected arguments
5556 # (none besides $self)
5557 #
5558 # Return values
5559 # 'undef' on improper arguments
5560 # 1 otherwise
5561  
5562 my ($self, $check) = @_;
5563  
5564 # Local variables
5565 my $subObj;
5566  
5567 # Check for improper arguments
5568 if (defined $check) {
5569  
5570 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5571 }
5572  
5573 # Add this 'do' statement to the code block stack for the current subroutine
5574 $subObj = $self->scriptObj->returnCurrentSub();
5575 $subObj->push_blockStackList($self);
5576  
5577 # Implementation complete
5578 return 1;
5579 }
5580 }
5581  
5582 { package Language::Axbasic::Statement::else;
5583  
5584 use strict;
5585 use warnings;
5586 use diagnostics;
5587  
5588 use Glib qw(TRUE FALSE);
5589  
5590 @Language::Axbasic::Statement::else::ISA = qw(
5591 Language::Axbasic
5592 Language::Axbasic::Statement
5593 );
5594  
5595 # ELSE IF condition THEN
5596 # ELSEIF condition THEN
5597 # ELSE
5598  
5599 ##################
5600 # Methods
5601  
5602 sub parse {
5603  
5604 # Called by LA::Line->parse directly after a call to LA::Statement->new
5605 #
5606 # Expected arguments
5607 # (none besides $self)
5608 #
5609 # Return values
5610 # 'undef' on improper arguments or if there is an error
5611 # 1 otherwise
5612  
5613 my ($self, $check) = @_;
5614  
5615 # Local variables
5616 my ($subObj, $ifStatement, $elseIfFlag, $token, $condition);
5617  
5618 # Check for improper arguments
5619 if (defined $check) {
5620  
5621 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5622 }
5623  
5624 # The 'else' keyword is not available in primitive numbering mode
5625 if ($self->scriptObj->executionMode ne 'no_line_num') {
5626  
5627 return $self->scriptObj->setError(
5628 'statement_not_available_with_line_numbers',
5629 $self->_objClass . '->parse',
5630 );
5631 }
5632  
5633 # Get the IF statement which starts this code block
5634 $subObj = $self->scriptObj->returnCurrentSub();
5635 if (! $subObj->ifStackList) {
5636  
5637 return $self->scriptObj->setError(
5638 'ELSE_statement_without_matching_IF',
5639 $self->_objClass . '->parse',
5640 );
5641  
5642 } else {
5643  
5644 # The matching IF statement is the last one in the stack
5645 $ifStatement = $subObj->pop_ifStackList();
5646 }
5647  
5648 # Test for ELSEIF or ELSE IF
5649 if ($self->keyword eq 'elseif') {
5650 $elseIfFlag = TRUE;
5651 } else {
5652  
5653 $token = $self->tokenGroupObj->shiftMatchingToken('if');
5654 if (defined $token) {
5655  
5656 $elseIfFlag = TRUE;
5657 }
5658 }
5659  
5660 if ($elseIfFlag) {
5661  
5662 # ELSE IF / ELSEIF statement
5663  
5664 # If the IF statement has already seen a plain ELSE, it must not be be followed by
5665 # another ELSE IF
5666 if (defined $ifStatement->ivShow('parseDataHash', 'else_statement')) {
5667  
5668 return $self->scriptObj->setError(
5669 'ELSE_IF_statement_cannot_follow_ELSE',
5670 $self->_objClass . '->parse',
5671 );
5672 }
5673  
5674 # Everything up until 'then' is a conditional expression
5675 $condition = Language::Axbasic::Expression::LogicalOr->new(
5676 $self->scriptObj,
5677 $self->tokenGroupObj,
5678 );
5679  
5680 if (! defined $condition) {
5681  
5682 return $self->scriptObj->setError(
5683 'missing_or_illegal_conditional_expression',
5684 $self->_objClass . '->parse',
5685 );
5686  
5687 } else {
5688  
5689 # Store the condition expression, so $self->implement can retrieve it
5690 $self->ivAdd('parseDataHash', 'condition', $condition);
5691 }
5692  
5693 if (! defined $self->tokenGroupObj->shiftMatchingToken('then')) {
5694  
5695 return $self->scriptObj->setError(
5696 'missing_THEN_in_ELSE_IF_statement',
5697 $self->_objClass . '->parse',
5698 );
5699 }
5700  
5701 # There should be nothing after the THEN keyword
5702 if (! $self->tokenGroupObj->testStatementEnd()) {
5703  
5704 return $self->scriptObj->setError(
5705 'ELSE_IF_statement_not_terminated_by_THEN',
5706 $self->_objClass . '->parse',
5707 );
5708 }
5709  
5710 # Save this statement in the IF statement's list of ElSE IF statements
5711 $ifStatement->push_parseDataList($self);
5712  
5713 } else {
5714  
5715 # Plain ELSE statement
5716  
5717 # If the IF statement has already seen a plain ELSE, it must not be followed by another
5718 # ELSE
5719 if (defined $ifStatement->ivShow('parseDataHash', 'else_statement')) {
5720  
5721 return $self->scriptObj->setError(
5722 'multiple_ELSE_statements_in_IF_block',
5723 $self->_objClass . '->parse',
5724 );
5725 }
5726  
5727 # There should be nothing after the ELSE keyword. Use a unique error message to make
5728 # clear that ELSE must occur alone
5729 if (! $self->tokenGroupObj->testStatementEnd()) {
5730  
5731 return $self->scriptObj->setError(
5732 'unexpected_keywords,_operators_or_expressions_in_ELSE_statement',
5733 $self->_objClass . '->parse',
5734 )
5735 }
5736  
5737 # Inform the IF statement where its ELSE statement is
5738 $ifStatement->ivAdd('parseDataHash', 'else_statement', $self);
5739 }
5740  
5741 # Store the IF statement so this statement's ->implement can use it
5742 $self->add_parseDataHash('if_statement', $ifStatement);
5743 # Re-insert the IF statement back into its stack
5744 $subObj->push_ifStackList($ifStatement);
5745  
5746 # Parsing complete
5747 return 1;
5748 }
5749  
5750 sub implement {
5751  
5752 # Called by LA::Line->implement directly after a call to $self->parse
5753 #
5754 # Expected arguments
5755 # (none besides $self)
5756 #
5757 # Return values
5758 # 'undef' on improper arguments or if there is an error
5759 # 1 otherwise
5760  
5761 my ($self, $check) = @_;
5762  
5763 # Local variables
5764 my ($ifStatement, $endIfStatement, $subObj, $topStatement);
5765  
5766 # Check for improper arguments
5767 if (defined $check) {
5768  
5769 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5770 }
5771  
5772 # Retrieve the IF statement which starts this code block
5773 $ifStatement = $self->ivShow('parseDataHash', 'if_statement');
5774 # Get the matching END IF statement
5775 $endIfStatement = $ifStatement->ivShow('parseDataHash', 'end_if_statement');
5776  
5777 # This IF..ELSE IF..ELSE..END IF code block has now finished
5778 $subObj = $self->scriptObj->returnCurrentSub();
5779  
5780 # Execution continues at the next statement after END IF
5781 if (defined $endIfStatement->nextStatement) {
5782  
5783 # LA::Script->nextStatement is currently set to this statement; continue execution
5784 # as if this were the END statement
5785 $self->scriptObj->set_nextStatement($endIfStatement);
5786  
5787 } else {
5788  
5789 $self->scriptObj->set_nextStatement(undef);
5790 $self->scriptObj->set_nextLine($endIfStatement->lineObj->procLineNum + 1);
5791 }
5792  
5793 # Remove this code block from the standard code block stack.
5794 if (! $subObj->blockStackList) {
5795  
5796 return $self->scriptObj->setError(
5797 'ELSE_statement_without_matching_IF',
5798 $self->_objClass . '->implement',
5799 );
5800  
5801 } else {
5802  
5803 $topStatement = $subObj->pop_blockStackList();
5804  
5805 # The statement at the top of the stack must be an IF statement, not another kind of
5806 # code block
5807 if ($topStatement->keyword ne 'if') {
5808  
5809 return $self->scriptObj->setError(
5810 'ELSE_statement_without_matching_IF',
5811 $self->_objClass . '->implement',
5812 );
5813 }
5814 }
5815  
5816 # Implementation complete
5817 return 1;
5818 }
5819 }
5820  
5821 { package Language::Axbasic::Statement::emptywin;
5822  
5823 use strict;
5824 use warnings;
5825 use diagnostics;
5826  
5827 use Glib qw(TRUE FALSE);
5828  
5829 @Language::Axbasic::Statement::emptywin::ISA = qw(
5830 Language::Axbasic
5831 Language::Axbasic::Statement
5832 );
5833  
5834 # EMPTYWIN
5835  
5836 ##################
5837 # Methods
5838  
5839 sub parse {
5840  
5841 # Called by LA::Line->parse directly after a call to LA::Statement->new
5842 #
5843 # Expected arguments
5844 # (none besides $self)
5845 #
5846 # Return values
5847 # 'undef' on improper arguments or if there is an error
5848 # 1 otherwise
5849  
5850 my ($self, $check) = @_;
5851  
5852 # Local variables
5853 my ($expression);
5854  
5855 # Check for improper arguments
5856 if (defined $check) {
5857  
5858 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5859 }
5860  
5861 # EMPTYWIN statements always appear on their own
5862 if (! $self->tokenGroupObj->testStatementEnd()) {
5863  
5864 return $self->scriptObj->setError(
5865 'unexpected_keywords,_operators_or_expressions',
5866 $self->_objClass . '->parse',
5867 );
5868 }
5869  
5870 # Parsing complete
5871 return 1;
5872 }
5873  
5874 sub implement {
5875  
5876 # Called by LA::Line->implement directly after a call to $self->parse
5877 #
5878 # Expected arguments
5879 # (none besides $self)
5880 #
5881 # Return values
5882 # 'undef' on improper arguments or if there is an error
5883 # 1 otherwise
5884  
5885 my ($self, $check) = @_;
5886  
5887 # Local variables
5888  
5889 # Check for improper arguments
5890 if (defined $check) {
5891  
5892 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5893 }
5894  
5895 # If the Axbasic script is being run from within an Axmud task and the task window is open,
5896 # empty it. Otherwise, do nothing
5897 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
5898  
5899 # Clears the task window's textview
5900 $self->scriptObj->parentTask->clearBuffer();
5901 }
5902  
5903 # Implementation complete
5904 return 1;
5905 }
5906 }
5907  
5908 { package Language::Axbasic::Statement::end;
5909  
5910 use strict;
5911 use warnings;
5912 use diagnostics;
5913  
5914 use Glib qw(TRUE FALSE);
5915  
5916 @Language::Axbasic::Statement::end::ISA = qw(
5917 Language::Axbasic
5918 Language::Axbasic::Statement
5919 );
5920  
5921 # END
5922 # END IF
5923 # END SUB
5924 # END SELECT
5925  
5926 ##################
5927 # Methods
5928  
5929 sub parse {
5930  
5931 # Called by LA::Line->parse directly after a call to LA::Statement->new
5932 #
5933 # Expected arguments
5934 # (none besides $self)
5935 #
5936 # Return values
5937 # 'undef' on improper arguments or if there is an error
5938 # 1 otherwise
5939  
5940 my ($self, $check) = @_;
5941  
5942 # Local variables
5943 my ($token, $currentSub, $selectStatement, $ifStatement);
5944  
5945 # Check for improper arguments
5946 if (defined $check) {
5947  
5948 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5949 }
5950  
5951 # Is this an 'END', 'END IF', 'END SELECT', 'END SUB'?
5952 $token = $self->tokenGroupObj->shiftToken();
5953 if (! defined $token) {
5954  
5955 # END statement
5956 $self->ivAdd('parseDataHash', 'end_sub_flag', FALSE);
5957  
5958 # Check that there isn't more than one 'end' statement in the script
5959 if ($self->scriptObj->endStatementFlag) {
5960  
5961 return $self->scriptObj->setError(
5962 'duplicate_END_statement',
5963 $self->_objClass . '->parse',
5964 );
5965  
5966 } else {
5967  
5968 # LA::Script->parse produces an error if, after parsing, it hasn't noticed one
5969 # (and only one) END statement
5970 $self->scriptObj->set_endStatementFlag(TRUE);
5971 }
5972  
5973 } elsif ($token->tokenText eq 'if') {
5974  
5975 # END IF statement
5976 $self->ivAdd('parseDataHash', 'end_if_flag', 1);
5977  
5978 # Check that nothing follows the END IF keywords
5979 if (! defined $self->tokenGroupObj->testStatementEnd()) {
5980  
5981 return $self->scriptObj->setError(
5982 'unexpected_keywords,_operators_or_expressions',
5983 $self->_objClass . '->parse',
5984 );
5985 }
5986  
5987 # Find the matching IF statement
5988 $currentSub = $self->scriptObj->returnCurrentSub();
5989 if (! $currentSub->ifStackList) {
5990  
5991 return $self->scriptObj->setError(
5992 'END_IF_statement_without_matching_IF',
5993 $self->_objClass . '->parse',
5994 );
5995  
5996 } else {
5997  
5998 # The matching IF statement is the last one in the stack
5999 $ifStatement = $currentSub->pop_ifStackList();
6000 $ifStatement->add_parseDataHash('end_if_statement', $self);
6001 # Store the matching statement for ->implement to use
6002 $self->ivAdd('parseDataHash', 'if_statement', $ifStatement);
6003 }
6004  
6005 } elsif ($token->tokenText eq 'select') {
6006  
6007 # END SELECT statement
6008 $self->ivAdd('parseDataHash', 'end_select_flag', 1);
6009  
6010 # END SELECT is not available in primitive numbering mode
6011 if ($self->scriptObj->executionMode ne 'no_line_num') {
6012  
6013 return $self->scriptObj->setError(
6014 'statement_not_available_with_line_numbers',
6015 $self->_objClass . '->parse',
6016 );
6017 }
6018  
6019 # Check that nothing follows the END SELECT keywords
6020 if (! defined $self->tokenGroupObj->testStatementEnd()) {
6021  
6022 return $self->scriptObj->setError(
6023 'unexpected_keywords,_operators_or_expressions',
6024 $self->_objClass . '->parse',
6025 );
6026 }
6027  
6028 # Find the matching SELECT CASE statement
6029 $currentSub = $self->scriptObj->returnCurrentSub();
6030 if (! $currentSub->selectStackList) {
6031  
6032 return $self->scriptObj->setError(
6033 'END_SELECT_statement_without_matching_SELECT_CASE',
6034 $self->_objClass . '->parse',
6035 );
6036  
6037 } else {
6038  
6039 # The matching SELECT CASE statement is the last one in the stack
6040 $selectStatement = $currentSub->pop_selectStackList();
6041 $selectStatement->add_parseDataHash('end_select_statement', $self);
6042 # Store the matching statement for ->implement to use
6043 $self->ivAdd('parseDataHash', 'select_statement', $selectStatement);
6044 }
6045  
6046 } elsif ($token->tokenText eq 'sub') {
6047  
6048 # END SUB statement
6049 $self->ivAdd('parseDataHash', 'end_sub_flag', TRUE);
6050  
6051 # END SUB is not available in primitive numbering mode
6052 if ($self->scriptObj->executionMode ne 'no_line_num') {
6053  
6054 return $self->scriptObj->setError(
6055 'statement_not_available_with_line_numbers',
6056 $self->_objClass . '->parse',
6057 );
6058 }
6059  
6060 # Check that nothing follows the END SUB keywords
6061 if (! defined $self->tokenGroupObj->testStatementEnd()) {
6062  
6063 return $self->scriptObj->setError(
6064 'unexpected_keywords,_operators_or_expressions',
6065 $self->_objClass . '->parse',
6066 );
6067 }
6068  
6069 # Check that we're inside a subroutine declaration
6070 if (! $self->scriptObj->currentParseSub) {
6071  
6072 return $self->scriptObj->setError(
6073 'mismatched_\'end_sub\'_statement',
6074 $self->_objClass . '->parse',
6075 );
6076 }
6077  
6078 # Otherwise, this is the end of the currently parsed subroutine declaration
6079 $currentSub = $self->scriptObj->currentParseSub;
6080 $currentSub->set_terminateStatement($self);
6081 $self->scriptObj->set_currentParseSub(undef);
6082  
6083 # $self->implement needs to know which subroutine is being ended
6084 $self->ivAdd('parseDataHash', 'sub_ref', $currentSub);
6085  
6086 } else {
6087  
6088 # END followed by something other than IF, SELECT or SUB
6089 return $self->scriptObj->setError(
6090 'unexpected_keywords,_operators_or_expressions',
6091 $self->_objClass . '->parse',
6092 );
6093 }
6094  
6095 # Parsing complete
6096 return 1;
6097 }
6098  
6099 sub implement {
6100  
6101 # Called by LA::Line->implement directly after a call to $self->parse
6102 #
6103 # Expected arguments
6104 # (none besides $self)
6105 #
6106 # Return values
6107 # 'undef' on improper arguments or if there is an error
6108 # 1 otherwise
6109  
6110 my ($self, $check) = @_;
6111  
6112 # Local variables
6113 my ($subObj, $callStatement, $topStatement);
6114  
6115 # Check for improper arguments
6116 if (defined $check) {
6117  
6118 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6119 }
6120  
6121 $subObj = $self->scriptObj->returnCurrentSub();
6122  
6123 if ($self->ivShow('parseDataHash', 'end_if_flag')) {
6124  
6125 # END IF statement
6126  
6127 # This IF..END IF code block has now finished
6128 if (! $subObj->blockStackList) {
6129  
6130 return $self->scriptObj->setError(
6131 'END_IF_statement_without_matching_IF',
6132 $self->_objClass . '->implement',
6133 );
6134  
6135 } else {
6136  
6137 $topStatement = $subObj->pop_blockStackList();
6138 # The statement at the top of the stack must be a IF statement, not another kind of
6139 # code block
6140 if ($topStatement->keyword ne 'if') {
6141  
6142 return $self->scriptObj->setError(
6143 'END_IF_statement_without_matching_IF',
6144 $self->_objClass . '->implement',
6145 );
6146 }
6147 }
6148  
6149 } elsif ($self->ivShow('parseDataHash', 'end_select_flag')) {
6150  
6151 # END SELECT statement
6152  
6153 # This SELECT CASE..CASE..END SELECT code block has now finished
6154 $subObj->pop_selectStackList();
6155  
6156 # Also remove this code block from the standard code block stack.
6157 if (! $subObj->blockStackList) {
6158  
6159 return $self->scriptObj->setError(
6160 'END_SELECT_statement_without_matching_SELECT_CASE',
6161 $self->_objClass . '->implement',
6162 );
6163  
6164 } else {
6165  
6166 $topStatement = $subObj->pop_blockStackList();
6167  
6168 # The statement at the top of the stack must be a WHILE statement, not another kind
6169 # of code block
6170 if ($topStatement->keyword ne 'select') {
6171  
6172 return $self->scriptObj->setError(
6173 'END_SELECT_statement_without_matching_SELECT_CASE',
6174 $self->_objClass . '->implement',
6175 );
6176 }
6177 }
6178  
6179 } elsif ($self->ivShow('parseDataHash', 'end_sub_flag')) {
6180  
6181 # END SUB statement
6182 $subObj = $self->ivShow('parseDataHash', 'sub_ref');
6183  
6184 # Execution resumes at the first statement after the one that called the subroutine
6185 $callStatement = $subObj->callStatement;
6186  
6187 # The next statement to execute is the statement after that
6188 if (defined $callStatement->nextStatement) {
6189  
6190 # LA::Script->nextStatement is currently set to this statement; continue execution
6191 # as if this were the GOSUB statement
6192 $self->scriptObj->set_nextStatement($callStatement);
6193  
6194 } else {
6195  
6196 $self->scriptObj->set_nextStatement(undef);
6197 $self->scriptObj->set_nextLine($callStatement->lineObj->procLineNum + 1);
6198 }
6199  
6200 # The subroutine's return value is 0 (for numeric) and '' (for strings). Set the return
6201 # variable, if there is one
6202 if (defined $subObj->returnVar) {
6203  
6204 if ($subObj->returnVarType eq 'numeric') {
6205 $subObj->returnVar->set(0);
6206 } else {
6207 $subObj->returnVar->set('');
6208 }
6209 }
6210  
6211 # Update the script's subroutine stack
6212 $self->scriptObj->popSubStack();
6213  
6214 } else {
6215  
6216 # END statement
6217  
6218 # Execution of the Axbasic script can now stop
6219 if ($self->scriptObj->executionStatus ne 'finished') {
6220  
6221 # 'wait_input' means that parsing/implementation of the script has finished
6222 $self->scriptObj->set_executionStatus('finished');
6223 # 'finished' means that parsing/implementation finished without an error
6224 $self->scriptObj->set_scriptStatus('finished')
6225 }
6226  
6227 # (Do nothing if the execution status has already been set to 3)
6228 }
6229  
6230 # Implementation complete
6231 return 1;
6232 }
6233 }
6234  
6235 { package Language::Axbasic::Statement::erase;
6236  
6237 use strict;
6238 use warnings;
6239 use diagnostics;
6240  
6241 use Glib qw(TRUE FALSE);
6242 # Include module here, as well as in Axbasic.pm, so that .../t/00-compile.t won't fail
6243 use Fcntl qw(SEEK_SET SEEK_END);
6244  
6245 @Language::Axbasic::Statement::erase::ISA = qw(
6246 Language::Axbasic
6247 Language::Axbasic::Statement
6248 );
6249  
6250 # ERASE #channel
6251  
6252 ##################
6253 # Methods
6254  
6255 sub parse {
6256  
6257 # Called by LA::Line->parse directly after a call to LA::Statement->new
6258 #
6259 # Expected arguments
6260 # (none besides $self)
6261 #
6262 # Return values
6263 # 'undef' on improper arguments or if there is an error
6264 # 1 otherwise
6265  
6266 my ($self, $check) = @_;
6267  
6268 # Local variables
6269 my ($channelToken, $channel, $nameFlag);
6270  
6271 # Check for improper arguments
6272 if (defined $check) {
6273  
6274 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6275 }
6276  
6277 # Get the channel token. For ERASE statements, it must not include a colon at the end
6278 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
6279 if (! defined $channelToken || $channelToken->tokenText =~ m/\:$/) {
6280  
6281 return $self->scriptObj->setError(
6282 'syntax_error',
6283 $self->_objClass . '->parse',
6284 );
6285  
6286 } else {
6287  
6288 # Store the channel number
6289 $channelToken->tokenText =~ m/([0-9]+)/;
6290 $channel = $1;
6291  
6292 # True BASIC specifies that the channel must be in the range 1-999; same range used by
6293 # Axbasic
6294 if ($channel < 1 || $channel > 999) {
6295  
6296 return $self->scriptObj->setError(
6297 'file_channel_NUM_out_of_range',
6298 $self->_objClass . '->parse',
6299 'NUM', $channel,
6300 );
6301  
6302 } else {
6303  
6304 $self->ivAdd('parseDataHash', 'channel', $channel);
6305 }
6306 }
6307  
6308 # Check that nothing follows the file channel
6309 if (! $self->tokenGroupObj->testStatementEnd()) {
6310  
6311 return $self->scriptObj->setError(
6312 'unexpected_keywords,_operators_or_expressions',
6313 $self->_objClass . '->parse',
6314 );
6315 }
6316  
6317 # Parsing complete
6318 return 1;
6319 }
6320  
6321 sub implement {
6322  
6323 # Called by LA::Line->implement directly after a call to $self->parse
6324 #
6325 # Expected arguments
6326 # (none besides $self)
6327 #
6328 # Return values
6329 # 'undef' on improper arguments or if there is an error
6330 # 1 otherwise
6331  
6332 my ($self, $check) = @_;
6333  
6334 # Local variables
6335 my ($channel, $channelObj);
6336  
6337 # Check for improper arguments
6338 if (defined $check) {
6339  
6340 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6341 }
6342  
6343 # Retrieve the variables stored by ->parse
6344 $channel = $self->ivShow('parseDataHash', 'channel');
6345  
6346 # Check that the file channel exists
6347 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
6348  
6349 return $self->scriptObj->setError(
6350 'file_channel_NUM_not_open',
6351 $self->_objClass . '->implement',
6352 'NUM', $channel,
6353 );
6354  
6355 } else {
6356  
6357 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
6358 }
6359  
6360 # Check that writing to the file channel is allowed
6361 if ($channelObj->accessType eq 'input') {
6362  
6363 return $self->scriptObj->setError(
6364 'file_channel_NUM_is_read_only',
6365 $self->_objClass . '->implement',
6366 'NUM', $channel,
6367 );
6368 }
6369  
6370 # Move the pointer to the beginning of the file, then erase its contents
6371 seek($channelObj->fileHandle, 0, Fcntl::SEEK_SET);
6372 truncate($channelObj->fileHandle, 0);
6373  
6374 # Implementation complete
6375 return 1;
6376 }
6377 }
6378  
6379 { package Language::Axbasic::Statement::error;
6380  
6381 use strict;
6382 use warnings;
6383 use diagnostics;
6384  
6385 use Glib qw(TRUE FALSE);
6386  
6387 @Language::Axbasic::Statement::error::ISA = qw(
6388 Language::Axbasic
6389 Language::Axbasic::Statement
6390 );
6391  
6392 # ERROR expression
6393  
6394 ##################
6395 # Methods
6396  
6397 sub parse {
6398  
6399 # Called by LA::Line->parse directly after a call to LA::Statement->new
6400 #
6401 # Expected arguments
6402 # (none besides $self)
6403 #
6404 # Return values
6405 # 'undef' on improper arguments or if there is an error
6406 # 1 otherwise
6407  
6408 my ($self, $check) = @_;
6409  
6410 # Local variables
6411 my $expression;
6412  
6413 # Check for improper arguments
6414 if (defined $check) {
6415  
6416 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6417 }
6418  
6419 # Get the expression and store it for ->implement to use
6420 $expression = Language::Axbasic::Expression::Arithmetic->new(
6421 $self->scriptObj,
6422 $self->tokenGroupObj,
6423 );
6424  
6425 if (! defined $expression) {
6426  
6427 return $self->scriptObj->setError(
6428 'missing_or_illegal_expression ',
6429 $self->_objClass . '->parse',
6430 );
6431  
6432 } else {
6433  
6434 $self->ivAdd('parseDataHash', 'expression', $expression);
6435 }
6436  
6437 # There should be nothing after the expression
6438 if (! $self->tokenGroupObj->testStatementEnd()) {
6439  
6440 return $self->scriptObj->setError(
6441 'unexpected_keywords,_operators_or_expressions',
6442 $self->_objClass . '->parse',
6443 );
6444 }
6445  
6446 # Parsing complete
6447 return 1;
6448 }
6449  
6450 sub implement {
6451  
6452 # Called by LA::Line->implement directly after a call to $self->parse
6453 #
6454 # Expected arguments
6455 # (none besides $self)
6456 #
6457 # Return values
6458 # 'undef' on improper arguments or if there is an error
6459 # 1 otherwise
6460  
6461 my ($self, $check) = @_;
6462  
6463 # Local variables
6464 my ($expression, $string);
6465  
6466 # Check for improper arguments
6467 if (defined $check) {
6468  
6469 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6470 }
6471  
6472 # Retrieve the expression to be written
6473 $expression = $self->ivShow('parseDataHash', 'expression');
6474 # Evaluate the expression to get a scalar value
6475 $string = $expression->evaluate();
6476  
6477 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
6478 # the error message appears on a new line
6479 if ($self->scriptObj->column != 0) {
6480  
6481 $self->scriptObj->session->writeText('', 'after');
6482 $self->scriptObj->set_column(0);
6483 }
6484  
6485 # Write the error message to the 'main' window
6486 $self->scriptObj->session->writeError($string);
6487  
6488 # Implementation complete
6489 return 1;
6490 }
6491 }
6492  
6493 { package Language::Axbasic::Statement::exit;
6494  
6495 use strict;
6496 use warnings;
6497 use diagnostics;
6498  
6499 use Glib qw(TRUE FALSE);
6500  
6501 @Language::Axbasic::Statement::exit::ISA = qw(
6502 Language::Axbasic
6503 Language::Axbasic::Statement
6504 );
6505  
6506 # EXIT DO
6507 # EXIT SUB
6508 # EXIT WHILE
6509  
6510 ##################
6511 # Methods
6512  
6513 sub parse {
6514  
6515 # Called by LA::Line->parse directly after a call to LA::Statement->new
6516 #
6517 # Expected arguments
6518 # (none besides $self)
6519 #
6520 # Return values
6521 # 'undef' on improper arguments or if there is an error
6522 # 1 otherwise
6523  
6524 my ($self, $check) = @_;
6525  
6526 # Local variables
6527 my $token;
6528  
6529 # Check for improper arguments
6530 if (defined $check) {
6531  
6532 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6533 }
6534  
6535 # The 'exit' keyword is not available in primitive numbering mode
6536 if ($self->scriptObj->executionMode ne 'no_line_num') {
6537  
6538 return $self->scriptObj->setError(
6539 'statement_not_available_with_line_numbers',
6540 $self->_objClass . '->parse',
6541 );
6542 }
6543  
6544 $token = $self->tokenGroupObj->shiftToken();
6545 if (
6546 ! defined $token
6547 || (
6548 $token->tokenText ne 'do' # EXIT DO
6549 && $token->tokenText ne 'sub' # EXIT SUB
6550 && $token->tokenText ne 'while' # EXIT WHILE
6551 )
6552 ) {
6553 # EXIT must be followed by DO, SUB or WHILE
6554 return $self->scriptObj->setError(
6555 'syntax error',
6556 $self->_objClass . '->parse',
6557 );
6558  
6559 } elsif (defined $self->tokenGroupObj->lookAhead()) {
6560  
6561 return $self->scriptObj->setError(
6562 'unexpected_keywords,_operators_or_expressions',
6563 $self->_objClass . '->parse',
6564 );
6565  
6566 } else {
6567  
6568 # Save the type of exit for ->implement
6569 $self->ivAdd('parseDataHash', 'keyword', $token->tokenText);
6570  
6571 # Parsing complete
6572 return 1;
6573 }
6574 }
6575  
6576 sub implement {
6577  
6578 # Called by LA::Line->implement directly after a call to $self->parse
6579 #
6580 # Expected arguments
6581 # (none besides $self)
6582 #
6583 # Return values
6584 # 'undef' on improper arguments or if there is an error
6585 # 1 otherwise
6586  
6587 my ($self, $check) = @_;
6588  
6589 # Local variables
6590 my ($keyword, $subObj, $matchStatement, $resumeStatement, $exitFlag);
6591  
6592 # Check for improper arguments
6593 if (defined $check) {
6594  
6595 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6596 }
6597  
6598 # Retrieve the keyword that followed the EXIT keyword
6599 $keyword = $self->ivShow('parseDataHash', 'keyword');
6600 # Get the current subroutine
6601 $subObj = $self->scriptObj->returnCurrentSub();
6602  
6603 if ($keyword eq 'do' || $keyword eq 'while') {
6604  
6605 # Get the corresponding DO/WHILE statement from the current subroutine's code block
6606 # stack. Keep removing code blocks from the top of the stack until we get the right
6607 # one
6608 if (! $subObj->blockStackList) {
6609  
6610 # EXIT_DO_statement_without_matching_DO
6611 # EXIT_WHILE_statement_without_matching_WHILE
6612 return $self->scriptObj->setError(
6613 'EXIT_' . uc($keyword) . '_statement_without_matching_' . uc($keyword),
6614 $self->_objClass . '->implement',
6615 );
6616 }
6617  
6618 do {
6619 $matchStatement = $subObj->pop_blockStackList();
6620  
6621 # Check that it's a DO/WHILE statement - not the start of another kind of code block
6622 if ($matchStatement->keyword eq $keyword) {
6623  
6624 # We've found the statement we're looking for
6625 $exitFlag = TRUE;
6626 }
6627  
6628 } until ($exitFlag || ! $subObj->blockStackList);
6629  
6630 if (! $exitFlag) {
6631  
6632 # EXIT_DO_statement_without_matching_DO
6633 # EXIT_WHILE_statement_without_matching_WHILE
6634 return $self->scriptObj->setError(
6635 'EXIT_' . uc($keyword) . '_statement_without_matching_' . uc($keyword),
6636 $self->_objClass . '->implement',
6637 );
6638  
6639 } elsif ($keyword eq 'do') {
6640  
6641 # Get the DO statement's corresponding UNTIL statement
6642 $resumeStatement = $matchStatement->ivShow('parseDataHash', 'until_statement');
6643  
6644 } else {
6645  
6646 # Get the WHILE statement's corresponding LOOP statement
6647 $resumeStatement = $matchStatement->ivShow('parseDataHash', 'loop_statement');
6648 }
6649  
6650 } elsif ($keyword eq 'sub') {
6651  
6652 # EXIT SUB is interpreted exactly the same way as END SUB, except that EXIT SUB won't
6653 # cause an error at the ->parse stage if it doesn't match an earlier SUB statement
6654 if ($subObj->name eq '*main') {
6655  
6656 return $self->scriptObj->setError(
6657 'EXIT_SUB_statement_used_outside_subroutine',
6658 $self->_objClass . '->implement',
6659 );
6660 }
6661  
6662 # Execution resumes at the first statement after the one that called the subroutine
6663 $resumeStatement = $subObj->callStatement;
6664  
6665 # The subroutine's return value is 0 (for numeric) and '' (for strings). Set the return
6666 # variable, if there is one
6667 if (defined $subObj->returnVar) {
6668  
6669 if ($subObj->returnVarType eq 'numeric') {
6670 $subObj->returnVar->set(0);
6671 } else {
6672 $subObj->returnVar->set('');
6673 }
6674 }
6675  
6676 # Update the script's subroutine stack
6677 $self->scriptObj->popSubStack();
6678 }
6679  
6680 if ($resumeStatement) {
6681  
6682 # The next statement to execute is the statement after that
6683 if (defined $resumeStatement->nextStatement) {
6684  
6685 # LA::Script->nextStatement is currently set to this statement; continue execution
6686 # as if this were the Do/SUB/WHILE statement
6687 $self->scriptObj->set_nextStatement($resumeStatement);
6688  
6689 } else {
6690  
6691 $self->scriptObj->set_nextStatement(undef);
6692 $self->scriptObj->set_nextLine($resumeStatement->lineObj->procLineNum + 1);
6693 }
6694 }
6695  
6696 # Implementation complete
6697 return 1;
6698 }
6699 }
6700  
6701 { package Language::Axbasic::Statement::flashwin;
6702  
6703 use strict;
6704 use warnings;
6705 use diagnostics;
6706  
6707 use Glib qw(TRUE FALSE);
6708  
6709 @Language::Axbasic::Statement::flashwin::ISA = qw(
6710 Language::Axbasic
6711 Language::Axbasic::Statement
6712 );
6713  
6714 # FLASHWIN
6715  
6716 ##################
6717 # Methods
6718  
6719 sub parse {
6720  
6721 # Called by LA::Line->parse directly after a call to LA::Statement->new
6722 #
6723 # Expected arguments
6724 # (none besides $self)
6725 #
6726 # Return values
6727 # 'undef' on improper arguments or if there is an error
6728 # 1 otherwise
6729  
6730 my ($self, $check) = @_;
6731  
6732 # Local variables
6733 my ($expression);
6734  
6735 # Check for improper arguments
6736 if (defined $check) {
6737  
6738 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6739 }
6740  
6741 # FLASHWIN statements always appear on their own
6742 if (! $self->tokenGroupObj->testStatementEnd()) {
6743  
6744 return $self->scriptObj->setError(
6745 'unexpected_keywords,_operators_or_expressions',
6746 $self->_objClass . '->parse',
6747 );
6748 }
6749  
6750 # Parsing complete
6751 return 1;
6752 }
6753  
6754 sub implement {
6755  
6756 # Called by LA::Line->implement directly after a call to $self->parse
6757 #
6758 # Expected arguments
6759 # (none besides $self)
6760 #
6761 # Return values
6762 # 'undef' on improper arguments or if there is an error
6763 # 1 otherwise
6764  
6765 my ($self, $check) = @_;
6766  
6767 # Local variables
6768  
6769 # Check for improper arguments
6770 if (defined $check) {
6771  
6772 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6773 }
6774  
6775 # If the Axbasic script is being run from within an Axmud task and the task window is open,
6776 # set the window's urgency hint. Otherwise, do nothing
6777 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->winObj) {
6778  
6779 # Sets the window urgency hint
6780 $self->scriptObj->parentTask->winObj->setUrgent();
6781 }
6782  
6783 # Implementation complete
6784 return 1;
6785 }
6786 }
6787  
6788 { package Language::Axbasic::Statement::for;
6789  
6790 use strict;
6791 use warnings;
6792 use diagnostics;
6793  
6794 use Glib qw(TRUE FALSE);
6795  
6796 @Language::Axbasic::Statement::for::ISA = qw(
6797 Language::Axbasic
6798 Language::Axbasic::Statement
6799 );
6800  
6801 # FOR variable-name = expression TO expression [ STEP expression ]
6802 # FOR EACH variable-name IN variable-name
6803  
6804 ##################
6805 # Methods
6806  
6807 sub parse {
6808  
6809 # Called by LA::Line->parse directly after a call to LA::Statement->new
6810 #
6811 # Expected arguments
6812 # (none besides $self)
6813 #
6814 # Return values
6815 # 'undef' on improper arguments or if there is an error
6816 # 1 otherwise
6817  
6818 my ($self, $check) = @_;
6819  
6820 # Local variables
6821 my ($token, $lvalue, $initExp, $termExp, $stepExp, $newTokenGroup, $expression);
6822  
6823 # Check for improper arguments
6824 if (defined $check) {
6825  
6826 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6827 }
6828  
6829 # There are two formats for a FOR statement. Store the type, so $self->implement can
6830 # retrieve it
6831 $token = $self->tokenGroupObj->shiftMatchingToken('each');
6832 if (! defined $token) {
6833 $self->ivAdd('parseDataHash', 'each_flag', FALSE);
6834 } else {
6835 $self->ivAdd('parseDataHash', 'each_flag', TRUE);
6836 }
6837  
6838 # Read the iterator variable name
6839 $lvalue = Language::Axbasic::Expression::Lvalue->new(
6840 $self->scriptObj,
6841 $self->tokenGroupObj,
6842 );
6843  
6844 if (! defined $lvalue) {
6845  
6846 return $self->scriptObj->setError(
6847 'missing_or_illegal_iterator',
6848 $self->_objClass . '->parse',
6849 );
6850  
6851 } elsif (
6852 ! $self->ivShow('parseDataHash', 'each_flag')
6853 && $lvalue->isa('Language::Axbasic::Expression::String')
6854 ) {
6855 return $self->scriptObj->setError(
6856 'missing_or_illegal_iterator',
6857 $self->_objClass . '->parse',
6858 );
6859  
6860 } else {
6861  
6862 # Store the iterator, so $self->implement can retrieve it
6863 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
6864 }
6865  
6866 if (! $self->ivShow('parseDataHash', 'each_flag')) {
6867  
6868 # First type: FOR variable-name = expression TO expression [ STEP expression ]
6869  
6870 # Read the assignment operator
6871 $token = $self->tokenGroupObj->shiftMatchingToken('=');
6872 if (! defined $token) {
6873  
6874 return $self->scriptObj->setError(
6875 'missing_assignment_operator',
6876 $self->_objClass . '->parse',
6877 );
6878 }
6879  
6880 # Read the initialisation expression
6881 $initExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6882 $self->scriptObj,
6883 $self->tokenGroupObj,
6884 );
6885  
6886 if (! defined $initExp) {
6887  
6888 return $self->scriptObj->setError(
6889 'missing_or_illegal_expression',
6890 $self->_objClass . '->parse',
6891 );
6892  
6893 } else {
6894  
6895 # Store the initialisation expression, so $self->implement can retrieve it
6896 $self->ivAdd('parseDataHash', 'init_exp', $initExp);
6897 }
6898  
6899 # Read the 'to' keyword
6900 $token = $self->tokenGroupObj->shiftMatchingToken('to');
6901 if (! defined $token) {
6902  
6903 return $self->scriptObj->setError(
6904 'syntax_error',
6905 $self->_objClass . '->parse',
6906 );
6907 }
6908  
6909 # Until the keyword 'step', or the end of the statement, we're copying the termination
6910 # expression
6911 $termExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6912 $self->scriptObj,
6913 $self->tokenGroupObj,
6914 );
6915  
6916 if (! defined $termExp) {
6917  
6918 return $self->scriptObj->setError(
6919 'missing_or_illegal_expression',
6920 $self->_objClass . '->parse',
6921 );
6922  
6923 } else {
6924  
6925 # Store the initialisation expression, so $self->implement can retrieve it
6926 $self->ivAdd('parseDataHash', 'term_exp', $termExp);
6927 }
6928  
6929 # If there is anything left, it should be a 'step' keyword. If 'step' isn't specified,
6930 # use the default increment of +1
6931 $token = $self->tokenGroupObj->shiftMatchingToken('step');
6932 if (defined $token) {
6933  
6934 $stepExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6935 $self->scriptObj,
6936 $self->tokenGroupObj,
6937 );
6938  
6939 if (! defined $stepExp) {
6940  
6941 return $self->scriptObj->setError(
6942 'missing_or_illegal_expression',
6943 $self->_objClass . '->parse',
6944 );
6945  
6946 } else {
6947  
6948 # Store the step expression, so $self->implement can retrieve it
6949 $self->ivAdd('parseDataHash', 'step_exp', $stepExp);
6950 }
6951  
6952 } elsif (! $self->tokenGroupObj->testStatementEnd()) {
6953  
6954 # There shouldn't be anything after the 'step' expression
6955 return $self->scriptObj->setError(
6956 'unexpected_keywords,_operators_or_expressions',
6957 $self->_objClass . '->parse',
6958 );
6959  
6960 } else {
6961  
6962 # Create a separate token group to hold a token containing '1', and lex it, so we
6963 # can save the '1' as an expression
6964 $newTokenGroup = Language::Axbasic::TokenGroup->new($self->scriptObj, '1');
6965 $newTokenGroup->lex();
6966 $stepExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6967 $self->scriptObj,
6968 $newTokenGroup,
6969 );
6970  
6971 # Store the step expression, so $self->implement can retrieve it
6972 $self->ivAdd('parseDataHash', 'step_exp', $stepExp);
6973 }
6974  
6975 } else {
6976  
6977 # Second type: FOR EACH variable-name IN variable-name
6978  
6979 # Read the 'in' keyword
6980 $token = $self->tokenGroupObj->shiftMatchingToken('in');
6981 if (! defined $token) {
6982  
6983 return $self->scriptObj->setError(
6984 'syntax_error',
6985 $self->_objClass . '->parse',
6986 );
6987 }
6988  
6989 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
6990 # LA::Variable->lookup that we're intentionally referring to an array variable, such
6991 # as that created by
6992 # DIM var (10)
6993 # ...by a variable name that looks like a scalar, i.e.
6994 # SORT var
6995 $self->scriptObj->set_declareMode('simple');
6996  
6997 # Get the variable name
6998 $expression = Language::Axbasic::Expression::Lvalue->new(
6999 $self->scriptObj,
7000 $self->tokenGroupObj,
7001 );
7002  
7003 if (! defined $expression) {
7004  
7005 return $self->scriptObj->setError(
7006 'missing_or_illegal_array_variable',
7007 $self->_objClass . '->parse',
7008 );
7009 }
7010  
7011 # Reset the temporary IV
7012 $self->scriptObj->set_declareMode('default');
7013  
7014 if (! $self->tokenGroupObj->testStatementEnd()) {
7015  
7016 return $self->scriptObj->setError(
7017 'unexpected_keywords,_operators_or_expressions',
7018 $self->_objClass . '->parse',
7019 );
7020 }
7021  
7022 # Store the variable for ->implement to use
7023 $self->ivAdd('parseDataHash', 'array_exp', $expression);
7024 }
7025  
7026 # Parsing complete
7027 return 1;
7028 }
7029  
7030 sub implement {
7031  
7032 # Called by LA::Line->implement directly after a call to $self->parse
7033 #
7034 # Expected arguments
7035 # (none besides $self)
7036 #
7037 # Return values
7038 # 'undef' on improper arguments
7039 # 1 otherwise
7040  
7041 my ($self, $check) = @_;
7042  
7043 # Local variables
7044 my (
7045 $eachFlag, $lvalue, $initExp, $arrayExp, $result, $iterVar, $subObj, $elementVar,
7046 @indexList,
7047 );
7048  
7049 # Check for improper arguments
7050 if (defined $check) {
7051  
7052 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7053 }
7054  
7055 # Retrieve the variables stored by ->parse
7056 $eachFlag = $self->ivShow('parseDataHash', 'each_flag');
7057 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
7058 $initExp = $self->ivShow('parseDataHash', 'init_exp');
7059 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
7060  
7061 # Get the variable object for the iterator
7062 $iterVar = $lvalue->variable;
7063 if (! defined $iterVar) {
7064  
7065 return $self->scriptObj->setDebug(
7066 'Couldn\'t set up iterator in FOR statement',
7067 $self->_objClass . '->implement',
7068 );
7069 }
7070  
7071 # There are two formats for a FOR statement
7072 if (! $eachFlag) {
7073  
7074 # First type: FOR variable-name = expression TO expression [ STEP expression ]
7075  
7076 # Evaluate the initialisation expression, and set the iterator with the value
7077 $result = $initExp->evaluate();
7078 if (! defined $result) {
7079  
7080 return $self->scriptObj->setDebug(
7081 'Couldn\'t evaluate initialisation expression in FOR statement',
7082 $self->_objClass . '->implement',
7083 );
7084  
7085 } else {
7086  
7087 $iterVar->set($result);
7088 }
7089  
7090 } else {
7091  
7092 # Second type: FOR EACH variable-name IN variable-name
7093  
7094 # If the array is empty, then we can't iterate over it (and there's no way to jump to
7095 # the NEXT statement)
7096 if ((scalar $arrayExp->varObj->cellList) <= 1) {
7097  
7098 return $self->scriptObj->setError(
7099 'cannot_iterate_over_empty_array',
7100 $self->_objClass . '->implement',
7101 );
7102  
7103 } else {
7104  
7105 # Otherwise, Axbasic handles multi-dimensional arrays with lists inside lists. Each
7106 # list represents a dimension and contains the lower bound, followed by an
7107 # optional list of value. (In multi-dimensional arrays, all dimensions have at
7108 # least one value)
7109 # Create a list of indices, each referring to a value in a dimension. The ->getCell
7110 # function takes account of the first item in every dimension, which is the lower
7111 # bound, hence the minimum index for each dimension is 0
7112 for (my $i = 1; $i <= $arrayExp->varObj->dimCount; $i++) {
7113  
7114 push (@indexList, 0);
7115 }
7116  
7117 # The NEXT statement increments the array index/indices, until we reach the end of
7118 # the array
7119 $self->ivAdd('parseDataHash', 'index_list_ref', \@indexList);
7120  
7121 # Retrieve the variable that's the first element of the array, and set the iterator
7122 # with its value. Ignore the cell numbered 0 - FOR EACH assumes the first
7123 # significant cell is #1
7124 $elementVar = $arrayExp->varObj->getCell(@indexList);
7125 if (! $elementVar) {
7126  
7127 return $self->scriptObj->setError(
7128 'empty_array_in_FOR_EACH_statement',
7129 $self->_objClass . '->implement',
7130 );
7131  
7132 } else {
7133  
7134 $iterVar->set($elementVar->value);
7135 }
7136 }
7137 }
7138  
7139 # Add this 'for' statement to the code block stack for the current subroutine
7140 $subObj = $self->scriptObj->returnCurrentSub();
7141 $subObj->push_blockStackList($self);
7142  
7143 # Implementation complete
7144 return 1;
7145 }
7146 }
7147  
7148 { package Language::Axbasic::Statement::global;
7149  
7150 use strict;
7151 use warnings;
7152 use diagnostics;
7153  
7154 use Glib qw(TRUE FALSE);
7155  
7156 @Language::Axbasic::Statement::global::ISA = qw(
7157 Language::Axbasic
7158 Language::Axbasic::Statement
7159 );
7160  
7161 # GLOBAL variable-name [ , variable-name ... ]
7162  
7163 ##################
7164 # Methods
7165  
7166 sub parse {
7167  
7168 # Called by LA::Line->parse directly after a call to LA::Statement->new
7169 #
7170 # Expected arguments
7171 # (none besides $self)
7172 #
7173 # Return values
7174 # 'undef' on improper arguments or if there is an error
7175 # 1 otherwise
7176  
7177 my ($self, $check) = @_;
7178  
7179 # Local variables
7180 my ($token, $argListObj, $lvalue);
7181  
7182 # Check for improper arguments
7183 if (defined $check) {
7184  
7185 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7186 }
7187  
7188 # The 'global' keyword is not available in primitive numbering mode
7189 if ($self->scriptObj->executionMode ne 'no_line_num') {
7190  
7191 return $self->scriptObj->setError(
7192 'statement_not_available_with_line_numbers',
7193 $self->_objClass . '->parse',
7194 );
7195 }
7196  
7197 # Temporarily set the IV that allows undeclared variables to be created
7198 $self->scriptObj->set_declareMode('global_scalar');
7199  
7200 # Process each array in turn (if several appear on the same line, they are separated by
7201 # commas)
7202 do {
7203  
7204 $lvalue = Language::Axbasic::Expression::Lvalue->new(
7205 $self->scriptObj,
7206 $self->tokenGroupObj,
7207 );
7208  
7209 if (! defined $lvalue) {
7210  
7211 return $self->scriptObj->setError(
7212 'missing_or_illegal_variable',
7213 $self->_objClass . '->parse',
7214 );
7215 }
7216  
7217 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
7218  
7219 # Reset the temporary IV
7220 $self->scriptObj->set_declareMode('default');
7221  
7222 # Check there is nothing else (except for the statement separator, :)
7223 if (! defined $self->tokenGroupObj->testStatementEnd()) {
7224  
7225 return $self->scriptObj->setError(
7226 'unexpected_keywords,_operators_or_expressions',
7227 $self->_objClass . '->parse',
7228 );
7229 }
7230  
7231 # Parsing complete
7232 return 1;
7233 }
7234  
7235 # sub implement {} # No ->implement method - LA::Variable->lookup has already added the
7236 # variable to LA::Script->globalScalarHash or ->globalArrayHash
7237 }
7238  
7239 { package Language::Axbasic::Statement::gosub;
7240  
7241 use strict;
7242 use warnings;
7243 use diagnostics;
7244  
7245 use Glib qw(TRUE FALSE);
7246  
7247 @Language::Axbasic::Statement::gosub::ISA = qw(
7248 Language::Axbasic
7249 Language::Axbasic::Statement
7250 );
7251  
7252 # GOSUB expression
7253  
7254 ##################
7255 # Methods
7256  
7257 sub parse {
7258  
7259 # Called by LA::Line->parse directly after a call to LA::Statement->new
7260 #
7261 # Expected arguments
7262 # (none besides $self)
7263 #
7264 # Return values
7265 # 'undef' on improper arguments or if there is an error
7266 # 1 otherwise
7267  
7268 my ($self, $check) = @_;
7269  
7270 # Local variables
7271 my $expression;
7272  
7273 # Check for improper arguments
7274 if (defined $check) {
7275  
7276 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7277 }
7278  
7279 # The 'gosub' keyword is only available in primitive numbering mode
7280 if ($self->scriptObj->executionMode ne 'line_num') {
7281  
7282 return $self->scriptObj->setError(
7283 'statement_not_available_without_line_numbers',
7284 $self->_objClass . '->parse',
7285 );
7286 }
7287  
7288 # The rest of the statement is an expression for the line to call
7289 $expression = Language::Axbasic::Expression::Arithmetic->new(
7290 $self->scriptObj,
7291 $self->tokenGroupObj,
7292 );
7293  
7294 if (! defined $expression) {
7295  
7296 return $self->scriptObj->setError(
7297 'missing_or_illegal_expression',
7298 $self->_objClass . '->parse',
7299 );
7300 }
7301  
7302 # Check that nothing follows the expression
7303 if (! $self->tokenGroupObj->testStatementEnd()) {
7304  
7305 return $self->scriptObj->setError(
7306 'unexpected_keywords,_operators_or_expression',
7307 $self->_objClass . '->parse',
7308 );
7309 }
7310  
7311 # Store the gosub expression, so $self->implement can retrieve it
7312 $self->ivAdd('parseDataHash', 'expression', $expression);
7313  
7314 # Parsing complete
7315 return 1;
7316 }
7317  
7318 sub implement {
7319  
7320 # Called by LA::Line->implement directly after a call to $self->parse
7321 #
7322 # Expected arguments
7323 # (none besides $self)
7324 #
7325 # Return values
7326 # 'undef' on improper arguments
7327 # 1 otherwise
7328  
7329 my ($self, $check) = @_;
7330  
7331 # Local variables
7332 my ($expression, $lineNumber);
7333  
7334 # Check for improper arguments
7335 if (defined $check) {
7336  
7337 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7338 }
7339  
7340 # Retrieve the variable stored by ->parse
7341 $expression = $self->ivShow('parseDataHash', 'expression');
7342  
7343 # Evaluate the expression to get the line number (because $expression could be 'x+17/3' as
7344 # well as '20')
7345 $lineNumber = $expression->evaluate();
7346 if (! defined $lineNumber || ! ($lineNumber =~ /^\d+$/)) {
7347  
7348 return $self->scriptObj->setError(
7349 'illegal_line_number_NUM',
7350 $self->_objClass . '->implement',
7351 'NUM', $lineNumber,
7352 );
7353 }
7354  
7355 # Check that the primitive line number exists
7356 if (! $self->scriptObj->ivExists('primLineHash', $lineNumber)) {
7357  
7358 return $self->scriptObj->setError(
7359 'line_number_NUM_not_found',
7360 $self->_objClass . '->implement',
7361 'NUM', $lineNumber,
7362 );
7363  
7364 } else {
7365  
7366 # Push the current statement onto the GOSUB stack
7367 $self->scriptObj->push_gosubStackList($self);
7368  
7369 # The line in the expression is the next line to be executed
7370 $self->scriptObj->set_nextLine($self->scriptObj->ivShow('primLineHash', $lineNumber));
7371  
7372 $self->scriptObj->set_nextStatement(undef);
7373 }
7374  
7375 # Implementation complete
7376 return 1;
7377 }
7378 }
7379  
7380 { package Language::Axbasic::Statement::goto;
7381  
7382 use strict;
7383 use warnings;
7384 use diagnostics;
7385  
7386 use Glib qw(TRUE FALSE);
7387  
7388 @Language::Axbasic::Statement::goto::ISA = qw(
7389 Language::Axbasic
7390 Language::Axbasic::Statement
7391 );
7392  
7393 # GOTO expression
7394  
7395 ##################
7396 # Methods
7397  
7398 sub parse {
7399  
7400 # Called by LA::Line->parse directly after a call to LA::Statement->new
7401 #
7402 # Expected arguments
7403 # (none besides $self)
7404 #
7405 # Return values
7406 # 'undef' on improper arguments or if there is an error
7407 # 1 otherwise
7408  
7409 my ($self, $check) = @_;
7410  
7411 # Local variables
7412 my $expression;
7413  
7414 # Check for improper arguments
7415 if (defined $check) {
7416  
7417 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7418 }
7419  
7420 # The 'goto' keyword is only available in primitive numbering mode
7421 if ($self->scriptObj->executionMode ne 'line_num') {
7422  
7423 return $self->scriptObj->setError(
7424 'statement_not_available_without_line_numbers',
7425 $self->_objClass . '->parse',
7426 );
7427 }
7428  
7429 # The rest of the statement is an expression for the line to go to
7430 $expression = Language::Axbasic::Expression::Arithmetic->new(
7431 $self->scriptObj,
7432 $self->tokenGroupObj,
7433 );
7434  
7435 if (! defined $expression) {
7436  
7437 return $self->scriptObj->setError(
7438 'missing_or_illegal_expression ',
7439 $self->_objClass . '->parse',
7440 );
7441 }
7442  
7443 # Check that nothing follows the expression
7444 if (! $self->tokenGroupObj->testStatementEnd()) {
7445  
7446 return $self->scriptObj->setError(
7447 'unexpected_keywords,_operators_or_expressions',
7448 $self->_objClass . '->parse',
7449 );
7450 }
7451  
7452 # Store the arithmetic expression, so $self->implement can retrieve it
7453 $self->ivAdd('parseDataHash', 'expression', $expression);
7454  
7455 # Parsing complete
7456 return 1;
7457 }
7458  
7459 sub implement {
7460  
7461 # Called by LA::Line->implement directly after a call to $self->parse
7462 #
7463 # Expected arguments
7464 # (none besides $self)
7465 #
7466 # Return values
7467 # 'undef' on improper arguments
7468 # 1 otherwise
7469  
7470 my ($self, $check) = @_;
7471  
7472 # Local variables
7473 my ($expression, $lineNumber);
7474  
7475 # Check for improper arguments
7476 if (defined $check) {
7477  
7478 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7479 }
7480  
7481 # Retrieve the variable stored by ->parse
7482 $expression = $self->ivShow('parseDataHash', 'expression');
7483  
7484 # Evaluate the expression to get the line number (because $expression could be 'x+17/3' as
7485 # well as '20')
7486 $lineNumber = $expression->evaluate();
7487 if (! defined $lineNumber || ! ($lineNumber =~ /^\d+$/)) {
7488  
7489 return $self->scriptObj->setError(
7490 'illegal_line_number_NUM',
7491 $self->_objClass . '->implement',
7492 'NUM', $lineNumber,
7493 );
7494 }
7495  
7496 # Check that the primitive line number exists
7497 if (! $self->scriptObj->ivExists('primLineHash', $lineNumber)) {
7498  
7499 return $self->scriptObj->setError(
7500 'line_number_NUM_not_found',
7501 $self->_objClass . '->implement',
7502 'NUM', $lineNumber,
7503 );
7504  
7505 } else {
7506  
7507 # That's the next line to be executed
7508 $self->scriptObj->set_nextLine(
7509 $self->scriptObj->ivShow('primLineHash', $lineNumber),
7510 );
7511 $self->scriptObj->set_nextStatement(undef);
7512 }
7513  
7514 # Implementation complete
7515 return 1;
7516 }
7517 }
7518  
7519 { package Language::Axbasic::Statement::help;
7520  
7521 use strict;
7522 use warnings;
7523 use diagnostics;
7524  
7525 use Glib qw(TRUE FALSE);
7526  
7527 @Language::Axbasic::Statement::help::ISA = qw(
7528 Language::Axbasic
7529 Language::Axbasic::Statement
7530 );
7531  
7532 # HELP
7533 # HELP expression
7534  
7535 ##################
7536 # Methods
7537  
7538 sub parse {
7539  
7540 # Called by LA::Line->parse directly after a call to LA::Statement->new
7541 #
7542 # Expected arguments
7543 # (none besides $self)
7544 #
7545 # Return values
7546 # 'undef' on improper arguments or if there is an error
7547 # 1 otherwise
7548  
7549 my ($self, $check) = @_;
7550  
7551 # Local variables
7552 my $expression;
7553  
7554 # Check for improper arguments
7555 if (defined $check) {
7556  
7557 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7558 }
7559  
7560 if ($self->tokenGroupObj->testStatementEnd()) {
7561  
7562 # HELP
7563  
7564 $self->ivAdd('parseDataHash', 'expression', undef);
7565  
7566 } else {
7567  
7568 # HELP Expression
7569  
7570 # Get the expression and store it for ->implement to use.
7571 $expression = Language::Axbasic::Expression::Arithmetic->new(
7572 $self->scriptObj,
7573 $self->tokenGroupObj,
7574 );
7575  
7576 if (! defined $expression) {
7577  
7578 return $self->scriptObj->setError(
7579 'missing_or_illegal_expression ',
7580 $self->_objClass . '->parse',
7581 );
7582  
7583 } else {
7584  
7585 $self->ivAdd('parseDataHash', 'expression', $expression);
7586 }
7587  
7588 # There should be nothing after the expression
7589 if (! $self->tokenGroupObj->testStatementEnd()) {
7590  
7591 return $self->scriptObj->setError(
7592 'unexpected_keywords,_operators_or_expressions',
7593 $self->_objClass . '->parse',
7594 );
7595 }
7596 }
7597  
7598 # Parsing complete
7599 return 1;
7600 }
7601  
7602 sub implement {
7603  
7604 # Called by LA::Line->implement directly after a call to $self->parse
7605 #
7606 # Expected arguments
7607 # (none besides $self)
7608 #
7609 # Return values
7610 # 'undef' on improper arguments or if there is an error
7611 # 1 otherwise
7612  
7613 my ($self, $check) = @_;
7614  
7615 # Local variables
7616 my ($expression, $topic);
7617  
7618 # Check for improper arguments
7619 if (defined $check) {
7620  
7621 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7622 }
7623  
7624 # Retrieve the expression to be displayed
7625 $expression = $self->ivShow('parseDataHash', 'expression');
7626 if (! defined $expression) {
7627  
7628 # 'HELP' is the same as the client command ';axbasichelp'
7629 $self->scriptObj->session->pseudoCmd('axbasichelp', $self->scriptObj->pseudoCmdMode);
7630  
7631 } else {
7632  
7633 # 'HELP Expression' is the same as the client command ';axbasichelp <topic>'
7634 $topic = $expression->evaluate();
7635 $self->scriptObj->session->pseudoCmd(
7636 'axbasichelp <' . $topic . '>',
7637 $self->scriptObj->pseudoCmdMode,
7638 );
7639 }
7640  
7641 # Implementation complete
7642 return 1;
7643 }
7644 }
7645  
7646 { package Language::Axbasic::Statement::if;
7647  
7648 use strict;
7649 use warnings;
7650 use diagnostics;
7651  
7652 use Glib qw(TRUE FALSE);
7653  
7654 @Language::Axbasic::Statement::if::ISA = qw(
7655 Language::Axbasic
7656 Language::Axbasic::Statement
7657 );
7658  
7659 # IF condition THEN statement [ : statement ...] [ ELSE statement [ : statement ...]]
7660 # IF condition THEN statement [ : statement ...] [ ELSEIF condition [ : statement ...]]
7661 # IF condition THEN expression [ ELSE expression ]
7662 #
7663 # IF condition THEN
7664 # statement
7665 # statement
7666 # ELSE IF condition THEN
7667 # statement
7668 # ELSEIF condition THEN
7669 # statement
7670 # ELSE
7671 # statement
7672 # END IF
7673  
7674 ##################
7675 # Methods
7676  
7677 sub parse {
7678  
7679 # Called by LA::Line->parse directly after a call to LA::Statement->new
7680 #
7681 # Expected arguments
7682 # (none besides $self)
7683 #
7684 # Return values
7685 # 'undef' on improper arguments or if there is an error
7686 # 1 otherwise
7687  
7688 my ($self, $check) = @_;
7689  
7690 # Local variables
7691 my (
7692 $condition, $newTokenGroup, $previousStatement, $thenStatement, $elseStatement,
7693 $otherStatement, $subObj, $token,
7694 );
7695  
7696 # Check for improper arguments
7697 if (defined $check) {
7698  
7699 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7700 }
7701  
7702 # Everything up until 'then' is a conditional expression
7703 $condition = Language::Axbasic::Expression::LogicalOr->new(
7704 $self->scriptObj,
7705 $self->tokenGroupObj,
7706 );
7707  
7708 if (! defined $condition) {
7709  
7710 return $self->scriptObj->setError(
7711 'missing_or_illegal_conditional_expression',
7712 $self->_objClass . '->parse',
7713 );
7714  
7715 } else {
7716  
7717 # Store the condition expression, so $self->implement can retrieve it
7718 $self->ivAdd('parseDataHash', 'condition', $condition);
7719 }
7720  
7721 if (! defined $self->tokenGroupObj->shiftMatchingToken('then')) {
7722  
7723 return $self->scriptObj->setError(
7724 'syntax_error',
7725 $self->_objClass . '->parse',
7726 );
7727 }
7728  
7729 # Everything up until 'else' or the end of the line is one or more statements to do if the
7730 # 'if' condition is true
7731 if (! defined $self->tokenGroupObj->lookAhead()) {
7732  
7733 # This statement is the start of a multi-line IF..END IF code block
7734 # Add it to the IF code block stack for the current subroutine
7735 $subObj = $self->scriptObj->returnCurrentSub();
7736 $subObj->push_ifStackList($self);
7737  
7738 # We don't know where the corresponding END IF statement is yet
7739 $self->ivAdd('parseDataHash', 'end_if_statement', undef);
7740  
7741 } else {
7742  
7743 # Import all the tokens until the ELSE or ELSEIF statement (if there is no ELSE of ELSE
7744 # IF, just import all the tokens)
7745 $newTokenGroup = Language::Axbasic::TokenGroup->new($self->scriptObj);
7746 $newTokenGroup->importTokens($self->tokenGroupObj, 'else', 'elseif');
7747  
7748 # Create a new statement to parse the 'then' clause, and parse the statement
7749 # 'line_num_ok' tells the new statement that it's parsing a 'then/else', so that
7750 # 'then 20' is parsed like 'then goto 20'
7751 $thenStatement = Language::Axbasic::Statement->new(
7752 $self->scriptObj,
7753 $self->lineObj,
7754 $newTokenGroup,
7755 'line_num_ok',
7756 );
7757  
7758 if (! defined $thenStatement) {
7759  
7760 return $self->scriptObj->setError(
7761 'syntax_error',
7762 $self->_objClass . '->parse',
7763 );
7764  
7765 } else {
7766  
7767 $thenStatement->parse();
7768 $previousStatement = $thenStatement;
7769 }
7770  
7771 # Deal with [: Statement]
7772 while (defined ($newTokenGroup->shiftTokenIfCategory('statement_end'))) {
7773  
7774 # A plain line number, like 'then 20', is only allowed in the first 'then/else'
7775 # statement
7776 $otherStatement = Language::Axbasic::Statement->new(
7777 $self->scriptObj,
7778 $self->lineObj,
7779 $newTokenGroup,
7780 );
7781  
7782 $otherStatement->parse();
7783 $previousStatement->set_nextStatement($otherStatement);
7784 $previousStatement = $otherStatement;
7785 }
7786  
7787 # Make sure we don't do the 'else' after the 'then'!
7788 $previousStatement->set_nextStatement(undef);
7789  
7790 # If there is anything left in $self->tokenGroup, it's the ELSE / ELSEIF clause
7791 # If we find an initial ELSEIF token, the following code is much simpler if we pretend
7792 # that it was two tokens, ELSE and IF
7793 $token = $self->tokenGroupObj->shiftMatchingToken('else');
7794 if (! defined $token) {
7795  
7796 $token = $self->tokenGroupObj->lookAhead();
7797 if (defined $token && $token->tokenText eq 'elseif') {
7798  
7799 # Pretend we have shifted an ELSE token, and convert the first remaining token
7800 # to an IF
7801 $token->set_tokenText('if');
7802  
7803 } else {
7804  
7805 $token = undef;
7806 }
7807 }
7808  
7809 if (defined $token) {
7810  
7811 # Use up all the remaining tokens
7812 $elseStatement = Language::Axbasic::Statement->new(
7813 $self->scriptObj,
7814 $self->lineObj,
7815 $self->tokenGroupObj,
7816 'line_num_ok',
7817 );
7818  
7819 if (! defined $elseStatement) {
7820  
7821 return $self->scriptObj->setError(
7822 'syntax_error',
7823 $self->_objClass . '->parse',
7824 );
7825  
7826 } else {
7827  
7828 $elseStatement->parse();
7829 $previousStatement = $elseStatement;
7830 }
7831  
7832 while (defined($self->tokenGroupObj->shiftTokenIfCategory('statement_end'))) {
7833  
7834 $otherStatement = Language::Axbasic::Statement->new(
7835 $self->scriptObj,
7836 $self->lineObj,
7837 $self->tokenGroupObj,
7838 );
7839  
7840 $otherStatement->parse();
7841 $previousStatement->set_nextStatement($otherStatement);
7842 $previousStatement = $otherStatement;
7843 }
7844  
7845 $previousStatement->set_nextStatement(undef);
7846  
7847 if (! $self->tokenGroupObj->testStatementEnd()) {
7848  
7849 return $self->scriptObj->setError(
7850 'unexpected_keywords,_operators_or_expressions',
7851 $self->_objClass . '->parse',
7852 )
7853 }
7854  
7855 } elsif (! $self->tokenGroupObj->testStatementEnd()) {
7856  
7857 return $self->scriptObj->setError(
7858 'unexpected_keywords,_operators_or_expressions',
7859 $self->_objClass . '->parse',
7860 )
7861 }
7862  
7863 # Save the 'then' and 'else' statements, so ->implement can retrieve them
7864 $self->ivAdd('parseDataHash', 'then_statement', $thenStatement);
7865 $self->ivAdd('parseDataHash', 'else_statement', $elseStatement);
7866 }
7867  
7868 # Parsing complete
7869 return 1;
7870 }
7871  
7872 sub implement {
7873  
7874 # Called by LA::Line->implement directly after a call to $self->parse
7875 #
7876 # Expected arguments
7877 # (none besides $self)
7878 #
7879 # Return values
7880 # 'undef' on improper arguments
7881 # 1 otherwise
7882  
7883 my ($self, $check) = @_;
7884  
7885 # Local variables
7886 my (
7887 $subObj, $thenStatement, $elseStatement, $condition, $endIfStatement, $nextStatement,
7888 @statementList,
7889 );
7890  
7891 # Check for improper arguments
7892 if (defined $check) {
7893  
7894 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7895 }
7896  
7897 # Retrieve the stored data
7898 $thenStatement = $self->ivShow('parseDataHash', 'then_statement');
7899 $elseStatement = $self->ivShow('parseDataHash', 'else_statement');
7900  
7901 # Single-line IF..THEN..ELSE statement
7902 if ($thenStatement) {
7903  
7904 $condition = $self->ivShow('parseDataHash', 'condition');
7905  
7906 # Decide which statement should be executed next, depending on whether the $condition is
7907 # true, or not
7908 if ($condition->evaluate()) {
7909  
7910 # Execute the 'then' statement (which always exists)
7911 $self->ivPoke('nextStatement', $thenStatement);
7912  
7913 } else {
7914  
7915 # Execute the 'else' statement (if it exists), or just continue on to the next
7916 # statement in the script (if it doesn't)
7917 $self->ivPoke('nextStatement', $elseStatement);
7918 }
7919  
7920 # Multi-line IF..END IF statement
7921 } else {
7922  
7923 # (Any ELSE IF statements are stored in $self->parseDataList)
7924  
7925 # Find the ELSE statement, if there is one
7926 $elseStatement = $self->ivShow('parseDataHash', 'else_statement');
7927 # Find the END IF statement
7928 $endIfStatement = $self->ivShow('parseDataHash', 'end_if_statement');
7929  
7930 # Compile a list of conditions to evaluate, starting with the one in the
7931 # current statement, followed by all the ELSE IF statements
7932 @statementList = ($self, $self->parseDataList);
7933  
7934 # Evaluate each condition, looking for the first one which evaluates to
7935 # 'true'
7936 OUTER: foreach my $statement (@statementList) {
7937  
7938 my $cond = $statement->ivShow('parseDataHash', 'condition');
7939  
7940 if ($cond->evaluate()) {
7941  
7942 $nextStatement = $statement;
7943 last OUTER;
7944 }
7945 }
7946  
7947 if (! $nextStatement && $elseStatement) {
7948  
7949 # The conditions in IF and ELSE IF are all false, but there is an
7950 # ELSE clause, so use it
7951 $nextStatement = $elseStatement;
7952 }
7953  
7954 if (! $nextStatement) {
7955  
7956 # All conditions are false (and there is no ELSE clause), so we need to skip to the
7957 # end of the IF..END IF code block
7958 if (defined $endIfStatement->nextStatement) {
7959  
7960 # LA::Script->nextStatement is currently set to this statement; continue
7961 # execution as if this were the END statement
7962 $self->scriptObj->set_nextStatement($endIfStatement);
7963  
7964 } else {
7965  
7966 $self->scriptObj->set_nextStatement(undef);
7967 $self->scriptObj->set_nextLine($endIfStatement->lineObj->procLineNum + 1);
7968 }
7969  
7970 } else {
7971  
7972 # Add this IF..END IF code block to the main code block stack, since we're going
7973 # to execute it now. The corresponding END IF statement will remove it.
7974 $subObj = $self->scriptObj->returnCurrentSub();
7975 $subObj->push_blockStackList($self);
7976  
7977 if (defined $nextStatement->nextStatement) {
7978  
7979 # LA::Script->nextStatement is currently set to this statement; continue
7980 # execution as if this were the ELSE statement
7981 $self->scriptObj->set_nextStatement($nextStatement);
7982  
7983 } else {
7984  
7985 $self->scriptObj->set_nextStatement(undef);
7986 $self->scriptObj->set_nextLine($nextStatement->lineObj->procLineNum + 1);
7987 }
7988 }
7989 }
7990  
7991 return 1;
7992 }
7993 }
7994  
7995 { package Language::Axbasic::Statement::input;
7996  
7997 use strict;
7998 use warnings;
7999 use diagnostics;
8000  
8001 use Glib qw(TRUE FALSE);
8002  
8003 @Language::Axbasic::Statement::input::ISA = qw(
8004 Language::Axbasic
8005 Language::Axbasic::Statement
8006 );
8007  
8008 # INPUT [ constant ; ] variable-name [ , variable-name ... ]
8009 # INPUT #channel: variable-name [ , variable-name ... ]
8010  
8011 ##################
8012 # Methods
8013  
8014 sub parse {
8015  
8016 # Called by LA::Line->parse directly after a call to LA::Statement->new
8017 #
8018 # Expected arguments
8019 # (none besides $self)
8020 #
8021 # Return values
8022 # 'undef' on improper arguments or if there is an error
8023 # 1 otherwise
8024  
8025 my ($self, $check) = @_;
8026  
8027 # Local variables
8028 my (
8029 $token, $channel, $promptExp,
8030 @lvalueList,
8031 );
8032  
8033 # Check for improper arguments
8034 if (defined $check) {
8035  
8036 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8037 }
8038  
8039 # First token can be a constant, a file channel or the first of the variable names
8040 $token = $self->tokenGroupObj->lookAhead();
8041 if (! defined $token) {
8042  
8043 return $self->scriptObj->setError(
8044 'syntax_error',
8045 $self->_objClass . '->parse',
8046 );
8047  
8048 # Get the file channel, if specified
8049 } elsif ($token->category eq 'file_channel') {
8050  
8051 $self->tokenGroupObj->shiftToken();
8052  
8053 # For INPUT statements, the file channel must include a colon at the end (e.g. '#5:' )
8054 if (! ($token->tokenText =~ m/\:$/)) {
8055  
8056 return $self->scriptObj->setError(
8057 'syntax_error',
8058 $self->_objClass . '->parse',
8059 );
8060 }
8061  
8062 # Get the channel number
8063 $token->tokenText =~ m/([0-9]+)/;
8064 $channel = $1;
8065  
8066 # True BASIC specifies that the channel must be in the range 1-999; same range used by
8067 # Axbasic
8068 if ($channel < 1 || $channel > 999) {
8069  
8070 return $self->scriptObj->setError(
8071 'file_channel_NUM_out_of_range',
8072 $self->_objClass . '->parse',
8073 'NUM', $channel,
8074 );
8075  
8076 } else {
8077  
8078 # Store the channel number; this also informs $self->implement that we're reading
8079 # from a file, not the user's keyboard
8080 $self->ivAdd('parseDataHash', 'channel', $channel);
8081 }
8082  
8083 # Get the optional prompt text, if specified
8084 } elsif ($token->category eq 'string_constant') {
8085  
8086 # A text prompt was specified - it requires either a following comma or semicolon
8087 $promptExp = Language::Axbasic::Expression::Constant::String->new(
8088 $self->scriptObj,
8089 $self->tokenGroupObj,
8090 );
8091  
8092 if (! defined $self->tokenGroupObj->shiftMatchingToken(';')) {
8093  
8094 return $self->scriptObj->setError(
8095 'missing_separator_after_INPUT_prompt',
8096 $self->_objClass . '->parse',
8097 );
8098 }
8099 }
8100  
8101 # The rest of the arguments are variable names, separated by commas
8102 do {
8103  
8104 my $expression = Language::Axbasic::Expression::Lvalue->new(
8105 $self->scriptObj,
8106 $self->tokenGroupObj,
8107 );
8108  
8109 if (! defined $expression) {
8110  
8111 return $self->scriptObj->setError(
8112 'missing_or_illegal_variable',
8113 $self->_objClass . '->parse',
8114 );
8115  
8116 } else {
8117  
8118 push (@lvalueList, $expression);
8119 }
8120  
8121 } until (! defined $self->tokenGroupObj->shiftMatchingToken(','));
8122  
8123 # Save the components so that $self->implement can retrieve them
8124 $self->ivAdd('parseDataHash', 'prompt_exp', $promptExp);
8125 $self->ivPush('parseDataList', @lvalueList);
8126  
8127 # Parsing complete
8128 return 1;
8129 }
8130  
8131 sub implement {
8132  
8133 # Called by LA::Line->implement directly after a call to $self->parse
8134 #
8135 # Expected arguments
8136 # (none besides $self)
8137 #
8138 # Return values
8139 # 'undef' on improper arguments or if there is an error
8140 # 1 otherwise
8141  
8142 my ($self, $check) = @_;
8143  
8144 # Local variables
8145 my (
8146 $channel, $channelObj, $fileHandle, $promptExp, $prompt, $taskObj,
8147 @lvalueList,
8148 );
8149  
8150 # Check for improper arguments
8151 if (defined $check) {
8152  
8153 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8154 }
8155  
8156 # Retrieve the components stored by $self->parse
8157 $channel = $self->ivShow('parseDataHash', 'channel');
8158 $promptExp = $self->ivShow('parseDataHash', 'prompt_exp');
8159 @lvalueList = $self->parseDataList;
8160  
8161 # Deal with reading from a file, if a file channel was specified
8162 if (defined $channel) {
8163  
8164 # Check that the file channel exists
8165 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
8166  
8167 return $self->scriptObj->setError(
8168 'file_channel_NUM_not_open',
8169 $self->_objClass . '->implement',
8170 'NUM', $channel,
8171 );
8172  
8173 } else {
8174  
8175 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
8176 $fileHandle = $channelObj->fileHandle;
8177 }
8178  
8179 # Check that reading from the file channel is allowed
8180 if ($channelObj->accessType eq 'output') {
8181  
8182 return $self->scriptObj->setError(
8183 'file_channel_NUM_is_write_only',
8184 $self->_objClass . '->implement',
8185 'NUM', $channel,
8186 );
8187 }
8188  
8189 # Check that the pointer hasn't already reached end-of-file
8190 if (eof($fileHandle)) {
8191  
8192 return $self->scriptObj->setError(
8193 'end_of_file_on_channel_NUM',
8194 $self->_objClass . '->implement',
8195 'NUM', $channel,
8196 );
8197 }
8198  
8199 # Read a file line for each value expected
8200 for (my $count = 0; $count < scalar @lvalueList; $count++) {
8201  
8202 my ($lvalue, $varObj, $line);
8203  
8204 $lvalue = $lvalueList[$count];
8205 $varObj = $lvalue->variable;
8206 if (! $varObj) {
8207  
8208 # Subscript out of bounds, or similar error, has already been set
8209 return undef;
8210 }
8211  
8212 # Read a line from the file
8213 $line = <$fileHandle>;
8214 chomp $line;
8215  
8216 if (! defined $line) {
8217  
8218 return $self->scriptObj->setError(
8219 'end_of_file_on_channel_NUM',
8220 $self->_objClass . '->implement',
8221 'NUM', $channel,
8222 );
8223  
8224 } else {
8225  
8226 # Set the variable
8227 if ($line) {
8228  
8229 $varObj->set($line);
8230  
8231 } else {
8232  
8233 if (ref($varObj) =~ m/Numeric/) {
8234 $varObj->set(0);
8235 } else {
8236 $varObj->set('');
8237 }
8238 }
8239 }
8240 }
8241  
8242 } else {
8243  
8244 # Otherwise, we're reading from the user's keyboard. Evaluate the prompt expression (if
8245 # there is one)
8246 if ($promptExp) {
8247  
8248 $prompt = $promptExp->evaluate();
8249 }
8250  
8251 # Import the parent task (if any)
8252 $taskObj = $self->scriptObj->parentTask;
8253  
8254 # If the task window is open and an entry box is available, use that window to get the
8255 # input. Otherwise, open 'dialogue' windows to get the input
8256 if ($taskObj && $taskObj->taskWinEntryFlag) {
8257  
8258 # Display the prompt text, if it exists; if it doesn't, we must still display a
8259 # question mark, because many BASIC scripts use a format like
8260 # 10 print "tell me";
8261 # 20 input a$
8262 # ...which forces Axmud to display unrelated text on the same line as the prompt
8263 if ($prompt) {
8264 $taskObj->insertPrint($prompt . '? ');
8265 } else {
8266 $taskObj->insertPrint('? ');
8267 }
8268  
8269 # Tell the script object how many lines of input to expect
8270 $self->scriptObj->set_inputList(@lvalueList);
8271  
8272 # Mark this script as 'waiting for INPUT' - it will be resumed automatically when
8273 # the user types in the task window's entry box
8274 $self->scriptObj->set_scriptStatus('wait_input');
8275  
8276 } else {
8277  
8278 # Display the prompt text, if it exists; if it doesn't, we must still display a
8279 # question mark, because many BASIC scripts use a format like
8280 # 10 print "tell me";
8281 # 20 input a$
8282 # ...which forces Axmud to display unrelated text on the same line as the prompt
8283 # NB The prompt is displayed both in the dialogue box, and also in the 'main' or
8284 # task window
8285 if ($taskObj && $taskObj->taskWinFlag) {
8286  
8287 if ($prompt) {
8288 $taskObj->insertPrint($prompt . '? ');
8289 } else {
8290 $taskObj->insertPrint('? ');
8291 }
8292  
8293 } else {
8294  
8295 if ($prompt) {
8296 $self->scriptObj->session->writeText($prompt . '? ', 'echo');
8297 } else {
8298 $self->scriptObj->session->writeText('? ', 'echo');
8299 }
8300 }
8301  
8302 # Use dialogue boxes - one for each value expected
8303 for (my $count = 0; $count < scalar @lvalueList; $count++) {
8304  
8305 my ($lvalue, $varObj, $msg, $result);
8306  
8307 $lvalue = $lvalueList[$count];
8308 $varObj = $lvalue->variable;
8309 if (! $varObj) {
8310  
8311 # Subscript out of bounds, or similar error, has already been set
8312 return undef;
8313 }
8314  
8315 if ($prompt) {
8316 $msg = $prompt . '?';
8317 } else {
8318 $msg = 'Value?';
8319 }
8320  
8321 if (scalar @lvalueList > 1) {
8322  
8323 $msg .= ' (' . ($count + 1) . '/' . scalar @lvalueList . ')';
8324 }
8325  
8326 # Open a 'dialogue' window to allow the user to input a value
8327 $result = $self->scriptObj->session->mainWin->showEntryDialogue(
8328 'Axbasic INPUT (' . $self->scriptObj->name . ')',
8329 $msg,
8330 );
8331  
8332 if (! defined $result) {
8333  
8334 # User clicked 'cancel' or closed the window
8335 if (! $taskObj || ! $taskObj->taskWinFlag) {
8336  
8337 $self->scriptObj->session->writeText(' '); # Cancel the earlier 'echo'
8338 }
8339  
8340 return $self->scriptObj->setError(
8341 'user_declined_input_error',
8342 $self->_objClass . '->implement',
8343 );
8344  
8345 } elsif ($result) {
8346  
8347 # Set the variable
8348 $varObj->set($result);
8349  
8350 # Also display it in the 'main' / task window
8351 if ($taskObj && $taskObj->taskWinFlag) {
8352 $taskObj->insertPrint($result, 'echo');
8353 } else {
8354 $self->scriptObj->session->writeText($result);
8355 }
8356  
8357 } else {
8358  
8359 # No value entered, so use a null value
8360 if (ref($varObj) =~ m/Numeric/) {
8361 $varObj->set(0);
8362 } else {
8363 $varObj->set('');
8364 }
8365  
8366 # Cancel the earlier 'echo' in the 'main' window
8367 if (! $taskObj || ! $taskObj->taskWinFlag) {
8368  
8369 $self->scriptObj->session->writeText(' ');
8370 }
8371 }
8372 }
8373 }
8374 }
8375  
8376 # Implementation complete
8377 return 1;
8378 }
8379 }
8380  
8381 { package Language::Axbasic::Statement::let;
8382  
8383 use strict;
8384 use warnings;
8385 use diagnostics;
8386  
8387 use Glib qw(TRUE FALSE);
8388  
8389 @Language::Axbasic::Statement::let::ISA = qw(
8390 Language::Axbasic
8391 Language::Axbasic::Statement
8392 );
8393  
8394 # [LET] variable-name = expression
8395 # [LET] variable-name = CALL subroutine-name
8396 # [LET] variable-name = CALL subroutine-name ( [ expression [ , expression ... ] ] )
8397 # [LET] variable-name = DIMENSIONS array-variable
8398 # [LET] variable-name = LOWER array-variable
8399 # [LET] variable-name = SIZE array-variable
8400 # [LET] variable-name = UPPER array-variable
8401  
8402 ##################
8403 # Methods
8404  
8405 sub parse {
8406  
8407 # Called by LA::Line->parse directly after a call to LA::Statement->new when the first token
8408 # in the statement is the keyword 'let', or when the first token in the statement isn't a
8409 # keyword (which is an implied 'let')
8410 #
8411 # Expected arguments
8412 # (none besides $self)
8413 #
8414 # Return values
8415 # 'undef' on improper arguments or if there is an error
8416 # 1 otherwise
8417  
8418 my ($self, $check) = @_;
8419  
8420 # Local variables
8421 my ($lvalue, $token, $subNameToken, $argListObj, $arrayExp, $scalarExp);
8422  
8423 # Check for improper arguments
8424 if (defined $check) {
8425  
8426 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8427 }
8428  
8429 # Get the variable name
8430 $lvalue = Language::Axbasic::Expression::Lvalue->new(
8431 $self->scriptObj,
8432 $self->tokenGroupObj,
8433 );
8434  
8435 if (! defined $lvalue) {
8436  
8437 return $self->scriptObj->setError(
8438 'missing_or_illegal_variable',
8439 $self->_objClass . '->parse',
8440 );
8441 }
8442  
8443 # Extract the assignment operator
8444 $token = $self->tokenGroupObj->shiftTokenIfCategory('assignment_operator');
8445 if (! defined $token) {
8446  
8447 return $self->scriptObj->setError(
8448 'syntax_error',
8449 $self->_objClass . '->parse',
8450 );
8451 }
8452  
8453 # The rest of the statement is either:
8454 # 1. A subroutine call as a CALL statement, the return value of which should be assigned
8455 # to the scalar variable
8456 # 2. The keywords DIMENSIONS, LOWER, SIZE or UPPER followed by an array variable; the
8457 # value is assigned to the scalar variable (only DIMENSIONS can be used with
8458 # multi-dimensional arrays)
8459 # 3. A scalar expression, the value of which should be assigned to the variable
8460 $token = $self->tokenGroupObj->lookAhead();
8461 if (! defined $token) {
8462  
8463 return $self->scriptObj->setError(
8464 'syntax_error',
8465 $self->_objClass . '->parse',
8466 );
8467 }
8468  
8469 if ($token->tokenText eq 'call') {
8470  
8471 # Eat the 'call' token
8472 $token = $self->tokenGroupObj->shiftToken();
8473  
8474 # Process the subroutine call using code from the CALL statement
8475 Language::Axbasic::Statement::call->parse($self);
8476  
8477 # Save the variable object. LA::Statement::call->implement will use it
8478 $self->ivAdd('parseDataHash', 'call_var', $lvalue->varObj);
8479  
8480 } elsif (
8481 $token->tokenText eq 'dimensions'
8482 || $token->tokenText eq 'lower'
8483 || $token->tokenText eq 'size'
8484 || $token->tokenText eq 'upper'
8485 ) {
8486 # Eat the keyword token
8487 $token = $self->tokenGroupObj->shiftToken();
8488  
8489 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
8490 # LA::Variable->lookup that we're intentionally referring to an array variable, such
8491 # as that created by
8492 # DIM var (10)
8493 # ...by a variable name that looks like a scalar, i.e.
8494 # SORT var
8495 $self->scriptObj->set_declareMode('simple');
8496  
8497 # Get the variable name
8498 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
8499 $self->scriptObj,
8500 $self->tokenGroupObj,
8501 );
8502  
8503 if (! defined $arrayExp) {
8504  
8505 return $self->scriptObj->setError(
8506 'missing_or_illegal_variable',
8507 $self->_objClass . '->parse',
8508 );
8509 }
8510  
8511 # Reset the temporary IV
8512 $self->scriptObj->set_declareMode('default');
8513  
8514 # Save the scalar variable and the array expression so $self->implement can use them,
8515 # if it is called
8516 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
8517 if ($token->tokenText eq 'dimensions') {
8518 $self->ivAdd('parseDataHash', 'dims_exp', $arrayExp);
8519 } elsif ($token->tokenText eq 'lower') {
8520 $self->ivAdd('parseDataHash', 'lower_exp', $arrayExp);
8521 } elsif ($token->tokenText eq 'size') {
8522 $self->ivAdd('parseDataHash', 'size_exp', $arrayExp);
8523 } else {
8524 $self->ivAdd('parseDataHash', 'upper_exp', $arrayExp);
8525 }
8526  
8527 } else {
8528  
8529 $scalarExp = Language::Axbasic::Expression::Arithmetic->new(
8530 $self->scriptObj,
8531 $self->tokenGroupObj,
8532 );
8533  
8534 if (! defined $scalarExp) {
8535  
8536 return $self->scriptObj->setError(
8537 'missing_or_illegal_expression',
8538 $self->_objClass . '->parse',
8539 );
8540 }
8541  
8542 # Save the variable and the scalar expression so $self->implement can use them, if it
8543 # is called
8544 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
8545 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
8546 }
8547  
8548 # Parsing complete
8549 return 1;
8550 }
8551  
8552 sub implement {
8553  
8554 # Called by LA::Line->implement directly after a call to $self->parse
8555 #
8556 # Expected arguments
8557 # (none besides $self)
8558 #
8559 # Return values
8560 # 'undef' on improper arguments or if there is an error
8561 # 1 otherwise
8562  
8563 my ($self, $check) = @_;
8564  
8565 # Local variables
8566 my ($lvalue, $assignVar, $arrayExp, $scalarExp, $value);
8567  
8568 # Check for improper arguments
8569 if (defined $check) {
8570  
8571 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8572 }
8573  
8574 # LET var$ = CALL subname
8575 # LET var$ = CALL subname (arglist)
8576 if ($self->ivExists('parseDataHash', 'call_var')) {
8577  
8578 # Process the subroutine call using code from the CALL statement
8579 Language::Axbasic::Statement::call->implement($self);
8580  
8581 # LET var$ = DIMENSIONS arrayname
8582 # LET var$ = LOWER arrayname
8583 # LET var$ = SIZE arrayname
8584 # LET var$ = UPPER arrayname
8585 # LET var$ = expression
8586 } else {
8587  
8588 # Get the assignment variable stored by $self->parse
8589 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
8590  
8591 $assignVar = $lvalue->variable;
8592 if (! defined $assignVar) {
8593  
8594 # Subscript out of bounds, or similar error, has already been set
8595 return undef;
8596 }
8597  
8598 # LET var$ = DIMENSIONS arrayname
8599 if ($self->ivExists('parseDataHash', 'dims_exp')) {
8600  
8601 # Get the other value stored by $self->parse
8602 $arrayExp = $self->ivShow('parseDataHash', 'dims_exp');
8603 # Set the variable's value
8604 $assignVar->set($arrayExp->varObj->dimCount);
8605  
8606 # LET var$ = LOWER arrayname
8607 } elsif ($self->ivExists('parseDataHash', 'lower_exp')) {
8608  
8609 # Get the other value stored by $self->parse
8610 $arrayExp = $self->ivShow('parseDataHash', 'lower_exp');
8611  
8612 if ($arrayExp->varObj->dimCount > 1) {
8613  
8614 return $self->scriptObj->setError(
8615 'LOWER_cannot_operate_on_multi-dimensional_array',
8616 $self->_objClass . '->implement',
8617 );
8618  
8619 } else {
8620  
8621 # Set the variable's value
8622 $assignVar->set($arrayExp->varObj->ivIndex('cellList', 0));
8623 }
8624  
8625 # LET var$ = SIZE arrayname
8626 } elsif ($self->ivExists('parseDataHash', 'size_exp')) {
8627  
8628 # Get the other value stored by $self->parse
8629 $arrayExp = $self->ivShow('parseDataHash', 'size_exp');
8630  
8631 if ($arrayExp->varObj->dimCount > 1) {
8632  
8633 return $self->scriptObj->setError(
8634 'SIZE_cannot_operate_on_multi-dimensional_array',
8635 $self->_objClass . '->implement',
8636 );
8637  
8638 } else {
8639  
8640 # Set the variable's value, taking account of the first item in ->cellList,
8641 # which is the lower bound
8642 $assignVar->set((scalar ($arrayExp->varObj->cellList)) - 1);
8643 }
8644  
8645 # LET var$ = UPPER arrayname
8646 } elsif ($self->ivExists('parseDataHash', 'upper_exp')) {
8647  
8648 # Get the other value stored by $self->parse
8649 $arrayExp = $self->ivShow('parseDataHash', 'upper_exp');
8650  
8651 if ($arrayExp->varObj->dimCount > 1) {
8652  
8653 return $self->scriptObj->setError(
8654 'UPPER_cannot_operate_on_multi-dimensional_array',
8655 $self->_objClass . '->implement',
8656 );
8657  
8658 } else {
8659  
8660 # Set the variable's value, taking account of the first item in ->cellList,
8661 # which is the lower bound
8662 $assignVar->set(
8663 $arrayExp->varObj->ivIndex('cellList', 0)
8664 + (scalar ($arrayExp->varObj->cellList)) - 2
8665 );
8666 }
8667  
8668 # LET var$ = expression
8669 } else {
8670  
8671 # Get the other value stored by $self->parse
8672 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
8673 # Set the variable's value
8674 $value = $scalarExp->evaluate();
8675 $assignVar->set($value);
8676 }
8677 }
8678  
8679 # Implementation complete
8680 return 1;
8681 }
8682 }
8683  
8684 { package Language::Axbasic::Statement::local;
8685  
8686 use strict;
8687 use warnings;
8688 use diagnostics;
8689  
8690 use Glib qw(TRUE FALSE);
8691  
8692 @Language::Axbasic::Statement::local::ISA = qw(
8693 Language::Axbasic
8694 Language::Axbasic::Statement
8695 );
8696  
8697 # LOCAL variable-name [ , variable-name ... ]
8698  
8699 ##################
8700 # Methods
8701  
8702 sub parse {
8703  
8704 # Called by LA::Line->parse directly after a call to LA::Statement->new
8705 #
8706 # Expected arguments
8707 # (none besides $self)
8708 #
8709 # Return values
8710 # 'undef' on improper arguments or if there is an error
8711 # 1 otherwise
8712  
8713 my ($self, $check) = @_;
8714  
8715 # Local variables
8716 my ($token, $argListObj);
8717  
8718 # Check for improper arguments
8719 if (defined $check) {
8720  
8721 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8722 }
8723  
8724 # The 'local' keyword is not available in primitive numbering mode
8725 if ($self->scriptObj->executionMode ne 'no_line_num') {
8726  
8727 return $self->scriptObj->setError(
8728 'statement_not_available_with_line_numbers',
8729 $self->_objClass . '->parse',
8730 );
8731 }
8732  
8733 # Temporarily set the IV that allows undeclared variables to be created
8734 $self->scriptObj->set_declareMode('local_scalar');
8735  
8736 # Process each array in turn (if several appear on the same line, they are separated by
8737 # commas)
8738 do {
8739  
8740 my $lvalue = Language::Axbasic::Expression::Lvalue->new(
8741 $self->scriptObj,
8742 $self->tokenGroupObj,
8743 );
8744  
8745 if (! defined $lvalue) {
8746  
8747 return $self->scriptObj->setError(
8748 'missing_or_illegal_variable',
8749 $self->_objClass . '->parse',
8750 );
8751 }
8752  
8753 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
8754  
8755 # Reset the temporary IV
8756 $self->scriptObj->set_declareMode('default');
8757  
8758 # Check there is nothing else (except for the statement separator, :)
8759 if (! defined $self->tokenGroupObj->testStatementEnd()) {
8760  
8761 return $self->scriptObj->setError(
8762 'unexpected_keywords,_operators_or_expressions',
8763 $self->_objClass . '->parse',
8764 );
8765 }
8766  
8767 # Save the arglist so that ->implement can add all these variables to the global variable
8768 # hash, when the line is executed
8769 $self->ivAdd('parseDataHash', 'arg_list_obj', $argListObj);
8770  
8771 # Parsing complete
8772 return 1;
8773 }
8774  
8775 # sub implement {} # No ->implement method - LA::Variable->lookup has already added the
8776 # variable to LA::Subroutine->localScalarHash or ->localArrayHash
8777 }
8778  
8779 { package Language::Axbasic::Statement::login;
8780  
8781 use strict;
8782 use warnings;
8783 use diagnostics;
8784  
8785 use Glib qw(TRUE FALSE);
8786  
8787 @Language::Axbasic::Statement::login::ISA = qw(
8788 Language::Axbasic
8789 Language::Axbasic::Statement
8790 );
8791  
8792 # LOGIN
8793  
8794 ##################
8795 # Methods
8796  
8797 sub parse {
8798  
8799 # Called by LA::Line->parse directly after a call to LA::Statement->new
8800 #
8801 # Expected arguments
8802 # (none besides $self)
8803  
8804 # Return values
8805 # 'undef' on improper arguments or if there is an error
8806 # 1 otherwise
8807  
8808 my ($self, $check) = @_;
8809  
8810 # Check for improper arguments
8811 if (defined $check) {
8812  
8813 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8814 }
8815  
8816 # LOGIN statements always appear on their own
8817 if (! $self->tokenGroupObj->testStatementEnd()) {
8818  
8819 return $self->scriptObj->setError(
8820 'unexpected_keywords,_operators_or_expressions',
8821 $self->_objClass . '->parse',
8822 );
8823 }
8824  
8825 # Parsing complete
8826 return 1;
8827 }
8828  
8829 sub implement {
8830  
8831 # Called by LA::Line->implement directly after a call to $self->parse
8832 #
8833 # Expected arguments
8834 # (none besides $self)
8835 #
8836 # Return values
8837 # 'undef' on improper arguments or if there is an error
8838 # 1 otherwise
8839  
8840 my ($self, $check) = @_;
8841  
8842 # Check for improper arguments
8843 if (defined $check) {
8844  
8845 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8846 }
8847  
8848 # Tell the GA::Session that the automatic login is complete (if the character is already
8849 # marked as 'logged in', nothing happens
8850 $self->scriptObj->session->doLogin();
8851  
8852 # Implementation complete
8853 return 1;
8854 }
8855 }
8856  
8857 { package Language::Axbasic::Statement::loop;
8858  
8859 use strict;
8860 use warnings;
8861 use diagnostics;
8862  
8863 use Glib qw(TRUE FALSE);
8864  
8865 @Language::Axbasic::Statement::loop::ISA = qw(
8866 Language::Axbasic
8867 Language::Axbasic::Statement
8868 );
8869  
8870 # LOOP
8871  
8872 ##################
8873 # Methods
8874  
8875 sub parse {
8876  
8877 # Called by LA::Line->parse directly after a call to LA::Statement->new
8878 #
8879 # Expected arguments
8880 # (none besides $self)
8881 #
8882 # Return values
8883 # 'undef' on improper arguments or if there is an error
8884 # 1 otherwise
8885  
8886 my ($self, $check) = @_;
8887  
8888 # Local variables
8889 my ($subObj, $whileStatement);
8890  
8891 # Check for improper arguments
8892 if (defined $check) {
8893  
8894 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8895 }
8896  
8897 # The 'loop' keyword is not available in primitive numbering mode
8898 if ($self->scriptObj->executionMode ne 'no_line_num') {
8899  
8900 return $self->scriptObj->setError(
8901 'statement_not_available_with_line_numbers',
8902 $self->_objClass . '->parse',
8903 );
8904 }
8905  
8906 # LOOP statements always appear on their own
8907 if (! $self->tokenGroupObj->testStatementEnd()) {
8908  
8909 return $self->scriptObj->setError(
8910 'unexpected_keywords,_operators_or_expressions',
8911 $self->_objClass . '->parse',
8912 );
8913 }
8914  
8915 # Find the matching WHILE statement, which should already have been parsed
8916 $subObj = $self->scriptObj->returnCurrentSub();
8917 if (! $subObj->whileStackList) {
8918  
8919 return $self->scriptObj->setError(
8920 'LOOP_statement_without_matching_WHILE',
8921 $self->_objClass . '->parse',
8922 );
8923  
8924 } else {
8925  
8926 $whileStatement = $subObj->pop_whileStackList();
8927  
8928 # Tell the WHILE statement's ->implement what its matching LOOP statement (i.e. this
8929 # one) is
8930 $whileStatement->add_parseDataHash('loop_statement', $self);
8931 # Store the WHILE statement so this statement's ->implement can use it
8932 $self->ivAdd('parseDataHash', 'while_statement', $whileStatement);
8933 }
8934  
8935 # Parsing complete
8936 return 1;
8937 }
8938  
8939 sub implement {
8940  
8941 # Called by LA::Line->implement directly after a call to $self->parse
8942 #
8943 # Expected arguments
8944 # (none besides $self)
8945 #
8946 # Return values
8947 # 'undef' on improper arguments or if there is an error
8948 # 1 otherwise
8949  
8950 my ($self, $check) = @_;
8951  
8952 # Local variables
8953 my ($subObj, $whileStatement);
8954  
8955 # Check for improper arguments
8956 if (defined $check) {
8957  
8958 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8959 }
8960  
8961 # Remove this code block from the standard code block stack. (The WHILE statement puts it
8962 # straight back, if the code block is to be executed again.)
8963 $subObj = $self->scriptObj->returnCurrentSub();
8964 if (! $subObj->blockStackList) {
8965  
8966 return $self->scriptObj->setError(
8967 'LOOP_statement_without_matching_WHILE',
8968 $self->_objClass . '->implement',
8969 );
8970 }
8971  
8972 $whileStatement = $subObj->pop_blockStackList();
8973  
8974 # The statement at the top of the stack must be a WHILE statement, not another kind of code
8975 # block
8976 if ($whileStatement->keyword ne 'while') {
8977  
8978 return $self->scriptObj->setError(
8979 'LOOP_statement_without_matching_WHILE',
8980 $self->_objClass . '->implement',
8981 );
8982 }
8983  
8984 # Nothing records a statement's previous statement on the same line (if any), so just
8985 # re-implement the WHILE statement, as if it had been called directly from
8986 # LA::Script->implement
8987 $self->scriptObj->set_nextStatement($whileStatement);
8988 return $whileStatement->implement();
8989 }
8990 }
8991  
8992 { package Language::Axbasic::Statement::move;
8993  
8994 use strict;
8995 use warnings;
8996 use diagnostics;
8997  
8998 use Glib qw(TRUE FALSE);
8999  
9000 @Language::Axbasic::Statement::move::ISA = qw(
9001 Language::Axbasic
9002 Language::Axbasic::Statement
9003 );
9004  
9005 # MOVE expression
9006  
9007 ##################
9008 # Methods
9009  
9010 sub parse {
9011  
9012 # Called by LA::Line->parse directly after a call to LA::Statement->new
9013 #
9014 # Expected arguments
9015 # (none besides $self)
9016 #
9017 # Return values
9018 # 'undef' on improper arguments or if there is an error
9019 # 1 otherwise
9020  
9021 my ($self, $check) = @_;
9022  
9023 # Local variables
9024 my $expression;
9025  
9026 # Check for improper arguments
9027 if (defined $check) {
9028  
9029 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9030 }
9031  
9032 # Get the expression and store it for ->implement to use
9033 $expression = Language::Axbasic::Expression::Arithmetic->new(
9034 $self->scriptObj,
9035 $self->tokenGroupObj,
9036 );
9037  
9038 if (! defined $expression) {
9039  
9040 return $self->scriptObj->setError(
9041 'missing_or_illegal_expression',
9042 $self->_objClass . '->parse',
9043 );
9044  
9045 } else {
9046  
9047 $self->ivAdd('parseDataHash', 'expression', $expression);
9048 }
9049  
9050 # There should be nothing after the expression
9051 if (! $self->tokenGroupObj->testStatementEnd()) {
9052  
9053 return $self->scriptObj->setError(
9054 'unexpected_keywords,_operators_or_expressions',
9055 $self->_objClass . '->parse',
9056 );
9057 }
9058  
9059 # Parsing complete
9060 return 1;
9061 }
9062  
9063 sub implement {
9064  
9065 # Called by LA::Line->implement directly after a call to $self->parse
9066 #
9067 # Expected arguments
9068 # (none besides $self)
9069 #
9070 # Return values
9071 # 'undef' on improper arguments or if there is an error
9072 # 1 otherwise
9073  
9074 my ($self, $check) = @_;
9075  
9076 # Local variables
9077 my ($expression, $cmd);
9078  
9079 # Check for improper arguments
9080 if (defined $check) {
9081  
9082 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9083 }
9084  
9085 # Retrieve the expression to be played
9086 $expression = $self->ivShow('parseDataHash', 'expression');
9087 # Evaluate the expression to get a world command
9088 $cmd = $expression->evaluate();
9089  
9090 # Send the command to the world
9091 $self->scriptObj->session->moveCmd($cmd);
9092  
9093 # Implementation complete
9094 return 1;
9095 }
9096 }
9097  
9098 { package Language::Axbasic::Statement::multi;
9099  
9100 use strict;
9101 use warnings;
9102 use diagnostics;
9103  
9104 use Glib qw(TRUE FALSE);
9105  
9106 @Language::Axbasic::Statement::multi::ISA = qw(
9107 Language::Axbasic
9108 Language::Axbasic::Statement
9109 );
9110  
9111 # MULTI expression
9112  
9113 ##################
9114 # Methods
9115  
9116 sub parse {
9117  
9118 # Called by LA::Line->parse directly after a call to LA::Statement->new
9119 #
9120 # Expected arguments
9121 # (none besides $self)
9122 #
9123 # Return values
9124 # 'undef' on improper arguments or if there is an error
9125 # 1 otherwise
9126  
9127 my ($self, $check) = @_;
9128  
9129 # Local variables
9130 my $expression;
9131  
9132 # Check for improper arguments
9133 if (defined $check) {
9134  
9135 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9136 }
9137  
9138 # Get the expression and store it for ->implement to use
9139 $expression = Language::Axbasic::Expression::Arithmetic->new(
9140 $self->scriptObj,
9141 $self->tokenGroupObj,
9142 );
9143  
9144 if (! defined $expression) {
9145  
9146 return $self->scriptObj->setError(
9147 'missing_or_illegal_expression',
9148 $self->_objClass . '->parse',
9149 );
9150  
9151 } else {
9152  
9153 $self->ivAdd('parseDataHash', 'expression', $expression);
9154 }
9155  
9156 # There should be nothing after the expression
9157 if (! $self->tokenGroupObj->testStatementEnd()) {
9158  
9159 return $self->scriptObj->setError(
9160 'unexpected_keywords,_operators_or_expressions',
9161 $self->_objClass . '->parse',
9162 );
9163 }
9164  
9165 # Parsing complete
9166 return 1;
9167 }
9168  
9169 sub implement {
9170  
9171 # Called by LA::Line->implement directly after a call to $self->parse
9172 #
9173 # Expected arguments
9174 # (none besides $self)
9175 #
9176 # Return values
9177 # 'undef' on improper arguments or if there is an error
9178 # 1 otherwise
9179  
9180 my ($self, $check) = @_;
9181  
9182 # Local variables
9183 my ($expression, $string);
9184  
9185 # Check for improper arguments
9186 if (defined $check) {
9187  
9188 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9189 }
9190  
9191 # Retrieve the expression to be written
9192 $expression = $self->ivShow('parseDataHash', 'expression');
9193 # Evaluate the expression to get a scalar value
9194 $string = $expression->evaluate();
9195  
9196 # Execute the expression as a multi command
9197 $self->scriptObj->session->multiCmd($string);
9198  
9199 # Implementation complete
9200 return 1;
9201 }
9202 }
9203  
9204 { package Language::Axbasic::Statement::next;
9205  
9206 use strict;
9207 use warnings;
9208 use diagnostics;
9209  
9210 use Glib qw(TRUE FALSE);
9211  
9212 @Language::Axbasic::Statement::next::ISA = qw(
9213 Language::Axbasic
9214 Language::Axbasic::Statement
9215 );
9216  
9217 # NEXT variable-name
9218  
9219 ##################
9220 # Methods
9221  
9222 sub parse {
9223  
9224 # Called by LA::Line->parse directly after a call to LA::Statement->new
9225 #
9226 # Expected arguments
9227 # (none besides $self)
9228 #
9229 # Return values
9230 # 'undef' on improper arguments or if there is an error
9231 # 1 otherwise
9232  
9233 my ($self, $check) = @_;
9234  
9235 # Local variables
9236 my $lvalue;
9237  
9238 # Check for improper arguments
9239 if (defined $check) {
9240  
9241 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9242 }
9243  
9244 # Read the iterator variable name
9245 $lvalue = Language::Axbasic::Expression::Lvalue->new(
9246 $self->scriptObj,
9247 $self->tokenGroupObj,
9248 );
9249  
9250 if (! defined $lvalue) {
9251  
9252 return $self->scriptObj->setError(
9253 'missing_or_illegal_iterator',
9254 $self->_objClass . '->parse',
9255 );
9256  
9257 # v1.2.120 Removed for FOR EACH statements
9258 # } elsif ($lvalue->isa('Language::Axbasic::Expression::String')) {
9259 #
9260 # return $self->scriptObj->setError(
9261 # 'missing_or_illegal_iterator',
9262 # $self->_objClass . '->parse',
9263 # );
9264  
9265 } else {
9266  
9267 # Store the iterator, so $self->implement can retrieve it
9268 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
9269 }
9270  
9271 # Check there's nothing else in the statement after the iterator
9272 if (! $self->tokenGroupObj->testStatementEnd()) {
9273  
9274 return $self->scriptObj->setError(
9275 'unexpected_keywords,_operators_or_expressions',
9276 $self->_objClass . '->parse',
9277 );
9278 }
9279  
9280 # Parsing complete
9281 return 1;
9282 }
9283  
9284 sub implement {
9285  
9286 # Called by LA::Line->implement directly after a call to $self->parse
9287 #
9288 # Expected arguments
9289 # (none besides $self)
9290 #
9291 # Return values
9292 # 'undef' on improper arguments or if there is an error
9293 # 1 otherwise
9294  
9295 my ($self, $check) = @_;
9296  
9297 # Local variables
9298 my (
9299 $lvalue, $subObj, $forStatement, $exitFlag, $forEachFlag, $forTermExp, $forStepExp,
9300 $forArrayExp, $forArrayIndex, $term, $step, $var, $value, $iterVar, $elementVar,
9301 $loopFlag, $indexListRef, $dim, $termFlag,
9302 );
9303  
9304 # Check for improper arguments
9305 if (defined $check) {
9306  
9307 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9308 }
9309  
9310 # Retrieve the iterator stored by $self->parse
9311 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
9312  
9313 # Get the corresponding FOR statement from the current subroutine's code block stack. Keep
9314 # removing code blocks from the top of the stack until we get the right one
9315 $subObj = $self->scriptObj->returnCurrentSub();
9316 if (! $subObj->blockStackList) {
9317  
9318 return $self->scriptObj->setError(
9319 'NEXT_statement_without_matching_FOR',
9320 $self->_objClass . '->implement',
9321 );
9322 }
9323  
9324 do {
9325  
9326 $forStatement = $subObj->pop_blockStackList();
9327  
9328 # Check that it's a FOR statement - not the start of another kind of code block - and
9329 # that it's the right iterator
9330 if (
9331 $forStatement->keyword eq 'for'
9332 && $forStatement->ivShow('parseDataHash', 'lvalue')->varObj eq $lvalue->varObj
9333 ) {
9334 # We've found the statement we're looking for
9335 $exitFlag = TRUE;
9336 }
9337  
9338 } until ($exitFlag || ! $subObj->blockStackList);
9339  
9340 if (! $exitFlag) {
9341  
9342 return $self->scriptObj->setError(
9343 'NEXT_statement_without_matching_FOR',
9344 $self->_objClass . '->implement',
9345 );
9346 }
9347  
9348 # Import the stored data from the matching FOR statement
9349 $forEachFlag = $forStatement->ivShow('parseDataHash', 'each_flag');
9350 $forTermExp = $forStatement->ivShow('parseDataHash', 'term_exp');
9351 $forStepExp = $forStatement->ivShow('parseDataHash', 'step_exp');
9352 $forArrayExp = $forStatement->ivShow('parseDataHash', 'array_exp');
9353  
9354 # There are two formats for a FOR statement
9355 if (! $forEachFlag) {
9356  
9357 # First type: FOR variable-name = expression TO expression [ STEP expression ]
9358  
9359 # Evaluate the termination and step expressions. Store them so that, during a FOR..NEXT
9360 # loop, we only have to evaluate the expressions once
9361 if (! $self->ivExists('parseDataHash', 'term_value')) {
9362  
9363 $term = $forTermExp->evaluate();
9364 $step = $forStepExp->evaluate();
9365  
9366 $self->ivAdd('parseDataHash', 'term_value', $term);
9367 $self->ivAdd('parseDataHash', 'step_value', $step);
9368  
9369 } else {
9370  
9371 $term = $self->ivShow('parseDataHash', 'term_value');
9372 $step = $self->ivShow('parseDataHash', 'step_value');
9373 }
9374  
9375 # Increment the iterator variable
9376 $var = $lvalue->variable;
9377 $value = $var->value;
9378 $value += $step;
9379 $var->set($value);
9380  
9381 # Termination test
9382 if (($step > 0 && $value <= $term) || ($step < 0 && $value >= $term)) {
9383  
9384 # Perform another iteration of the loop
9385 $loopFlag = TRUE;
9386 }
9387  
9388 } else {
9389  
9390 # Second type: FOR EACH variable-name IN variable-name
9391  
9392 # On the next FOR loop, we will use the next element in the sequence
9393 $indexListRef = $forStatement->ivShow('parseDataHash', 'index_list_ref');
9394 # The array variable might be multi-dimensional, in which case we have multiple indexes,
9395 # one for each dimension. Increment the index(es) from the bottom up
9396 # e.g. For a 3x3 array, [1, 1], then [1, 2], [1, 3], [2, 1], [2, 2]...
9397 # Check each dimension in turn, starting with the last one
9398 $dim = scalar @$indexListRef;
9399 $exitFlag = FALSE;
9400  
9401 OUTER: do {
9402  
9403 $dim--;
9404  
9405 # Increment the index
9406 # e.g. In a 3x3 array, on the first spin of this loop, $dim is 2, and [1, 1]
9407 # becomes [1, 2]
9408 $$indexListRef[$dim] = $$indexListRef[$dim] + 1;
9409 # But on a later spin, [1, 3] becomes [1, 4], which does not exist in the array.
9410 # In that case, [1, 3] becomes [2, 1]
9411 my $cellVar = $forArrayExp->varObj->testCell(@$indexListRef);
9412  
9413 if (defined $cellVar) {
9414  
9415 # The cell now described by $indexListRef is valid, so we can proceed with the
9416 # next iteration of the FOR EACH loop
9417 $exitFlag = TRUE;
9418  
9419 } else {
9420  
9421 # The cell now described by $indexListRef is not valid
9422 if (! $dim) {
9423  
9424 # At the end of the array (e.g. [3, 3] ), so terminate the FOR EACH loop
9425 $termFlag = TRUE;
9426 $exitFlag = TRUE;
9427  
9428 } else {
9429  
9430 # Increment the indices, e.g. [1, 3] becomes [2, 1]
9431 $$indexListRef[$dim] = 1;
9432 }
9433 }
9434  
9435 } until ($exitFlag || ! $dim);
9436  
9437 # Termination test
9438 if (! $termFlag) {
9439  
9440 # Update the stored indices (commented out as not necessary for a list reference)
9441 # $forStatement->ivAdd('parseDataHash', 'index_list_ref', $indexListRef);
9442  
9443 # Retrieve the variable that's the next element of the array, and set the iterator
9444 # with its value
9445 $iterVar = $lvalue->variable;
9446 $elementVar = $forArrayExp->varObj->getCell(@$indexListRef);
9447 $iterVar->set($elementVar->value);
9448  
9449 # Perform another iteration of the loop
9450 $loopFlag = TRUE;
9451 }
9452 }
9453  
9454 if ($loopFlag) {
9455  
9456 # Perform another iteration of the loop. Go to the statement immediately after the
9457 # corresponding FOR statement
9458 if (defined $forStatement->nextStatement) {
9459  
9460 # LA::Script->nextStatement is currently set to this statement; continue execution
9461 # as if this were the GOSUB statement
9462 $self->scriptObj->set_nextStatement($forStatement);
9463  
9464 } else {
9465  
9466 # The FOR statement was the last (or only) statement on the line: use the next line
9467 $self->scriptObj->set_nextStatement(undef);
9468 $self->scriptObj->set_nextLine($forStatement->lineObj->procLineNum + 1);
9469 }
9470  
9471 # Put the corresponding 'for' statement back into the current subroutine's code
9472 # block stack
9473 $subObj->push_blockStackList($forStatement);
9474 }
9475  
9476 # Implementation complete
9477 return 1;
9478 }
9479 }
9480  
9481 { package Language::Axbasic::Statement::nextiface;
9482  
9483 use strict;
9484 use warnings;
9485 use diagnostics;
9486  
9487 use Glib qw(TRUE FALSE);
9488  
9489 @Language::Axbasic::Statement::nextiface::ISA = qw(
9490 Language::Axbasic
9491 Language::Axbasic::Statement
9492 );
9493  
9494 # NEXTIFACE
9495  
9496 ##################
9497 # Methods
9498  
9499 sub parse {
9500  
9501 # Called by LA::Line->parse directly after a call to LA::Statement->new
9502 #
9503 # Expected arguments
9504 # (none besides $self)
9505 #
9506 # Return values
9507 # 'undef' on improper arguments or if there is an error
9508 # 1 otherwise
9509  
9510 my ($self, $check) = @_;
9511  
9512 # Local variables
9513 my ($subObj, $whileStatement);
9514  
9515 # Check for improper arguments
9516 if (defined $check) {
9517  
9518 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9519 }
9520  
9521 # NEXTIFACE statements always appear on their own
9522 if (! $self->tokenGroupObj->testStatementEnd()) {
9523  
9524 return $self->scriptObj->setError(
9525 'unexpected_keywords,_operators_or_expressions',
9526 $self->_objClass . '->parse',
9527 );
9528 }
9529  
9530 # Parsing complete
9531 return 1;
9532 }
9533  
9534 sub implement {
9535  
9536 # Called by LA::Line->implement directly after a call to $self->parse
9537 #
9538 # Expected arguments
9539 # (none besides $self)
9540 #
9541 # Return values
9542 # 'undef' on improper arguments or if there is an error
9543 # 1 otherwise
9544  
9545 my ($self, $check) = @_;
9546  
9547 # Check for improper arguments
9548 if (defined $check) {
9549  
9550 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9551 }
9552  
9553 # Do nothing, if the interface notification list is empty
9554 if (! $self->scriptObj->notificationList) {
9555  
9556 # Implementation complete
9557 return 1;
9558  
9559 } else {
9560  
9561 # Remove the current interface from the list
9562 $self->scriptObj->rmv_currentNotification();
9563 if ($self->scriptObj->notificationList) {
9564  
9565 # The next current notification is the first one in the list
9566 $self->scriptObj->set_currentNotification(0);
9567  
9568 } else {
9569  
9570 # The list is empty. Mark this with the value -1
9571 $self->scriptObj->set_currentNotification(-1);
9572 }
9573 }
9574  
9575 # Implementation complete
9576 return 1;
9577 }
9578 }
9579  
9580 { package Language::Axbasic::Statement::on;
9581  
9582 use strict;
9583 use warnings;
9584 use diagnostics;
9585  
9586 use Glib qw(TRUE FALSE);
9587  
9588 @Language::Axbasic::Statement::on::ISA = qw(
9589 Language::Axbasic
9590 Language::Axbasic::Statement
9591 );
9592  
9593 # ON expression GOTO expression [ , expression ... ]
9594 # ON expression GOSUB expression [ , expression ... ]
9595  
9596 ##################
9597 # Methods
9598  
9599 sub parse {
9600  
9601 # Called by LA::Line->parse directly after a call to LA::Statement->new
9602 #
9603 # Expected arguments
9604 # (none besides $self)
9605 #
9606 # Return values
9607 # 'undef' on improper arguments or if there is an error
9608 # 1 otherwise
9609  
9610 my ($self, $check) = @_;
9611  
9612 # Local variables
9613 my (
9614 $expression, $token, $statementType,
9615 @lineList,
9616 );
9617  
9618 # Check for improper arguments
9619 if (defined $check) {
9620  
9621 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9622 }
9623  
9624 # The 'on' keyword is only available in primitive numbering mode
9625 if ($self->scriptObj->executionMode ne 'line_num') {
9626  
9627 return $self->scriptObj->setError(
9628 'statement_not_available_without_line_numbers',
9629 $self->_objClass . '->parse',
9630 );
9631 }
9632  
9633 # Everything up to the 'gosub' or 'goto' token is an arithmetic expression
9634 $expression = Language::Axbasic::Expression::Arithmetic->new(
9635 $self->scriptObj,
9636 $self->tokenGroupObj,
9637 );
9638  
9639 if (! defined $expression) {
9640  
9641 return $self->scriptObj->setError(
9642 'missing_or_illegal_expression',
9643 $self->_objClass . '->parse',
9644 );
9645 }
9646  
9647 # Extract the 'gosub'/'goto' token
9648 $token = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
9649 if (! defined $token || ($token->tokenText ne 'gosub' && $token->tokenText ne 'goto')) {
9650  
9651 return $self->scriptObj->setError(
9652 'syntax_error',
9653 $self->_objClass . '->parse',
9654 );
9655  
9656 } else {
9657  
9658 # Remember if it's a 'gosub' or a 'goto'
9659 $statementType = $token->tokenText;
9660 }
9661  
9662 # The remaining tokens should be line numbers, separated by commas
9663 do {
9664  
9665 my $lineNumber = Language::Axbasic::Expression::Arithmetic->new(
9666 $self->scriptObj,
9667 $self->tokenGroupObj,
9668 );
9669  
9670 if (! defined $lineNumber) {
9671  
9672 return $self->scriptObj->setError(
9673 'missing_or_illegal_expression',
9674 $self->_objClass . '->parse',
9675 );
9676  
9677 } else {
9678  
9679 push (@lineList, $lineNumber);
9680 }
9681  
9682 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
9683  
9684 # Store the data, so $self->implement can retrieve it
9685 $self->ivAdd('parseDataHash', 'expression', $expression);
9686 $self->ivAdd('parseDataHash', 'statement_type', $statementType);
9687 $self->ivPush('parseDataList', @lineList);
9688  
9689 # Parsing complete
9690 return 1;
9691 }
9692  
9693 sub implement {
9694  
9695 # Called by LA::Line->implement directly after a call to $self->parse
9696 #
9697 # Expected arguments
9698 # (none besides $self)
9699 #
9700 # Return values
9701 # 'undef' on improper arguments
9702 # 1 otherwise
9703  
9704 my ($self, $check) = @_;
9705  
9706 # Local variables
9707 my (
9708 $expression, $statementType, $line, $lineNumber, $value,
9709 @lineList,
9710 );
9711  
9712 # Check for improper arguments
9713 if (defined $check) {
9714  
9715 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9716 }
9717  
9718 # Retrieve the data stored by ->parse
9719 $expression = $self->ivShow('parseDataHash', 'expression');
9720 $statementType = $self->ivShow('parseDataHash', 'statement_type');
9721 @lineList = $self->parseDataList;
9722  
9723 # Evaluate the main expression
9724 $value = $expression->evaluate();
9725 if (! defined $value || ! ($value =~ /^\d+$/) || $value > @lineList) {
9726  
9727 return $self->scriptObj->setError(
9728 'missing_or_illegal_expression',
9729 $self->_objClass . '->implement',
9730 'VALUE', $value,
9731 );
9732 }
9733  
9734 # If $value == n, the line number to jump to is the [n-1]th value in @lineList
9735 $line = $lineList[$value - 1];
9736 $lineNumber = $line->evaluate();
9737 if (! defined $lineNumber || ! ($lineNumber =~ /^\d+$/)) {
9738  
9739 return $self->scriptObj->setError(
9740 'illegal_line_number_NUM',
9741 $self->_objClass . '->implement',
9742 'NUM', $lineNumber,
9743 );
9744 }
9745  
9746 # Check that the primitive line number exists
9747 if (! $self->scriptObj->ivExists('primLineHash', $lineNumber)) {
9748  
9749 return $self->scriptObj->setError(
9750 'line_number_NUM_not_found',
9751 $self->_objClass . '->implement',
9752 'NUM', $lineNumber,
9753 );
9754 }
9755  
9756 if ($statementType eq 'gosub') {
9757  
9758 # Push the current statement onto the subroutine stack
9759 $self->scriptObj->push_gosubStackList($self);
9760 }
9761  
9762 # Set the next line/statement to be executed
9763 $self->scriptObj->set_nextLine($self->scriptObj->ivShow('primLineHash', $lineNumber));
9764 $self->scriptObj->set_nextStatement(undef);
9765  
9766 # Implementation complete
9767 return 1;
9768 }
9769 }
9770  
9771 { package Language::Axbasic::Statement::open;
9772  
9773 use strict;
9774 use warnings;
9775 use diagnostics;
9776  
9777 use Glib qw(TRUE FALSE);
9778  
9779 @Language::Axbasic::Statement::open::ISA = qw(
9780 Language::Axbasic
9781 Language::Axbasic::Statement
9782 );
9783  
9784 # OPEN #channel: NAME expression
9785 # [, ORGANIZATION TEXT ] [, CREATE NEW|OLD|NEWOLD ] [, ACCESS OUTIN|INPUT|OUTPUT ]
9786 # OPEN #channel: NAME expression
9787 # [, ORGANIZATION expression ] [, CREATE expression ] [, ACCESS expression ]
9788  
9789 ##################
9790 # Methods
9791  
9792 sub parse {
9793  
9794 # Called by LA::Line->parse directly after a call to LA::Statement->new
9795 #
9796 # Expected arguments
9797 # (none besides $self)
9798 #
9799 # Return values
9800 # 'undef' on improper arguments or if there is an error
9801 # 1 otherwise
9802  
9803 my ($self, $check) = @_;
9804  
9805 # Local variables
9806 my ($channelToken, $channel, $nameFlag);
9807  
9808 # Check for improper arguments
9809 if (defined $check) {
9810  
9811 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9812 }
9813  
9814 # Get the channel token. For OPEN statements, it must include a colon at the end
9815 # (e.g. '#5:' )
9816 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
9817 if (! defined $channelToken || ! ($channelToken->tokenText =~ m/\:$/)) {
9818  
9819 return $self->scriptObj->setError(
9820 'syntax_error',
9821 $self->_objClass . '->parse',
9822 );
9823  
9824 } else {
9825  
9826 # Store the channel number
9827 $channelToken->tokenText =~ m/([0-9]+)/;
9828 $channel = $1;
9829  
9830 # True BASIC specifies that the channel must be in the range 1-999; same range used by
9831 # Axbasic
9832 if ($channel < 1 || $channel > 999) {
9833  
9834 return $self->scriptObj->setError(
9835 'file_channel_NUM_out_of_range',
9836 $self->_objClass . '->parse',
9837 'NUM', $channel,
9838 );
9839  
9840 } else {
9841  
9842 $self->ivAdd('parseDataHash', 'channel', $channel);
9843 }
9844 }
9845  
9846 # The rest of the arguments will be separated by commas
9847 do {
9848  
9849 my ($token, $expression, $nextToken);
9850  
9851 $token = $self->tokenGroupObj->shiftToken();
9852 if ($token) {
9853  
9854 if ($token->category ne 'keyword') {
9855  
9856 return $self->scriptObj->setError(
9857 'syntax_error',
9858 $self->_objClass . '->parse',
9859 );
9860  
9861 } elsif ($token->tokenText eq 'name') {
9862  
9863 # Next token is an expression for the file name
9864 $expression = Language::Axbasic::Expression::Arithmetic->new(
9865 $self->scriptObj,
9866 $self->tokenGroupObj,
9867 );
9868  
9869 if (! defined $expression) {
9870  
9871 return $self->scriptObj->setError(
9872 'missing_or_illegal_expression',
9873 $self->_objClass . '->parse',
9874 );
9875  
9876 } else {
9877  
9878 # Store the file expression
9879 $self->ivAdd('parseDataHash', 'file_exp', $expression);
9880 $nameFlag = TRUE;
9881 }
9882  
9883 } elsif ($token->tokenText eq 'organization' || $token->tokenText eq 'org') {
9884  
9885 # Next token must be the keyword TEXT (True BASIC also uses STREAM, RANDOM,
9886 # RECORD and BYTE, but Axbasic does not implement them)
9887 # (Can also be an expression evaluating to 'text')
9888 $nextToken = $self->tokenGroupObj->shiftMatchingToken('text');
9889 if (! $nextToken) {
9890  
9891 $expression = Language::Axbasic::Expression::Arithmetic->new(
9892 $self->scriptObj,
9893 $self->tokenGroupObj,
9894 );
9895  
9896 if (! $expression) {
9897  
9898 return $self->scriptObj->setError(
9899 'syntax_error',
9900 $self->_objClass . '->parse',
9901 );
9902  
9903 } else {
9904  
9905 # Store the expression, for $self->implement to evaluate
9906 $self->ivAdd('parseDataHash', 'org_exp', $expression);
9907 }
9908  
9909 } else {
9910  
9911 # Axbasic only reads/writes text files, but we'll store value for
9912 # $self->implemement to retrieve anyway
9913 $self->ivAdd('parseDataHash', 'org_type', 'text');
9914 }
9915  
9916 } elsif ($token->tokenText eq 'create') {
9917  
9918 # Next token must be one of the keywords NEW, OLD, NEWOLD (can also be an
9919 # expression evaluating to 'new', 'old' or 'newold')
9920 $nextToken = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
9921 if (! $nextToken) {
9922  
9923 $expression = Language::Axbasic::Expression::Arithmetic->new(
9924 $self->scriptObj,
9925 $self->tokenGroupObj,
9926 );
9927  
9928 if (! $expression) {
9929  
9930 return $self->scriptObj->setError(
9931 'syntax_error',
9932 $self->_objClass . '->parse',
9933 );
9934  
9935 } else {
9936  
9937 # Store the expression, for $self->implement to evaluate
9938 $self->ivAdd('parseDataHash', 'create_exp', $expression);
9939 }
9940  
9941 } else {
9942  
9943 if (
9944 $nextToken->tokenText eq 'new'
9945 || $nextToken->tokenText eq 'old'
9946 || $nextToken->tokenText eq 'newold'
9947 ) {
9948 # Store the create file mode
9949 $self->ivAdd('parseDataHash', 'create_type', $nextToken->tokenText);
9950  
9951 } else {
9952  
9953 return $self->scriptObj->setError(
9954 'syntax_error',
9955 $self->_objClass . '->parse',
9956 );
9957 }
9958 }
9959  
9960 } elsif ($token->tokenText eq 'access') {
9961  
9962 # Next token must be one of the keywords OUTIN, INPUT, OUTPUT (can also be an
9963 # expression evaluating to 'outin', 'input' or 'output')
9964 $nextToken = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
9965 if (! $nextToken) {
9966  
9967 $expression = Language::Axbasic::Expression::Arithmetic->new(
9968 $self->scriptObj,
9969 $self->tokenGroupObj,
9970 );
9971  
9972 if (! $expression) {
9973  
9974 return $self->scriptObj->setError(
9975 'syntax_error',
9976 $self->_objClass . '->parse',
9977 );
9978  
9979 } else {
9980  
9981 # Store the expression, for $self->implement to evaluate
9982 $self->ivAdd('parseDataHash', 'access_exp', $expression);
9983 }
9984  
9985 } else {
9986  
9987 if (
9988 $nextToken->tokenText eq 'outin'
9989 || $nextToken->tokenText eq 'input'
9990 || $nextToken->tokenText eq 'output'
9991 ) {
9992 # Store the create file mode
9993 $self->ivAdd('parseDataHash', 'access_type', $nextToken->tokenText);
9994  
9995 } else {
9996  
9997 return $self->scriptObj->setError(
9998 'syntax_error',
9999 $self->_objClass . '->parse',
10000 );
10001 }
10002 }
10003  
10004 } else {
10005  
10006 return $self->scriptObj->setError(
10007 'syntax_error',
10008 $self->_objClass . '->parse',
10009 );
10010 }
10011 }
10012  
10013 } until (! defined $self->tokenGroupObj->shiftMatchingToken(','));
10014  
10015 # The NAME keyword, followed by a file expression, are compulsory
10016 if (! $nameFlag) {
10017  
10018 return $self->scriptObj->setError(
10019 'missing_file_NAME_in_OPEN_statement',
10020 $self->_objClass . '->parse',
10021 );
10022 }
10023  
10024 # Parsing complete
10025 return 1;
10026 }
10027  
10028 sub implement {
10029  
10030 # Called by LA::Line->implement directly after a call to $self->parse
10031 #
10032 # Expected arguments
10033 # (none besides $self)
10034 #
10035 # Return values
10036 # 'undef' on improper arguments or if there is an error
10037 # 1 otherwise
10038  
10039 my ($self, $check) = @_;
10040  
10041 # Local variables
10042 my (
10043 $channel, $fileExp, $orgType, $orgExp, $createType, $createExp, $accessType, $accessExp,
10044 $channelCount, $channelObj, $filePath, $file, $directory, $fileMode, $fileHandle,
10045 );
10046  
10047 # Check for improper arguments
10048 if (defined $check) {
10049  
10050 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10051 }
10052  
10053 # Retrieve the variables stored by ->parse
10054 $channel = $self->ivShow('parseDataHash', 'channel');
10055 $fileExp = $self->ivShow('parseDataHash', 'file_exp');
10056 $orgType = $self->ivShow('parseDataHash', 'org_type'); # Recognised, but not used
10057 $orgExp = $self->ivShow('parseDataHash', 'org_exp');
10058 $createType = $self->ivShow('parseDataHash', 'create_type');
10059 $createExp = $self->ivShow('parseDataHash', 'create_exp');
10060 $accessType = $self->ivShow('parseDataHash', 'access_type');
10061 $accessExp = $self->ivShow('parseDataHash', 'access_exp');
10062  
10063 # Check that the file channel is not already open
10064 if ($self->scriptObj->ivExists('fileChannelHash', $channel)) {
10065  
10066 return $self->scriptObj->setError(
10067 'file_channel_NUM_already_open',
10068 $self->_objClass . '->implement',
10069 'NUM', $channel,
10070 );
10071 }
10072  
10073 # Check that there aren't already too many channels open. True BASIC specifies a limit of
10074 # 25 simultaneous channels; same limit used by Axbasic
10075 $channelCount = $self->scriptObj->ivPairs('fileChannelHash');
10076 if ($channelCount >= 25) {
10077  
10078 return $self->scriptObj->setError(
10079 'file_channel_limit_reached',
10080 $self->_objClass . '->implement',
10081 'NUM', $channel,
10082 );
10083 }
10084  
10085 # OPEN statements can contain TEXT, NEW, OLD, NEWOLD, OUTIN, INPUT, OUTPUT option keywords.
10086 # If expressions were used instead, evaluate the expression
10087 if ($orgExp) {
10088  
10089 $orgType = lc($orgExp->evaluate());
10090 if (! $orgType || $orgType ne 'text') {
10091  
10092 return $self->scriptObj->setError(
10093 'invalid_option_in_OPEN_statement',
10094 $self->_objClass . '->implement',
10095 );
10096 }
10097 }
10098  
10099 if ($createExp) {
10100  
10101 $createType = lc($createExp->evaluate());
10102 if (
10103 ! $createType
10104 || ($createType ne 'new' && $createType ne 'old' && $createType ne 'newold')
10105 ) {
10106 return $self->scriptObj->setError(
10107 'invalid_option_in_OPEN_statement',
10108 $self->_objClass . '->implement',
10109 );
10110 }
10111 }
10112  
10113 if ($accessExp) {
10114  
10115 $accessType = lc($accessExp->evaluate());
10116 if (
10117 ! $accessType
10118 || ($accessType ne 'outin' && $accessType ne 'input' && $accessType ne 'output')
10119 ) {
10120 return $self->scriptObj->setError(
10121 'invalid_option_in_OPEN_statement',
10122 $self->_objClass . '->implement',
10123 );
10124 }
10125 }
10126  
10127 # OPEN statements can contain ORGANIZATION, CREATE and ACCESS option keywords but, if not,
10128 # set the default values
10129 if (! defined $orgType) {
10130  
10131 $orgType = 'text';
10132 }
10133  
10134 if (! defined $createType) {
10135  
10136 $createType = 'old';
10137 }
10138  
10139 if (! defined $accessType) {
10140  
10141 $accessType = 'outin';
10142 }
10143  
10144 # Evaluate the filepath expression
10145 $filePath = $fileExp->evaluate();
10146 if (! $filePath) {
10147  
10148 return $self->scriptObj->setError(
10149 'invalid_file_path',
10150 $self->_objClass . '->implement',
10151 );
10152  
10153 } else {
10154  
10155 # Assuming that $filePath is relative to the script's directory, convert it to an
10156 # absolute filepath
10157 # LA::Script->filePath is the path to the script's .bas file. Get its directory
10158 ($file, $directory) = File::Basename::fileparse($self->scriptObj->filePath);
10159 if ($directory) {
10160  
10161 $filePath = $directory . $filePath;
10162 }
10163 }
10164  
10165 # For CREATE NEW, display an error if the file already exists
10166 if ($createType eq 'new' && -e $filePath) {
10167  
10168 return $self->scriptObj->setError(
10169 'file_already_exists',
10170 $self->_objClass . '->implement',
10171 );
10172 }
10173  
10174 # For CREATE OLD, check that the file actually exists
10175 if ($createType eq 'old' && ! -e $filePath) {
10176  
10177 return $self->scriptObj->setError(
10178 'file_does_not_exist',
10179 $self->_objClass . '->implement',
10180 );
10181 }
10182  
10183 # CREATE NEW can't be used with ACCESS INPUT - can't read a file that doesn't exist
10184 if ($createType eq 'new' && $accessType eq 'input') {
10185  
10186 return $self->scriptObj->setError(
10187 'invalid_OPEN_statement_options',
10188 $self->_objClass . '->implement',
10189 );
10190 }
10191  
10192 # Axbasic simplifies things by opening a file in 'read/write' mode; every subsequent INPUT /
10193 # PRINT statement that uses this file channel checks the options specified by the CREATE
10194 # and ACCESS keywords, to make sure reading/writing is allowed
10195 if (! open ($fileHandle, "+>>", $filePath)) { # Read/write, create, don't truncate
10196  
10197 return $self->scriptObj->setError(
10198 'failed_to_open_file',
10199 $self->_objClass . '->implement',
10200 );
10201 }
10202  
10203 # However, for read-only and read/write modes, need to move the pointer to the beginning of
10204 # the file
10205 if ($accessType ne 'output') {
10206  
10207 seek($fileHandle, 0, Fcntl::SEEK_SET);
10208 }
10209  
10210 # File channel open. Create a file channel object
10211 $channelObj = Language::Axbasic::FileChannel->new(
10212 $self->scriptObj,
10213 $channel,
10214 $filePath,
10215 $fileHandle,
10216 $orgType,
10217 $createType,
10218 $accessType,
10219 );
10220  
10221 if (! $channelObj) {
10222  
10223 return $self->scriptObj->setError(
10224 'failed_to_open_channel',
10225 $self->_objClass . '->implement',
10226 );
10227  
10228 } else {
10229  
10230 # Update the script's IVs
10231 $self->scriptObj->add_fileChannel($channelObj);
10232  
10233 # Implementation complete
10234 return 1;
10235 }
10236 }
10237 }
10238  
10239 { package Language::Axbasic::Statement::openentry;
10240  
10241 use strict;
10242 use warnings;
10243 use diagnostics;
10244  
10245 use Glib qw(TRUE FALSE);
10246  
10247 @Language::Axbasic::Statement::openentry::ISA = qw(
10248 Language::Axbasic
10249 Language::Axbasic::Statement
10250 );
10251  
10252 # OPENENTRY
10253  
10254 ##################
10255 # Methods
10256  
10257 sub parse {
10258  
10259 # Called by LA::Line->parse directly after a call to LA::Statement->new
10260 #
10261 # Expected arguments
10262 # (none besides $self)
10263 #
10264 # Return values
10265 # 'undef' on improper arguments or if there is an error
10266 # 1 otherwise
10267  
10268 my ($self, $check) = @_;
10269  
10270 # Local variables
10271 my ($expression);
10272  
10273 # Check for improper arguments
10274 if (defined $check) {
10275  
10276 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10277 }
10278  
10279 # OPENENTRY statements always appear on their own
10280 if (! $self->tokenGroupObj->testStatementEnd()) {
10281  
10282 return $self->scriptObj->setError(
10283 'unexpected_keywords,_operators_or_expressions',
10284 $self->_objClass . '->parse',
10285 );
10286 }
10287  
10288 # Parsing complete
10289 return 1;
10290 }
10291  
10292 sub implement {
10293  
10294 # Called by LA::Line->implement directly after a call to $self->parse
10295 #
10296 # Expected arguments
10297 # (none besides $self)
10298 #
10299 # Return values
10300 # 'undef' on improper arguments or if there is an error
10301 # 1 otherwise
10302  
10303 my ($self, $check) = @_;
10304  
10305 # Local variables
10306  
10307 # Check for improper arguments
10308 if (defined $check) {
10309  
10310 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10311 }
10312  
10313 # If the Axbasic script is being run from within an Axmud task, open the window (unless one
10314 # is already open). Otherwise, do nothing
10315 if ($self->scriptObj->parentTask && ! $self->scriptObj->parentTask->taskWinFlag) {
10316  
10317 # Open a task window with an entry box (by specifying these arguments, we get either a
10318 # 'grid' window or a pane object in the session's 'main' window, both using an
10319 # entry box)
10320 $self->scriptObj->parentTask->openWin('entry_fill', 'pane', 'grid');
10321 }
10322  
10323 # Implementation complete
10324 return 1;
10325 }
10326 }
10327  
10328 { package Language::Axbasic::Statement::openwin;
10329  
10330 use strict;
10331 use warnings;
10332 use diagnostics;
10333  
10334 use Glib qw(TRUE FALSE);
10335  
10336 @Language::Axbasic::Statement::openwin::ISA = qw(
10337 Language::Axbasic
10338 Language::Axbasic::Statement
10339 );
10340  
10341 # OPENWIN
10342  
10343 ##################
10344 # Methods
10345  
10346 sub parse {
10347  
10348 # Called by LA::Line->parse directly after a call to LA::Statement->new
10349 #
10350 # Expected arguments
10351 # (none besides $self)
10352 #
10353 # Return values
10354 # 'undef' on improper arguments or if there is an error
10355 # 1 otherwise
10356  
10357 my ($self, $check) = @_;
10358  
10359 # Local variables
10360 my ($expression);
10361  
10362 # Check for improper arguments
10363 if (defined $check) {
10364  
10365 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10366 }
10367  
10368 # OPENWIN statements always appear on their own
10369 if (! $self->tokenGroupObj->testStatementEnd()) {
10370  
10371 return $self->scriptObj->setError(
10372 'unexpected_keywords,_operators_or_expressions',
10373 $self->_objClass . '->parse',
10374 );
10375 }
10376  
10377 # Parsing complete
10378 return 1;
10379 }
10380  
10381 sub implement {
10382  
10383 # Called by LA::Line->implement directly after a call to $self->parse
10384 #
10385 # Expected arguments
10386 # (none besides $self)
10387 #
10388 # Return values
10389 # 'undef' on improper arguments or if there is an error
10390 # 1 otherwise
10391  
10392 my ($self, $check) = @_;
10393  
10394 # Local variables
10395  
10396 # Check for improper arguments
10397 if (defined $check) {
10398  
10399 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10400 }
10401  
10402 # If the Axbasic script is being run from within an Axmud task, open the window (unless one
10403 # is already open). Otherwise, do nothing
10404 if ($self->scriptObj->parentTask && ! $self->scriptObj->parentTask->taskWinFlag) {
10405  
10406 # Open a task window with an entry box (by specifying these arguments, we get either a
10407 # 'grid' window or a pane object in the session's 'main' window, neither using an
10408 # entry box)
10409 $self->scriptObj->parentTask->openWin('basic_fill', 'entry', 'grid');
10410 }
10411  
10412 # Implementation complete
10413 return 1;
10414 }
10415 }
10416  
10417 { package Language::Axbasic::Statement::option;
10418  
10419 use strict;
10420 use warnings;
10421 use diagnostics;
10422  
10423 use Glib qw(TRUE FALSE);
10424  
10425 @Language::Axbasic::Statement::option::ISA = qw(
10426 Language::Axbasic
10427 Language::Axbasic::Statement
10428 );
10429  
10430 # OPTION ANGLE DEGREES
10431 # OPTION ANGLE RADIANS
10432 # OPTION NEEDTASK
10433 # OPTION NOLET
10434 # OPTION PERSIST
10435 # OPTION PSEUDO expression
10436 # OPTION REDIRECT
10437 # OPTION REQUIRE expression
10438 # OPTION SILENT
10439 # OPTION TYPO
10440  
10441 ##################
10442 # Methods
10443  
10444 sub parse {
10445  
10446 # Called by LA::Line->parse directly after a call to LA::Statement->new
10447 #
10448 # Expected arguments
10449 # (none besides $self)
10450 #
10451 # Return values
10452 # 'undef' on improper arguments or if there is an error
10453 # 1 otherwise
10454  
10455 my ($self, $check) = @_;
10456  
10457 # Local variables
10458 my ($token, $expression, $value);
10459  
10460 # Check for improper arguments
10461 if (defined $check) {
10462  
10463 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10464 }
10465  
10466 # OPTION ANGLE DEGREES statement
10467 # OPTION ANGLE RADIANS statement
10468 $token = $self->tokenGroupObj->shiftMatchingToken('angle');
10469 if (defined $token) {
10470  
10471 $token = $self->tokenGroupObj->shiftMatchingToken('degrees');
10472 if (! defined $token) {
10473  
10474 $token = $self->tokenGroupObj->shiftMatchingToken('radians');
10475 }
10476  
10477 if (defined $token) {
10478  
10479 if (! $self->tokenGroupObj->testStatementEnd()) {
10480  
10481 return $self->scriptObj->setError(
10482 'unexpected_keywords,_operators_or_expressions',
10483 $self->_objClass . '->parse',
10484 );
10485  
10486 } elsif ($token->tokenText eq 'degrees') {
10487  
10488 $self->scriptObj->add_optionStatement('angle', 'degrees');
10489  
10490 } else {
10491  
10492 $self->scriptObj->add_optionStatement('angle', 'radians');
10493 }
10494  
10495 return 1;
10496  
10497 } else {
10498  
10499 return $self->scriptObj->setError(
10500 'syntax_error',
10501 $self->_objClass . '->parse',
10502 );
10503 }
10504 }
10505  
10506 # OPTION NEEDTASK statement
10507 $token = $self->tokenGroupObj->shiftMatchingToken('needtask');
10508 if (defined $token) {
10509  
10510 if (! $self->tokenGroupObj->testStatementEnd()) {
10511  
10512 return $self->scriptObj->setError(
10513 'unexpected_keywords,_operators_or_expressions',
10514 $self->_objClass . '->parse',
10515 );
10516  
10517 } elsif (! $self->scriptObj->parentTask) {
10518  
10519 return $self->scriptObj->setError(
10520 'script_cannot_run_without_parent_task',
10521 $self->_objClass . '->parse',
10522 );
10523  
10524 } else {
10525  
10526 $self->scriptObj->add_optionStatement('needtask', TRUE);
10527 return 1;
10528 }
10529 }
10530  
10531 # OPTION NOLET statement
10532 $token = $self->tokenGroupObj->shiftMatchingToken('nolet');
10533 if (defined $token) {
10534  
10535 if (! $self->tokenGroupObj->testStatementEnd()) {
10536  
10537 return $self->scriptObj->setError(
10538 'unexpected_keywords,_operators_or_expressions',
10539 $self->_objClass . '->parse',
10540 );
10541  
10542 } else {
10543  
10544 $self->scriptObj->add_optionStatement('nolet', TRUE);
10545 return 1;
10546 }
10547 }
10548  
10549 # OPTION PERSIST statement
10550 $token = $self->tokenGroupObj->shiftMatchingToken('persist');
10551 if (defined $token) {
10552  
10553 if (! $self->tokenGroupObj->testStatementEnd()) {
10554  
10555 return $self->scriptObj->setError(
10556 'unexpected_keywords,_operators_or_expressions',
10557 $self->_objClass . '->parse',
10558 );
10559  
10560 } else {
10561  
10562 $self->scriptObj->add_optionStatement('persist', TRUE);
10563 return 1;
10564 }
10565 }
10566  
10567 # OPTION PSEUDO String-Exp
10568 $token = $self->tokenGroupObj->shiftMatchingToken('pseudo');
10569 if (defined $token) {
10570  
10571 # Get the expression
10572 $expression = Language::Axbasic::Expression::Arithmetic->new(
10573 $self->scriptObj,
10574 $self->tokenGroupObj,
10575 );
10576  
10577 if (! defined $expression) {
10578  
10579 return $self->scriptObj->setError(
10580 'missing_or_illegal_expression',
10581 $self->_objClass . '->parse',
10582 );
10583 }
10584  
10585 # There should be nothing more
10586 if (! $self->tokenGroupObj->testStatementEnd()) {
10587  
10588 return $self->scriptObj->setError(
10589 'unexpected_keywords,_operators_or_expressions',
10590 $self->_objClass . '->parse',
10591 );
10592 }
10593  
10594 # Check that a valid expression has been specified
10595 # Evaluate the expression
10596 $value = $expression->evaluate();
10597 if (
10598 ! defined $value
10599 || (
10600 $value ne 'show_all' && $value ne 'hide_complete' && $value ne 'hide_system'
10601 && $value ne 'win_error' && $value ne 'win_only'
10602 )
10603 ) {
10604 return $self->scriptObj->setError(
10605 'invalid_expression',
10606 $self->_objClass . '->parse',
10607 )
10608 }
10609  
10610 # Set the new pseudo-command mode
10611 $self->scriptObj->add_optionStatement('pseudo', $value);
10612 $self->scriptObj->set_pseudoCmdMode($value);
10613  
10614 return 1;
10615 }
10616  
10617 # OPTION REDIRECT statement
10618 $token = $self->tokenGroupObj->shiftMatchingToken('redirect');
10619 if (defined $token) {
10620  
10621 if (! $self->tokenGroupObj->testStatementEnd()) {
10622  
10623 return $self->scriptObj->setError(
10624 'unexpected_keywords,_operators_or_expressions',
10625 $self->_objClass . '->parse',
10626 );
10627  
10628 } else {
10629  
10630 $self->scriptObj->add_optionStatement('redirect', TRUE);
10631 return 1;
10632 }
10633 }
10634  
10635 # OPTION REQUIRE Arith-Exp statement
10636 $token = $self->tokenGroupObj->shiftMatchingToken('require');
10637 if (defined $token) {
10638  
10639 # Get the expression
10640 $expression = Language::Axbasic::Expression::Arithmetic->new(
10641 $self->scriptObj,
10642 $self->tokenGroupObj,
10643 );
10644  
10645 if (! defined $expression) {
10646  
10647 return $self->scriptObj->setError(
10648 'missing_or_illegal_expression',
10649 $self->_objClass . '->parse',
10650 );
10651 }
10652  
10653 # There should be nothing more
10654 if (! $self->tokenGroupObj->testStatementEnd()) {
10655  
10656 return $self->scriptObj->setError(
10657 'unexpected_keywords,_operators_or_expressions',
10658 $self->_objClass . '->parse',
10659 );
10660 }
10661  
10662 # Check that a valid expression (floating point numbers, 1.0 or above) has been
10663 # specified
10664 # Evaluate the expression
10665 $value = $expression->evaluate();
10666 if (
10667 ! defined $value
10668 || ! ($value =~ /^-?(?:\d+\.?|\.\d)\d*\z/)
10669 ) {
10670 return $self->scriptObj->setError(
10671 'invalid_version',
10672 $self->_objClass . '->parse',
10673 )
10674  
10675 } elsif ($value < 1) {
10676  
10677 return $self->scriptObj->setError(
10678 'version_NUM_out_of_range',
10679 $self->_objClass . '->parse',
10680 'NUM', $value,
10681 )
10682  
10683 } elsif ($value > $axmud::BASIC_VERSION) {
10684  
10685 return $self->scriptObj->setError(
10686 'script_requires_version_NUM',
10687 $self->_objClass . '->parse',
10688 'NUM', $value,
10689 );
10690 }
10691  
10692 # Set the new minimum version
10693 $self->scriptObj->add_optionStatement('require', $value);
10694  
10695 return 1;
10696 }
10697  
10698 # OPTION SILENT statement
10699 $token = $self->tokenGroupObj->shiftMatchingToken('silent');
10700 if (defined $token) {
10701  
10702 if (! $self->tokenGroupObj->testStatementEnd()) {
10703  
10704 return $self->scriptObj->setError(
10705 'unexpected_keywords,_operators_or_expressions',
10706 $self->_objClass . '->parse',
10707 );
10708  
10709 } else {
10710  
10711 $self->scriptObj->add_optionStatement('silent', TRUE);
10712 return 1;
10713 }
10714 }
10715  
10716 # OPTION TYPO statement
10717 $token = $self->tokenGroupObj->shiftMatchingToken('typo');
10718 if (defined $token) {
10719  
10720 if (! $self->tokenGroupObj->testStatementEnd()) {
10721  
10722 return $self->scriptObj->setError(
10723 'unexpected_keywords,_operators_or_expressions',
10724 $self->_objClass . '->parse',
10725 );
10726  
10727 } else {
10728  
10729 $self->scriptObj->add_optionStatement('typo', TRUE);
10730  
10731 return 1;
10732 }
10733 }
10734  
10735 # Default
10736 return $self->scriptObj->setError(
10737 'syntax_error',
10738 $self->_objClass . '->parse',
10739 );
10740  
10741 # Parsing complete
10742 return 1;
10743 }
10744  
10745 # No ->implement function needed
10746 }
10747  
10748 { package Language::Axbasic::Statement::paintwin;
10749  
10750 use strict;
10751 use warnings;
10752 use diagnostics;
10753  
10754 use Glib qw(TRUE FALSE);
10755  
10756 @Language::Axbasic::Statement::paintwin::ISA = qw(
10757 Language::Axbasic
10758 Language::Axbasic::Statement
10759 );
10760  
10761 # PAINTWIN [ expression ]
10762  
10763 ##################
10764 # Methods
10765  
10766 sub parse {
10767  
10768 # Called by LA::Line->parse directly after a call to LA::Statement->new
10769 #
10770 # Expected arguments
10771 # (none besides $self)
10772 #
10773 # Return values
10774 # 'undef' on improper arguments or if there is an error
10775 # 1 otherwise
10776  
10777 my ($self, $check) = @_;
10778  
10779 # Local variables
10780 my $paintExp;
10781  
10782 # Check for improper arguments
10783 if (defined $check) {
10784  
10785 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10786 }
10787  
10788 if (! $self->tokenGroupObj->testStatementEnd()) {
10789  
10790 # Convert the name string into an expression
10791 $paintExp = Language::Axbasic::Expression::Arithmetic->new(
10792 $self->scriptObj,
10793 $self->tokenGroupObj,
10794 );
10795  
10796 if (! defined $paintExp) {
10797  
10798 return $self->scriptObj->setError(
10799 'missing_or_illegal_expression',
10800 $self->_objClass . '->parse',
10801 );
10802 }
10803 }
10804  
10805 # Check that nothing more remains
10806 if (! $self->tokenGroupObj->testStatementEnd()) {
10807  
10808 return $self->scriptObj->setError(
10809 'unexpected_keywords,_operators_or_expressions',
10810 $self->_objClass . '->parse',
10811 );
10812 }
10813  
10814 if ($paintExp) {
10815  
10816 # Store the expression, so $self->implement can retrieve it
10817 $self->ivAdd('parseDataHash', 'paint_exp', $paintExp);
10818 }
10819  
10820 # Parsing complete
10821 return 1;
10822 }
10823  
10824 sub implement {
10825  
10826 # Called by LA::Line->implement directly after a call to $self->parse
10827 #
10828 # Expected arguments
10829 # (none besides $self)
10830 #
10831 # Return values
10832 # 'undef' on improper arguments or if there is an error
10833 # 1 otherwise
10834  
10835 my ($self, $check) = @_;
10836  
10837 # Local variables
10838 my ($paintExp, $paint, $type, $taskObj);
10839  
10840 # Check for improper arguments
10841 if (defined $check) {
10842  
10843 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10844 }
10845  
10846 # Retrieve the argument stored by $self->parse
10847 $paintExp = $self->ivShow('parseDataHash', 'paint_exp');
10848  
10849 if (defined $paintExp) {
10850  
10851 # Evaluate the expression
10852 $paint = $paintExp->evaluate();
10853 }
10854  
10855 # Import the parent task (if any)
10856 $taskObj = $self->scriptObj->parentTask;
10857  
10858 # If the Axbasic script is being run from within an Axmud task and the window is open, paint
10859 # it. Otherwise, do nothing
10860 if ($taskObj && $taskObj->taskWinFlag) {
10861  
10862 if (defined $paintExp) {
10863  
10864 # Evaluate the expression
10865 $paint = $paintExp->evaluate();
10866 # Is it a valid Axmud standard colour tag (not xterm or RGB)?
10867 ($type) = $axmud::CLIENT->checkColourTags($paint, 'standard');
10868 if (! $type) {
10869  
10870 return $self->scriptObj->setError(
10871 'invalid_colour_tag_TAG',
10872 $self->_objClass . '->implement',
10873 'TAG',
10874 $paint,
10875 );
10876 }
10877 }
10878  
10879 # Paint the window
10880 $taskObj->paintWin($paint);
10881 }
10882  
10883 # Implementation complete
10884 return 1;
10885 }
10886 }
10887  
10888 { package Language::Axbasic::Statement::pause;
10889  
10890 use strict;
10891 use warnings;
10892 use diagnostics;
10893  
10894 use Glib qw(TRUE FALSE);
10895  
10896 @Language::Axbasic::Statement::pause::ISA = qw(
10897 Language::Axbasic
10898 Language::Axbasic::Statement
10899 );
10900  
10901 # PAUSE expression
10902 # SLEEP expression
10903  
10904 ##################
10905 # Methods
10906  
10907 sub parse {
10908  
10909 # Called by LA::Line->parse directly after a call to LA::Statement->new
10910 #
10911 # Expected arguments
10912 # (none besides $self)
10913 #
10914 # Return values
10915 # 'undef' on improper arguments or if there is an error
10916 # 1 otherwise
10917  
10918 my ($self, $check) = @_;
10919  
10920 # Local variables
10921 my ($expression);
10922  
10923 # Check for improper arguments
10924 if (defined $check) {
10925  
10926 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10927 }
10928  
10929 # The rest of the statement is an arithmetic expression which evaluates to a number of
10930 # seconds
10931 $expression = Language::Axbasic::Expression::Arithmetic->new(
10932 $self->scriptObj,
10933 $self->tokenGroupObj,
10934 );
10935  
10936 if (! defined $expression) {
10937  
10938 return $self->scriptObj->setError(
10939 'missing_or_illegal_expression',
10940 $self->_objClass . '->parse',
10941 );
10942 }
10943  
10944 # Check that nothing follows the expression
10945 if (! $self->tokenGroupObj->testStatementEnd()) {
10946  
10947 return $self->scriptObj->setError(
10948 'unexpected_keywords,_operators_or_expressions',
10949 $self->_objClass . '->parse',
10950 );
10951 }
10952  
10953 # Store the arithmetic expression, so $self->implement can retrieve it
10954 $self->ivAdd('parseDataHash', 'expression', $expression);
10955  
10956 # Parsing complete
10957 return 1;
10958 }
10959  
10960 sub implement {
10961  
10962 # Called by LA::Line->implement directly after a call to $self->parse
10963 #
10964 # Expected arguments
10965 # (none besides $self)
10966 #
10967 # Return values
10968 # 'undef' on improper arguments or if there is an error
10969 # 1 otherwise
10970  
10971 my ($self, $check) = @_;
10972  
10973 # Local variables
10974 my ($expression, $seconds);
10975  
10976 # Check for improper arguments
10977 if (defined $check) {
10978  
10979 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10980 }
10981  
10982 # Retrieve the variable stored by ->parse
10983 $expression = $self->ivShow('parseDataHash', 'expression');
10984  
10985 # Evaluate the expression to get a number of seconds (which can be fractional, but must be
10986 # > 0)
10987 $seconds = $expression->evaluate();
10988 if (! ($seconds =~ /^\d+$/)) {
10989  
10990 return $self->scriptObj->setError(
10991 'invalid_integer',
10992 $self->_objClass . '->implement',
10993 );
10994  
10995 } elsif ($seconds < 1) {
10996  
10997 return $self->scriptObj->setError(
10998  
10999 'number_NUM_out_of_range',
11000 $self->_objClass . '->parse',
11001 'NUM', $seconds,
11002 );
11003 }
11004  
11005 # If the Axbasic script is being run from within an Axmud task, pause execution, otherwise
11006 # do nothing
11007 if ($self->scriptObj->parentTask) {
11008  
11009 # Mark this script as paused
11010 $self->scriptObj->set_scriptStatus('paused');
11011 # Reset the number of steps to take, before taking an automatic pause
11012 $self->scriptObj->set_stepCount(0);
11013  
11014 # Also, tell the parent task to pause
11015 $self->scriptObj->parentTask->pauseUntil(
11016 ($self->scriptObj->session->sessionTime + $seconds),
11017 );
11018 }
11019  
11020 # Implementation complete
11021 return 1;
11022 }
11023 }
11024  
11025 { package Language::Axbasic::Statement::peek;
11026  
11027 use strict;
11028 use warnings;
11029 use diagnostics;
11030  
11031 use Glib qw(TRUE FALSE);
11032  
11033 @Language::Axbasic::Statement::peek::ISA = qw(
11034 Language::Axbasic
11035 Language::Axbasic::Statement
11036 );
11037  
11038 # PEEK variable-name = axmud-object-name
11039 # PEEK variable-name = axmud-object-property
11040 # PEEK ARRAY variable-name = axmud-object-property
11041  
11042 ##################
11043 # Methods
11044  
11045 sub parse {
11046  
11047 # Called by LA::Line->parse directly after a call to LA::Statement->new
11048 #
11049 # Expected arguments
11050 # (none besides $self)
11051 #
11052 # Return values
11053 # 'undef' on improper arguments or if there is an error
11054 # 1 otherwise
11055  
11056 my ($self, $check) = @_;
11057  
11058 # Check for improper arguments
11059 if (defined $check) {
11060  
11061 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11062 }
11063  
11064 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11065 # $self->parseDataHash, ready for $self->implement to access
11066 if (! $self->parsePeek()) {
11067  
11068 # ($self->scriptObj->setError has already been called)
11069 return undef;
11070 }
11071  
11072 # Parsing complete
11073 return 1;
11074 }
11075  
11076 sub implement {
11077  
11078 # Called by LA::Line->implement directly after a call to $self->parse
11079 #
11080 # Expected arguments
11081 # (none besides $self)
11082 #
11083 # Return values
11084 # 'undef' on improper arguments or if there is an error
11085 # 1 otherwise
11086  
11087 my ($self, $check) = @_;
11088  
11089 # Local variables
11090 my (
11091 # Standard
11092 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11093 $var, $objFlag, $privFlag, $scalar, $varObj,
11094 @array,
11095 # Custom (set after $varObj is set)
11096 $impScalarFlag, $impArrayFlag,
11097 );
11098  
11099 # Check for improper arguments
11100 if (defined $check) {
11101  
11102 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11103 }
11104  
11105 # Get the values stored by $self->parse
11106 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11107 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11108 $expression = $self->ivShow('parseDataHash', 'expression');
11109  
11110 # Evaluate the expression to get the Axmud internal variable, e.g. "world.current.name"
11111 $expValue = $expression->evaluate();
11112 # Process the string representing the Axmud internal variable
11113 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11114 = $self->scriptObj->session->parsePeekPoke($expValue);
11115 if (! $successFlag) {
11116  
11117 return $self->scriptObj->setError(
11118 'PEEK_operation_failure',
11119 $self->_objClass . '->implement',
11120 );
11121 }
11122  
11123 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11124 # or @array if $string refers to a list or hash value
11125 if (! $objFlag) {
11126  
11127 if (! defined $var) {
11128  
11129 $scalar = undef;
11130 $impScalarFlag = TRUE;
11131  
11132 } elsif (ref($var) eq 'ARRAY') {
11133  
11134 @array = @$var;
11135 $impArrayFlag = TRUE;
11136  
11137 } elsif (ref($var) eq 'HASH') {
11138  
11139 @array = %$var;
11140 $impArrayFlag = TRUE; # Perl hash gets converted to an Axbasic array
11141  
11142 } else {
11143  
11144 $scalar = $var;
11145 $impScalarFlag = TRUE;
11146 }
11147  
11148 # If this was a PEEK ARRAY statement, but the IV is a scalar, copy it into the first
11149 # cell of the Axbasic array (being an array containing 1 element)
11150 if ($impScalarFlag && $parseArrayFlag) {
11151  
11152 push (@array, $scalar);
11153  
11154 # Don't let the user copy a list/hash IV into an Axbasic scalar variable
11155 } elsif ($impArrayFlag && ! $parseArrayFlag) {
11156  
11157 return $self->scriptObj->setError(
11158 'PEEK_operation_failure',
11159 $self->_objClass . '->implement',
11160 );
11161 }
11162  
11163 } else {
11164  
11165 # Set $scalar to the Perl object
11166 if ($parseArrayFlag) {
11167  
11168 # We'll let the user copy an Axmud scalar IV into an Axbasic array, but we won't let
11169 # them copy a Perl object into an Axbasic array
11170 return $self->scriptObj->setError(
11171 'PEEK_operation_failure',
11172 $self->_objClass . '->implement',
11173 );
11174  
11175 } else {
11176  
11177 $scalar = $blessed;
11178 $impScalarFlag = TRUE;
11179 }
11180 }
11181  
11182 # Look up the LA::Variable
11183 $varObj = $self->fetchVar('PEEK', $basicVarName, $parseArrayFlag);
11184 if (! $varObj) {
11185  
11186 # (self->scriptObj->setError already called)
11187 return undef;
11188 }
11189  
11190 # Now we can set the variable to PEEK's return value
11191 if (! $parseArrayFlag) {
11192  
11193 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11194 # neccesary
11195 $self->importAsScalar($varObj, $scalar);
11196  
11197 } else {
11198  
11199 # Import the list/hash into an Axbasic array, resizing it as necessary
11200 $self->importAsArray($varObj, @array);
11201 }
11202  
11203 # Implementation complete
11204 return 1;
11205 }
11206 }
11207  
11208 { package Language::Axbasic::Statement::peekequals;
11209  
11210 use strict;
11211 use warnings;
11212 use diagnostics;
11213  
11214 use Glib qw(TRUE FALSE);
11215  
11216 @Language::Axbasic::Statement::peekequals::ISA = qw(
11217 Language::Axbasic
11218 Language::Axbasic::Statement
11219 );
11220  
11221 # PEEKEQUALS variable-name = axmud-object-property, expression
11222 # PEEKEQUALS ARRAY variable-name = axmud-object-property, expression
11223  
11224 ##################
11225 # Methods
11226  
11227 sub parse {
11228  
11229 # Called by LA::Line->parse directly after a call to LA::Statement->new
11230 #
11231 # Expected arguments
11232 # (none besides $self)
11233 #
11234 # Return values
11235 # 'undef' on improper arguments or if there is an error
11236 # 1 otherwise
11237  
11238 my ($self, $check) = @_;
11239  
11240 # Check for improper arguments
11241 if (defined $check) {
11242  
11243 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11244 }
11245  
11246 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11247 # $self->parseDataHash, ready for $self->implement to access
11248 if (! $self->parsePeek(FALSE, TRUE)) {
11249  
11250 # ($self->scriptObj->setError has already been called)
11251 return undef;
11252 }
11253  
11254 # Parsing complete
11255 return 1;
11256 }
11257  
11258 sub implement {
11259  
11260 # Called by LA::Line->implement directly after a call to $self->parse
11261 #
11262 # Expected arguments
11263 # (none besides $self)
11264 #
11265 # Return values
11266 # 'undef' on improper arguments or if there is an error
11267 # 1 otherwise
11268  
11269 my ($self, $check) = @_;
11270  
11271 # Local variables
11272 my (
11273 # Standard
11274 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11275 $var, $objFlag, $privFlag, $scalar, $varObj,
11276 @array,
11277 # Custom (set after $varObj is set)
11278 $matchExp, $match, $matchIndex,
11279 );
11280  
11281 # Check for improper arguments
11282 if (defined $check) {
11283  
11284 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11285 }
11286  
11287 # Get the values stored by $self->parse
11288 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11289 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11290 $expression = $self->ivShow('parseDataHash', 'expression');
11291 $matchExp = $self->ivShow('parseDataHash', 'extra_exp');
11292  
11293 # Evaluate the first expression to get the Axmud internal variable, e.g.
11294 # "current.world.name"
11295 $expValue = $expression->evaluate();
11296 # Evaluate the second expression to get a numeric value
11297 $match = $matchExp->evaluate();
11298 if (! defined $match || ! ($match =~ /^\d+$/)) {
11299  
11300 return $self->scriptObj->setError(
11301 'invalid_matching_expression',
11302 $self->_objClass . '->implement',
11303 );
11304 }
11305  
11306 # Process the string representing the Axmud internal variable
11307 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11308 = $self->scriptObj->session->parsePeekPoke($expValue);
11309 if (! $successFlag) {
11310  
11311 return $self->scriptObj->setError(
11312 'PEEKEQUALS_operation_failure',
11313 $self->_objClass . '->implement',
11314 );
11315 }
11316  
11317 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11318 # or @array if $string refers to a list or hash value
11319 if (! $objFlag) {
11320  
11321 # This statement only accepts Perl scalars
11322 if (defined $var && ref($var) eq 'ARRAY') {
11323  
11324 @array = @$var;
11325  
11326 } else {
11327  
11328 return $self->scriptObj->setError(
11329 'PEEKEQUALS_operation_expects_list',
11330 $self->_objClass . '->implement',
11331 );
11332 }
11333  
11334 } else {
11335  
11336 return $self->scriptObj->setError(
11337 'PEEKEQUALS_cannot_import_object',
11338 $self->_objClass . '->implement',
11339 );
11340 }
11341  
11342 # Look up the LA::Variable
11343 $varObj = $self->fetchVar('PEEKEQUALS', $basicVarName, $parseArrayFlag);
11344 if (! $varObj) {
11345  
11346 # (self->scriptObj->setError already called)
11347 return undef;
11348 }
11349  
11350 # Now we can set the variable to PEEKEQUALS's return value
11351 # Assuming the array is not empty, walk the array looking for a value which is the same as
11352 # $match
11353 if (@array) {
11354  
11355 OUTER: for (my $count = 0; $count < scalar @array; $count++) {
11356  
11357 my $number;
11358  
11359 if (defined $array[$count]) {
11360  
11361 $number = $array[$count];
11362 if (
11363 $number =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/
11364 && $number == $match
11365 ) {
11366  
11367 # Matching value found at index $count
11368 $matchIndex = $count;
11369 last OUTER;
11370 }
11371 }
11372 }
11373 }
11374  
11375 if (! defined $matchIndex) {
11376  
11377 # List is empty, or a matching value was not found
11378 $matchIndex = -1;
11379 }
11380  
11381 if (! $parseArrayFlag) {
11382  
11383 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11384 # necessary
11385 $self->importAsScalar($varObj, $matchIndex);
11386  
11387 } else {
11388  
11389 # Import the list/hash into an Axbasic array, resizing it as necessary
11390 $self->importAsArray($varObj, $matchIndex);
11391 }
11392  
11393 # Implementation complete
11394 return 1;
11395 }
11396 }
11397  
11398 { package Language::Axbasic::Statement::peekexists;
11399  
11400 use strict;
11401 use warnings;
11402 use diagnostics;
11403  
11404 use Glib qw(TRUE FALSE);
11405  
11406 @Language::Axbasic::Statement::peekexists::ISA = qw(
11407 Language::Axbasic
11408 Language::Axbasic::Statement
11409 );
11410  
11411 # PEEKEXISTS variable-name = axmud-object-property, expression
11412 # PEEKEXISTS ARRAY variable-name = axmud-object-property, expression
11413  
11414 ##################
11415 # Methods
11416  
11417 sub parse {
11418  
11419 # Called by LA::Line->parse directly after a call to LA::Statement->new
11420 #
11421 # Expected arguments
11422 # (none besides $self)
11423 #
11424 # Return values
11425 # 'undef' on improper arguments or if there is an error
11426 # 1 otherwise
11427  
11428 my ($self, $check) = @_;
11429  
11430 # Check for improper arguments
11431 if (defined $check) {
11432  
11433 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11434 }
11435  
11436 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11437 # $self->parseDataHash, ready for $self->implement to access
11438 if (! $self->parsePeek(FALSE, TRUE)) {
11439  
11440 # ($self->scriptObj->setError has already been called)
11441 return undef;
11442 }
11443  
11444 # Parsing complete
11445 return 1;
11446 }
11447  
11448 sub implement {
11449  
11450 # Called by LA::Line->implement directly after a call to $self->parse
11451 #
11452 # Expected arguments
11453 # (none besides $self)
11454 #
11455 # Return values
11456 # 'undef' on improper arguments or if there is an error
11457 # 1 otherwise
11458  
11459 my ($self, $check) = @_;
11460  
11461 # Local variables
11462 my (
11463 # Standard
11464 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11465 $var, $objFlag, $privFlag, $scalar, $varObj,
11466 @array,
11467 # Custom (set after $varObj is set)
11468 $keyExp, $hashKey, $flagValue,
11469 %hash,
11470 );
11471  
11472 # Check for improper arguments
11473 if (defined $check) {
11474  
11475 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11476 }
11477  
11478 # Get the values stored by $self->parse
11479 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11480 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11481 $expression = $self->ivShow('parseDataHash', 'expression');
11482 $keyExp = $self->ivShow('parseDataHash', 'extra_exp');
11483  
11484 # Evaluate the first expression to get the Axmud internal variable, e.g.
11485 # "current.world.name"
11486 $expValue = $expression->evaluate();
11487 # Process the string representing the Axmud internal variable
11488 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11489 = $self->scriptObj->session->parsePeekPoke($expValue);
11490 if (! $successFlag) {
11491  
11492 return $self->scriptObj->setError(
11493 'PEEKEXISTS_operation_failure',
11494 $self->_objClass . '->implement',
11495 );
11496 }
11497  
11498 # Evaluate the second expression to get a hash key, e.g. 'gold'
11499 $hashKey = $keyExp->evaluate();
11500  
11501 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11502 # or @array if $string refers to a list or hash value
11503 if (! $objFlag) {
11504  
11505 # This statement only accepts Perl hashes
11506 if (defined $var && ref($var) eq 'HASH') {
11507  
11508 %hash = %$var;
11509  
11510 } else {
11511  
11512 return $self->scriptObj->setError(
11513 'PEEKEXISTS_operation_expects_hash',
11514 $self->_objClass . '->implement',
11515 );
11516 }
11517  
11518 } else {
11519  
11520 return $self->scriptObj->setError(
11521 'PEEKEXISTS_cannot_import_object',
11522 $self->_objClass . '->implement',
11523 );
11524 }
11525  
11526 # Look up the LA::Variable
11527 $varObj = $self->fetchVar('PEEKEXISTS', $basicVarName, $parseArrayFlag);
11528 if (! $varObj) {
11529  
11530 # (self->scriptObj->setError already called)
11531 return undef;
11532 }
11533  
11534 # Now we can set the variable to PEEKEXISTS's return value
11535 if (! exists $hash{$hashKey}) {
11536  
11537 # $hashKey doesn't exist in the hash
11538 if (ref($varObj) =~ m/Numeric/) {
11539 $flagValue = 0;
11540 } else {
11541 $flagValue = 'false';
11542 }
11543  
11544 } else {
11545  
11546 # $hashKey does exist in the hash
11547 if (ref($varObj) =~ m/Numeric/) {
11548 $flagValue = 1;
11549 } else {
11550 $flagValue = 'true';
11551 }
11552 }
11553  
11554 if (! $parseArrayFlag) {
11555  
11556 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11557 # necessary
11558 $self->importAsScalar($varObj, $flagValue);
11559  
11560 } else {
11561  
11562 # Import the list/hash into an Axbasic array, resizing it as necessary
11563 $self->importAsArray($varObj, $flagValue);
11564 }
11565  
11566 # Implementation complete
11567 return 1;
11568 }
11569 }
11570  
11571 { package Language::Axbasic::Statement::peekfind;
11572  
11573 use strict;
11574 use warnings;
11575 use diagnostics;
11576  
11577 use Glib qw(TRUE FALSE);
11578  
11579 @Language::Axbasic::Statement::peekfind::ISA = qw(
11580 Language::Axbasic
11581 Language::Axbasic::Statement
11582 );
11583  
11584 # PEEKFIND variable-name = axmud-object-property, expression
11585 # PEEKFIND ARRAY variable-name = axmud-object-property, expression
11586  
11587 ##################
11588 # Methods
11589  
11590 sub parse {
11591  
11592 # Called by LA::Line->parse directly after a call to LA::Statement->new
11593 #
11594 # Expected arguments
11595 # (none besides $self)
11596 #
11597 # Return values
11598 # 'undef' on improper arguments or if there is an error
11599 # 1 otherwise
11600  
11601 my ($self, $check) = @_;
11602  
11603 # Check for improper arguments
11604 if (defined $check) {
11605  
11606 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11607 }
11608  
11609 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11610 # $self->parseDataHash, ready for $self->implement to access
11611 if (! $self->parsePeek(FALSE, TRUE)) {
11612  
11613 # ($self->scriptObj->setError has already been called)
11614 return undef;
11615 }
11616  
11617 # Parsing complete
11618 return 1;
11619 }
11620  
11621 sub implement {
11622  
11623 # Called by LA::Line->implement directly after a call to $self->parse
11624 #
11625 # Expected arguments
11626 # (none besides $self)
11627 #
11628 # Return values
11629 # 'undef' on improper arguments or if there is an error
11630 # 1 otherwise
11631  
11632 my ($self, $check) = @_;
11633  
11634 # Local variables
11635 my (
11636 # Standard
11637 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11638 $var, $objFlag, $privFlag, $scalar, $varObj,
11639 @array,
11640 # Custom (set after $varObj is set)
11641 $matchExp, $match, $matchIndex,
11642 );
11643  
11644 # Check for improper arguments
11645 if (defined $check) {
11646  
11647 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11648 }
11649  
11650 # Get the values stored by $self->parse
11651 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11652 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11653 $expression = $self->ivShow('parseDataHash', 'expression');
11654 $matchExp = $self->ivShow('parseDataHash', 'extra_exp');
11655  
11656 # Evaluate the first expression to get the Axmud internal variable, e.g.
11657 # "current.world.name"
11658 $expValue = $expression->evaluate();
11659 # Evaluate the second expression to get a numeric/string value (allow 0, but not empty
11660 # strings)
11661 $match = $matchExp->evaluate();
11662 if (! defined $match || length($match) == 0) {
11663  
11664 return $self->scriptObj->setError(
11665 'invalid_matching_expression',
11666 $self->_objClass . '->implement',
11667 );
11668 }
11669  
11670 # Process the string representing the Axmud internal variable
11671 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11672 = $self->scriptObj->session->parsePeekPoke($expValue);
11673 if (! $successFlag) {
11674  
11675 return $self->scriptObj->setError(
11676 'PEEKFIND_operation_failure',
11677 $self->_objClass . '->implement',
11678 );
11679 }
11680  
11681 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11682 # or @array if $string refers to a list or hash value
11683 if (! $objFlag) {
11684  
11685 # This statement only accepts Perl scalars
11686 if (defined $var && ref($var) eq 'ARRAY') {
11687  
11688 @array = @$var;
11689  
11690 } else {
11691  
11692 return $self->scriptObj->setError(
11693 'PEEKFIND_operation_expects_list',
11694 $self->_objClass . '->implement',
11695 );
11696 }
11697  
11698 } else {
11699  
11700 return $self->scriptObj->setError(
11701 'PEEKFIND_cannot_import_object',
11702 $self->_objClass . '->implement',
11703 );
11704 }
11705  
11706 # Look up the LA::Variable
11707 $varObj = $self->fetchVar('PEEKFIND', $basicVarName, $parseArrayFlag);
11708 if (! $varObj) {
11709  
11710 # (self->scriptObj->setError already called)
11711 return undef;
11712 }
11713  
11714 # Now we can set the variable to PEEKFIND's return value
11715 # Assuming the array is not empty, walk the array looking for a value which is the same as
11716 # $match
11717 if (@array) {
11718  
11719 OUTER: for (my $count = 0; $count < scalar @array; $count++) {
11720  
11721 if (defined $array[$count] && $array[$count] eq $match) {
11722  
11723 # Matching value found at index $count
11724 $matchIndex = $count;
11725 last OUTER;
11726 }
11727 }
11728 }
11729  
11730 if (! defined $matchIndex) {
11731  
11732 # List is empty, or a matching value was not found
11733 $matchIndex = -1;
11734 }
11735  
11736 if (! $parseArrayFlag) {
11737  
11738 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11739 # necessary
11740 $self->importAsScalar($varObj, $matchIndex);
11741  
11742 } else {
11743  
11744 # Import the list/hash into an Axbasic array, resizing it as necessary
11745 $self->importAsArray($varObj, $matchIndex);
11746 }
11747  
11748 # Implementation complete
11749 return 1;
11750 }
11751 }
11752  
11753 { package Language::Axbasic::Statement::peekfirst;
11754  
11755 use strict;
11756 use warnings;
11757 use diagnostics;
11758  
11759 use Glib qw(TRUE FALSE);
11760  
11761 @Language::Axbasic::Statement::peekfirst::ISA = qw(
11762 Language::Axbasic
11763 Language::Axbasic::Statement
11764 );
11765  
11766 # PEEKFIRST variable-name = axmud-object-property
11767 # PEEKFIRST ARRAY variable-name = axmud-object-property
11768  
11769 ##################
11770 # Methods
11771  
11772 sub parse {
11773  
11774 # Called by LA::Line->parse directly after a call to LA::Statement->new
11775 #
11776 # Expected arguments
11777 # (none besides $self)
11778 #
11779 # Return values
11780 # 'undef' on improper arguments or if there is an error
11781 # 1 otherwise
11782  
11783 my ($self, $check) = @_;
11784  
11785 # Check for improper arguments
11786 if (defined $check) {
11787  
11788 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11789 }
11790  
11791 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11792 # $self->parseDataHash, ready for $self->implement to access
11793 if (! $self->parsePeek()) {
11794  
11795 # ($self->scriptObj->setError has already been called)
11796 return undef;
11797 }
11798  
11799 # Parsing complete
11800 return 1;
11801 }
11802  
11803 sub implement {
11804  
11805 # Called by LA::Line->implement directly after a call to $self->parse
11806 #
11807 # Expected arguments
11808 # (none besides $self)
11809 #
11810 # Return values
11811 # 'undef' on improper arguments or if there is an error
11812 # 1 otherwise
11813  
11814 my ($self, $check) = @_;
11815  
11816 # Local variables
11817 my (
11818 # Standard
11819 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11820 $var, $objFlag, $privFlag, $scalar, $varObj,
11821 @array,
11822 # Custom (set after $varObj is set)
11823 $elementValue,
11824 );
11825  
11826 # Check for improper arguments
11827 if (defined $check) {
11828  
11829 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11830 }
11831  
11832 # Get the values stored by $self->parse
11833 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11834 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11835 $expression = $self->ivShow('parseDataHash', 'expression');
11836  
11837 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
11838 $expValue = $expression->evaluate();
11839 # Process the string representing the Axmud internal variable
11840 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11841 = $self->scriptObj->session->parsePeekPoke($expValue);
11842 if (! $successFlag) {
11843  
11844 return $self->scriptObj->setError(
11845 'PEEKFIRST_operation_failure',
11846 $self->_objClass . '->implement',
11847 );
11848 }
11849  
11850 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11851 # or @array if $string refers to a list or hash value
11852 if (! $objFlag) {
11853  
11854 # This statement only accepts Perl lists
11855 if (defined $var && ref($var) eq 'ARRAY') {
11856  
11857 @array = @$var;
11858  
11859 } else {
11860  
11861 return $self->scriptObj->setError(
11862 'PEEKFIRST_operation_expects_list',
11863 $self->_objClass . '->implement',
11864 );
11865 }
11866  
11867 } else {
11868  
11869 return $self->scriptObj->setError(
11870 'PEEKFIRST_cannot_import_object',
11871 $self->_objClass . '->implement',
11872 );
11873 }
11874  
11875 # Look up the LA::Variable
11876 $varObj = $self->fetchVar('PEEKFIRST', $basicVarName, $parseArrayFlag);
11877 if (! $varObj) {
11878  
11879 # (self->scriptObj->setError already called)
11880 return undef;
11881 }
11882  
11883 # Now we can set the variable to PEEKFIRST's return value
11884 if (! @array) {
11885  
11886 # If the array is empty, then PEEKFIRST's return value is 0 or an empty string
11887 if (ref($varObj) =~ m/Numeric/) {
11888 $elementValue = 0;
11889 } else {
11890 $elementValue = '';
11891 }
11892  
11893 } else {
11894  
11895 $elementValue = $array[0];
11896  
11897 # If the corresponding value is actually 'undef', PEEKFIRST's return value is 0 or the
11898 # string "<<undef>>"
11899 if (! defined $elementValue) {
11900  
11901 if (ref($varObj) =~ m/Numeric/) {
11902 $elementValue = 0;
11903 } else {
11904 $elementValue = '<<undef>>';
11905 }
11906 }
11907 }
11908  
11909 if (! $parseArrayFlag) {
11910  
11911 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11912 # necessary
11913 $self->importAsScalar($varObj, $elementValue);
11914  
11915 } else {
11916  
11917 # Import the list/hash into an Axbasic array, resizing it as necessary
11918 $self->importAsArray($varObj, $elementValue);
11919 }
11920  
11921 # Implementation complete
11922 return 1;
11923 }
11924 }
11925  
11926 { package Language::Axbasic::Statement::peekget;
11927  
11928 use strict;
11929 use warnings;
11930 use diagnostics;
11931  
11932 use Glib qw(TRUE FALSE);
11933  
11934 @Language::Axbasic::Statement::peekget::ISA = qw(
11935 Language::Axbasic
11936 Language::Axbasic::Statement
11937 );
11938  
11939 # PEEKGET variable-name = axmud-object-property
11940 # PEEKGET ARRAY variable-name = axmud-object-property
11941  
11942 ##################
11943 # Methods
11944  
11945 sub parse {
11946  
11947 # Called by LA::Line->parse directly after a call to LA::Statement->new
11948 #
11949 # Expected arguments
11950 # (none besides $self)
11951 #
11952 # Return values
11953 # 'undef' on improper arguments or if there is an error
11954 # 1 otherwise
11955  
11956 my ($self, $check) = @_;
11957  
11958 # Check for improper arguments
11959 if (defined $check) {
11960  
11961 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11962 }
11963  
11964 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11965 # $self->parseDataHash, ready for $self->implement to access
11966 if (! $self->parsePeek()) {
11967  
11968 # ($self->scriptObj->setError has already been called)
11969 return undef;
11970 }
11971  
11972 # Parsing complete
11973 return 1;
11974 }
11975  
11976 sub implement {
11977  
11978 # Called by LA::Line->implement directly after a call to $self->parse
11979 #
11980 # Expected arguments
11981 # (none besides $self)
11982 #
11983 # Return values
11984 # 'undef' on improper arguments or if there is an error
11985 # 1 otherwise
11986  
11987 my ($self, $check) = @_;
11988  
11989 # Local variables
11990 my (
11991 # Standard
11992 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11993 $var, $objFlag, $privFlag, $scalar, $varObj,
11994 @array,
11995 # Custom (set after $varObj is set)
11996 );
11997  
11998 # Check for improper arguments
11999 if (defined $check) {
12000  
12001 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12002 }
12003  
12004 # Get the values stored by $self->parse
12005 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12006 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12007 $expression = $self->ivShow('parseDataHash', 'expression');
12008  
12009 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12010 $expValue = $expression->evaluate();
12011 # Process the string representing the Axmud internal variable
12012 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12013 = $self->scriptObj->session->parsePeekPoke($expValue);
12014 if (! $successFlag) {
12015  
12016 return $self->scriptObj->setError(
12017 'PEEKGET_operation_failure',
12018 $self->_objClass . '->implement',
12019 );
12020 }
12021  
12022 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12023 # or @array if $string refers to a list or hash value
12024 if (! $objFlag) {
12025  
12026 # This statement only accepts Perl scalars
12027 if (! defined $var || (ref($var) ne 'ARRAY' && ref($var) ne 'HASH')) {
12028  
12029 $scalar = $var;
12030  
12031 # If this was a PEEKGET ARRAY statement, but the IV is a scalar, copy it into the
12032 # first cell of the Axbasic array (being an array containing 1 element)
12033 if ($parseArrayFlag) {
12034  
12035 push (@array, $scalar);
12036 }
12037  
12038 } else {
12039  
12040 return $self->scriptObj->setError(
12041 'PEEKGET_operation_expects_scalar',
12042 $self->_objClass . '->implement',
12043 );
12044 }
12045  
12046 } else {
12047  
12048 return $self->scriptObj->setError(
12049 'PEEKGET_cannot_import_object',
12050 $self->_objClass . '->implement',
12051 );
12052 }
12053  
12054 # Look up the LA::Variable
12055 $varObj = $self->fetchVar('PEEKGET', $basicVarName, $parseArrayFlag);
12056 if (! $varObj) {
12057  
12058 # (self->scriptObj->setError already called)
12059 return undef;
12060 }
12061  
12062 # Now we can set the variable to PEEKGET's return value
12063 if (! $parseArrayFlag) {
12064  
12065 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12066 # necessary
12067 $self->importAsScalar($varObj, $scalar);
12068  
12069 } else {
12070  
12071 # Import the list/hash into an Axbasic array, resizing it as necessary
12072 $self->importAsArray($varObj, @array);
12073 }
12074  
12075 # Implementation complete
12076 return 1;
12077 }
12078 }
12079  
12080 { package Language::Axbasic::Statement::peekindex;
12081  
12082 use strict;
12083 use warnings;
12084 use diagnostics;
12085  
12086 use Glib qw(TRUE FALSE);
12087  
12088 @Language::Axbasic::Statement::peekindex::ISA = qw(
12089 Language::Axbasic
12090 Language::Axbasic::Statement
12091 );
12092  
12093 # PEEKINDEX variable-name = axmud-object-property, expression
12094 # PEEKINDEX ARRAY variable-name = axmud-object-property, expression
12095  
12096 ##################
12097 # Methods
12098  
12099 sub parse {
12100  
12101 # Called by LA::Line->parse directly after a call to LA::Statement->new
12102 #
12103 # Expected arguments
12104 # (none besides $self)
12105 #
12106 # Return values
12107 # 'undef' on improper arguments or if there is an error
12108 # 1 otherwise
12109  
12110 my ($self, $check) = @_;
12111  
12112 # Check for improper arguments
12113 if (defined $check) {
12114  
12115 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12116 }
12117  
12118 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12119 # $self->parseDataHash, ready for $self->implement to access
12120 if (! $self->parsePeek(FALSE, TRUE)) {
12121  
12122 # ($self->scriptObj->setError has already been called)
12123 return undef;
12124 }
12125  
12126 # Parsing complete
12127 return 1;
12128 }
12129  
12130 sub implement {
12131  
12132 # Called by LA::Line->implement directly after a call to $self->parse
12133 #
12134 # Expected arguments
12135 # (none besides $self)
12136 #
12137 # Return values
12138 # 'undef' on improper arguments or if there is an error
12139 # 1 otherwise
12140  
12141 my ($self, $check) = @_;
12142  
12143 # Local variables
12144 my (
12145 # Standard
12146 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12147 $var, $objFlag, $privFlag, $scalar, $varObj,
12148 @array,
12149 # Custom (set after $varObj is set)
12150 $indexExp, $index, $indexValue,
12151 );
12152  
12153 # Check for improper arguments
12154 if (defined $check) {
12155  
12156 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12157 }
12158  
12159 # Get the values stored by $self->parse
12160 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12161 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12162 $expression = $self->ivShow('parseDataHash', 'expression');
12163 $indexExp = $self->ivShow('parseDataHash', 'extra_exp');
12164  
12165 # Evaluate the first expression to get the Axmud internal variable, e.g.
12166 # "current.world.name"
12167 $expValue = $expression->evaluate();
12168 # Evaluate the second expression to get an index
12169 $index = $indexExp->evaluate();
12170 if (! defined $index || ! ($index =~ /^\d+$/) || $index < 0) {
12171  
12172 return $self->scriptObj->setError(
12173 'invalid_index_NUM',
12174 $self->_objClass . '->implement',
12175 'NUM', $index,
12176 );
12177 }
12178  
12179 # Process the string representing the Axmud internal variable
12180 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12181 = $self->scriptObj->session->parsePeekPoke($expValue);
12182 if (! $successFlag) {
12183  
12184 return $self->scriptObj->setError(
12185 'PEEKINDEX_operation_failure',
12186 $self->_objClass . '->implement',
12187 );
12188 }
12189  
12190 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12191 # or @array if $string refers to a list or hash value
12192 if (! $objFlag) {
12193  
12194 # This statement only accepts Perl scalars
12195 if (defined $var && ref($var) eq 'ARRAY') {
12196  
12197 @array = @$var;
12198  
12199 } else {
12200  
12201 return $self->scriptObj->setError(
12202 'PEEKINDEX_operation_expects_list',
12203 $self->_objClass . '->implement',
12204 );
12205 }
12206  
12207 } else {
12208  
12209 return $self->scriptObj->setError(
12210 'PEEKINDEX_cannot_import_object',
12211 $self->_objClass . '->implement',
12212 );
12213 }
12214  
12215 # Look up the LA::Variable
12216 $varObj = $self->fetchVar('PEEKINDEX', $basicVarName, $parseArrayFlag);
12217 if (! $varObj) {
12218  
12219 # (self->scriptObj->setError already called)
12220 return undef;
12221 }
12222  
12223 # Now we can set the variable to PEEKINDEX's return value.
12224 if ($index >= scalar @array) {
12225  
12226 # If $index is bigger than the array itself, then PEEKINDEX's return value is 0 or an
12227 # empty string
12228 if (ref($varObj) =~ m/Numeric/) {
12229 $indexValue = 0;
12230 } else {
12231 $indexValue = '';
12232 }
12233  
12234 } else {
12235  
12236 $indexValue = $array[$index];
12237  
12238 # If the corresponding value is actually 'undef', PEEKINDEX's return value is 0 or the
12239 # string "<<undef>>"
12240 if (! defined $indexValue) {
12241  
12242 if (ref($varObj) =~ m/Numeric/) {
12243 $indexValue = 0;
12244 } else {
12245 $indexValue = '<<undef>>';
12246 }
12247 }
12248 }
12249  
12250 if (! $parseArrayFlag) {
12251  
12252 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12253 # necessary
12254 $self->importAsScalar($varObj, $indexValue);
12255  
12256 } else {
12257  
12258 # Import the list/hash into an Axbasic array, resizing it as necessary
12259 $self->importAsArray($varObj, $indexValue);
12260 }
12261  
12262 # Implementation complete
12263 return 1;
12264 }
12265 }
12266  
12267 { package Language::Axbasic::Statement::peekkeys;
12268  
12269 use strict;
12270 use warnings;
12271 use diagnostics;
12272  
12273 use Glib qw(TRUE FALSE);
12274  
12275 @Language::Axbasic::Statement::peekkeys::ISA = qw(
12276 Language::Axbasic
12277 Language::Axbasic::Statement
12278 );
12279  
12280 # PEEKKEYS variable-name = axmud-object-property
12281 # PEEKKEYS ARRAY variable-name = axmud-object-property
12282  
12283 ##################
12284 # Methods
12285  
12286 sub parse {
12287  
12288 # Called by LA::Line->parse directly after a call to LA::Statement->new
12289 #
12290 # Expected arguments
12291 # (none besides $self)
12292 #
12293 # Return values
12294 # 'undef' on improper arguments or if there is an error
12295 # 1 otherwise
12296  
12297 my ($self, $check) = @_;
12298  
12299 # Check for improper arguments
12300 if (defined $check) {
12301  
12302 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12303 }
12304  
12305 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12306 # $self->parseDataHash, ready for $self->implement to access
12307 if (! $self->parsePeek(TRUE, FALSE)) {
12308  
12309 # ($self->scriptObj->setError has already been called)
12310 return undef;
12311 }
12312  
12313 # Parsing complete
12314 return 1;
12315 }
12316  
12317 sub implement {
12318  
12319 # Called by LA::Line->implement directly after a call to $self->parse
12320 #
12321 # Expected arguments
12322 # (none besides $self)
12323 #
12324 # Return values
12325 # 'undef' on improper arguments or if there is an error
12326 # 1 otherwise
12327  
12328 my ($self, $check) = @_;
12329  
12330 # Local variables
12331 my (
12332 # Standard
12333 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12334 $var, $objFlag, $privFlag, $scalar, $varObj,
12335 @array,
12336 # Custom (set after $varObj is set)
12337 );
12338  
12339 # Check for improper arguments
12340 if (defined $check) {
12341  
12342 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12343 }
12344  
12345 # Get the values stored by $self->parse
12346 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12347 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12348 $expression = $self->ivShow('parseDataHash', 'expression');
12349  
12350 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12351 $expValue = $expression->evaluate();
12352 # Process the string representing the Axmud internal variable
12353 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12354 = $self->scriptObj->session->parsePeekPoke($expValue);
12355 if (! $successFlag) {
12356  
12357 return $self->scriptObj->setError(
12358 'PEEKKEYS_operation_failure',
12359 $self->_objClass . '->implement',
12360 );
12361 }
12362  
12363 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12364 # or @array if $string refers to a list or hash value
12365 if (! $objFlag) {
12366  
12367 # This statement only accepts Perl hashes
12368 if (defined $var && ref($var) eq 'HASH') {
12369  
12370 @array = keys %$var;
12371  
12372 } else {
12373  
12374 return $self->scriptObj->setError(
12375 'PEEKKEYS_operation_expects_hash',
12376 $self->_objClass . '->implement',
12377 );
12378 }
12379  
12380 } else {
12381  
12382 return $self->scriptObj->setError(
12383 'PEEKKEYS_cannot_import_object',
12384 $self->_objClass . '->implement',
12385 );
12386 }
12387  
12388 # Look up the LA::Variable
12389 $varObj = $self->fetchVar('PEEKKEYS', $basicVarName, TRUE);
12390 if (! $varObj) {
12391  
12392 # (self->scriptObj->setError already called)
12393 return undef;
12394 }
12395  
12396 # Now we can set the variable to PEEKKEYS's return values ($parseArrayFlag is definitely
12397 # TRUE)
12398 # Import the list/hash into an Axbasic array, resizing it as necessary
12399 $self->importAsArray($varObj, @array);
12400  
12401 # Implementation complete
12402 return 1;
12403 }
12404 }
12405  
12406 { package Language::Axbasic::Statement::peeklast;
12407  
12408 use strict;
12409 use warnings;
12410 use diagnostics;
12411  
12412 use Glib qw(TRUE FALSE);
12413  
12414 @Language::Axbasic::Statement::peeklast::ISA = qw(
12415 Language::Axbasic
12416 Language::Axbasic::Statement
12417 );
12418  
12419 # PEEKLAST variable-name = axmud-object-property
12420 # PEEKLAST ARRAY variable-name = axmud-object-property
12421  
12422 ##################
12423 # Methods
12424  
12425 sub parse {
12426  
12427 # Called by LA::Line->parse directly after a call to LA::Statement->new
12428 #
12429 # Expected arguments
12430 # (none besides $self)
12431 #
12432 # Return values
12433 # 'undef' on improper arguments or if there is an error
12434 # 1 otherwise
12435  
12436 my ($self, $check) = @_;
12437  
12438 # Check for improper arguments
12439 if (defined $check) {
12440  
12441 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12442 }
12443  
12444 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12445 # $self->parseDataHash, ready for $self->implement to access
12446 if (! $self->parsePeek()) {
12447  
12448 # ($self->scriptObj->setError has already been called)
12449 return undef;
12450 }
12451  
12452 # Parsing complete
12453 return 1;
12454 }
12455  
12456 sub implement {
12457  
12458 # Called by LA::Line->implement directly after a call to $self->parse
12459 #
12460 # Expected arguments
12461 # (none besides $self)
12462 #
12463 # Return values
12464 # 'undef' on improper arguments or if there is an error
12465 # 1 otherwise
12466  
12467 my ($self, $check) = @_;
12468  
12469 # Local variables
12470 my (
12471 # Standard
12472 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12473 $var, $objFlag, $privFlag, $scalar, $varObj,
12474 @array,
12475 # Custom (set after $varObj is set)
12476 $lastIndex,
12477 );
12478  
12479 # Check for improper arguments
12480 if (defined $check) {
12481  
12482 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12483 }
12484  
12485 # Get the values stored by $self->parse
12486 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12487 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12488 $expression = $self->ivShow('parseDataHash', 'expression');
12489  
12490 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12491 $expValue = $expression->evaluate();
12492 # Process the string representing the Axmud internal variable
12493 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12494 = $self->scriptObj->session->parsePeekPoke($expValue);
12495 if (! $successFlag) {
12496  
12497 return $self->scriptObj->setError(
12498 'PEEKLAST_operation_failure',
12499 $self->_objClass . '->implement',
12500 );
12501 }
12502  
12503 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12504 # or @array if $string refers to a list or hash value
12505 if (! $objFlag) {
12506  
12507 # This statement only accepts Perl lists
12508 if (defined $var && ref($var) eq 'ARRAY') {
12509  
12510 @array = @$var;
12511  
12512 } else {
12513  
12514 return $self->scriptObj->setError(
12515 'PEEKLAST_operation_expects_list',
12516 $self->_objClass . '->implement',
12517 );
12518 }
12519  
12520 } else {
12521  
12522 return $self->scriptObj->setError(
12523 'PEEKLAST_cannot_import_object',
12524 $self->_objClass . '->implement',
12525 );
12526 }
12527  
12528 # Look up the LA::Variable
12529 $varObj = $self->fetchVar('PEEKLAST', $basicVarName, $parseArrayFlag);
12530 if (! $varObj) {
12531  
12532 # (self->scriptObj->setError already called)
12533 return undef;
12534 }
12535  
12536 # Now we can set the variable to PEEKLAST's return value. If the list is empty, we use the
12537 # value -1
12538 if (! @array) {
12539 $lastIndex = -1;
12540 } else {
12541 $lastIndex = (scalar @array) - 1;
12542 }
12543  
12544 if (! $parseArrayFlag) {
12545  
12546 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12547 # necessary
12548 $self->importAsScalar($varObj, $lastIndex);
12549  
12550 } else {
12551  
12552 # Import the list/hash into an Axbasic array, resizing it as necessary
12553 $self->importAsArray($varObj, $lastIndex);
12554 }
12555  
12556 # Implementation complete
12557 return 1;
12558 }
12559 }
12560  
12561 { package Language::Axbasic::Statement::peekmatch;
12562  
12563 use strict;
12564 use warnings;
12565 use diagnostics;
12566  
12567 use Glib qw(TRUE FALSE);
12568  
12569 @Language::Axbasic::Statement::peekmatch::ISA = qw(
12570 Language::Axbasic
12571 Language::Axbasic::Statement
12572 );
12573  
12574 # PEEKMATCH variable-name = axmud-object-property, expression
12575 # PEEKMATCH ARRAY variable-name = axmud-object-property, expression
12576  
12577 ##################
12578 # Methods
12579  
12580 sub parse {
12581  
12582 # Called by LA::Line->parse directly after a call to LA::Statement->new
12583 #
12584 # Expected arguments
12585 # (none besides $self)
12586 #
12587 # Return values
12588 # 'undef' on improper arguments or if there is an error
12589 # 1 otherwise
12590  
12591 my ($self, $check) = @_;
12592  
12593 # Check for improper arguments
12594 if (defined $check) {
12595  
12596 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12597 }
12598  
12599 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12600 # $self->parseDataHash, ready for $self->implement to access
12601 if (! $self->parsePeek(FALSE, TRUE)) {
12602  
12603 # ($self->scriptObj->setError has already been called)
12604 return undef;
12605 }
12606  
12607 # Parsing complete
12608 return 1;
12609 }
12610  
12611 sub implement {
12612  
12613 # Called by LA::Line->implement directly after a call to $self->parse
12614 #
12615 # Expected arguments
12616 # (none besides $self)
12617 #
12618 # Return values
12619 # 'undef' on improper arguments or if there is an error
12620 # 1 otherwise
12621  
12622 my ($self, $check) = @_;
12623  
12624 # Local variables
12625 my (
12626 # Standard
12627 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12628 $var, $objFlag, $privFlag, $scalar, $varObj,
12629 @array,
12630 # Custom (set after $varObj is set)
12631 $regexExp, $regex, $matchIndex,
12632 );
12633  
12634 # Check for improper arguments
12635 if (defined $check) {
12636  
12637 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12638 }
12639  
12640 # Get the values stored by $self->parse
12641 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12642 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12643 $expression = $self->ivShow('parseDataHash', 'expression');
12644 $regexExp = $self->ivShow('parseDataHash', 'extra_exp');
12645  
12646 # Evaluate the first expression to get the Axmud internal variable, e.g.
12647 # "current.world.name"
12648 $expValue = $expression->evaluate();
12649 # Evaluate the second expression to get a regex
12650 $regex = $regexExp->evaluate();
12651 if (! $regex) {
12652  
12653 return $self->scriptObj->setError(
12654 'invalid_matching_expression',
12655 $self->_objClass . '->implement',
12656 );
12657 }
12658  
12659 # Process the string representing the Axmud internal variable
12660 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12661 = $self->scriptObj->session->parsePeekPoke($expValue);
12662 if (! $successFlag) {
12663  
12664 return $self->scriptObj->setError(
12665 'PEEKMATCH_operation_failure',
12666 $self->_objClass . '->implement',
12667 );
12668 }
12669  
12670 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12671 # or @array if $string refers to a list or hash value
12672 if (! $objFlag) {
12673  
12674 # This statement only accepts Perl scalars
12675 if (defined $var && ref($var) eq 'ARRAY') {
12676  
12677 @array = @$var;
12678  
12679 } else {
12680  
12681 return $self->scriptObj->setError(
12682 'PEEKMATCH_operation_expects_list',
12683 $self->_objClass . '->implement',
12684 );
12685 }
12686  
12687 } else {
12688  
12689 return $self->scriptObj->setError(
12690 'PEEKMATCH_cannot_import_object',
12691 $self->_objClass . '->implement',
12692 );
12693 }
12694  
12695 # Look up the LA::Variable
12696 $varObj = $self->fetchVar('PEEKMATCH', $basicVarName, $parseArrayFlag);
12697 if (! $varObj) {
12698  
12699 # (self->scriptObj->setError already called)
12700 return undef;
12701 }
12702  
12703 # Now we can set the variable to PEEKMATCH's return value
12704 # Assuming the array is not empty, walk the array looking for a value which matches the
12705 # regex
12706 if (@array) {
12707  
12708 OUTER: for (my $count = 0; $count < scalar @array; $count++) {
12709  
12710 if (defined $array[$count] && $array[$count] =~ m/$regex/) {
12711  
12712 # Matching value found at index $count
12713 $matchIndex = $count;
12714 last OUTER;
12715 }
12716 }
12717 }
12718  
12719 if (! defined $matchIndex) {
12720  
12721 # List is empty, or a matching value was not found
12722 $matchIndex = -1;
12723 }
12724  
12725 if (! $parseArrayFlag) {
12726  
12727 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12728 # necessary
12729 $self->importAsScalar($varObj, $matchIndex);
12730  
12731 } else {
12732  
12733 # Import the list/hash into an Axbasic array, resizing it as necessary
12734 $self->importAsArray($varObj, $matchIndex);
12735 }
12736  
12737 # Implementation complete
12738 return 1;
12739 }
12740 }
12741  
12742 { package Language::Axbasic::Statement::peeknumber;
12743  
12744 use strict;
12745 use warnings;
12746 use diagnostics;
12747  
12748 use Glib qw(TRUE FALSE);
12749  
12750 @Language::Axbasic::Statement::peeknumber::ISA = qw(
12751 Language::Axbasic
12752 Language::Axbasic::Statement
12753 );
12754  
12755 # PEEKNUMBER variable-name = axmud-object-property
12756 # PEEKNUMBER ARRAY variable-name = axmud-object-property
12757  
12758 ##################
12759 # Methods
12760  
12761 sub parse {
12762  
12763 # Called by LA::Line->parse directly after a call to LA::Statement->new
12764 #
12765 # Expected arguments
12766 # (none besides $self)
12767 #
12768 # Return values
12769 # 'undef' on improper arguments or if there is an error
12770 # 1 otherwise
12771  
12772 my ($self, $check) = @_;
12773  
12774 # Check for improper arguments
12775 if (defined $check) {
12776  
12777 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12778 }
12779  
12780 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12781 # $self->parseDataHash, ready for $self->implement to access
12782 if (! $self->parsePeek()) {
12783  
12784 # ($self->scriptObj->setError has already been called)
12785 return undef;
12786 }
12787  
12788 # Parsing complete
12789 return 1;
12790 }
12791  
12792 sub implement {
12793  
12794 # Called by LA::Line->implement directly after a call to $self->parse
12795 #
12796 # Expected arguments
12797 # (none besides $self)
12798 #
12799 # Return values
12800 # 'undef' on improper arguments or if there is an error
12801 # 1 otherwise
12802  
12803 my ($self, $check) = @_;
12804  
12805 # Local variables
12806 my (
12807 # Standard
12808 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12809 $var, $objFlag, $privFlag, $scalar, $varObj,
12810 @array,
12811 # Custom (set after $varObj is set)
12812 );
12813  
12814 # Check for improper arguments
12815 if (defined $check) {
12816  
12817 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12818 }
12819  
12820 # Get the values stored by $self->parse
12821 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12822 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12823 $expression = $self->ivShow('parseDataHash', 'expression');
12824  
12825 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12826 $expValue = $expression->evaluate();
12827 # Process the string representing the Axmud internal variable
12828 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12829 = $self->scriptObj->session->parsePeekPoke($expValue);
12830 if (! $successFlag) {
12831  
12832 return $self->scriptObj->setError(
12833 'PEEKNUMBER_operation_failure',
12834 $self->_objClass . '->implement',
12835 );
12836 }
12837  
12838 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12839 # or @array if $string refers to a list or hash value
12840 if (! $objFlag) {
12841  
12842 # This statement only accepts Perl lists
12843 if (defined $var && ref($var) eq 'ARRAY') {
12844  
12845 @array = @$var;
12846  
12847 } else {
12848  
12849 return $self->scriptObj->setError(
12850 'PEEKNUMBER_operation_expects_list',
12851 $self->_objClass . '->implement',
12852 );
12853 }
12854  
12855 } else {
12856  
12857 return $self->scriptObj->setError(
12858 'PEEKNUMBER_cannot_import_object',
12859 $self->_objClass . '->implement',
12860 );
12861 }
12862  
12863 # Look up the LA::Variable
12864 $varObj = $self->fetchVar('PEEKNUMBER', $basicVarName, $parseArrayFlag);
12865 if (! $varObj) {
12866  
12867 # (self->scriptObj->setError already called)
12868 return undef;
12869 }
12870  
12871 # Now we can set the variable to PEEKNUMBER's return value
12872 if (! $parseArrayFlag) {
12873  
12874 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12875 # necessary
12876 $self->importAsScalar($varObj, scalar @array);
12877  
12878 } else {
12879  
12880 # Import the list/hash into an Axbasic array, resizing it as necessary
12881 $self->importAsArray($varObj, scalar @array);
12882 }
12883  
12884 # Implementation complete
12885 return 1;
12886 }
12887 }
12888  
12889 { package Language::Axbasic::Statement::peekpairs;
12890  
12891 use strict;
12892 use warnings;
12893 use diagnostics;
12894  
12895 use Glib qw(TRUE FALSE);
12896  
12897 @Language::Axbasic::Statement::peekpairs::ISA = qw(
12898 Language::Axbasic
12899 Language::Axbasic::Statement
12900 );
12901  
12902 # PEEKPAIRS variable-name = axmud-object-property
12903 # PEEKPAIRS ARRAY variable-name = axmud-object-property
12904  
12905 ##################
12906 # Methods
12907  
12908 sub parse {
12909  
12910 # Called by LA::Line->parse directly after a call to LA::Statement->new
12911 #
12912 # Expected arguments
12913 # (none besides $self)
12914 #
12915 # Return values
12916 # 'undef' on improper arguments or if there is an error
12917 # 1 otherwise
12918  
12919 my ($self, $check) = @_;
12920  
12921 # Check for improper arguments
12922 if (defined $check) {
12923  
12924 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12925 }
12926  
12927 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12928 # $self->parseDataHash, ready for $self->implement to access
12929 if (! $self->parsePeek()) {
12930  
12931 # ($self->scriptObj->setError has already been called)
12932 return undef;
12933 }
12934  
12935 # Parsing complete
12936 return 1;
12937 }
12938  
12939 sub implement {
12940  
12941 # Called by LA::Line->implement directly after a call to $self->parse
12942 #
12943 # Expected arguments
12944 # (none besides $self)
12945 #
12946 # Return values
12947 # 'undef' on improper arguments or if there is an error
12948 # 1 otherwise
12949  
12950 my ($self, $check) = @_;
12951  
12952 # Local variables
12953 my (
12954 # Standard
12955 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12956 $var, $objFlag, $privFlag, $scalar, $varObj,
12957 @array,
12958 # Custom (set after $varObj is set)
12959 %hash,
12960 );
12961  
12962 # Check for improper arguments
12963 if (defined $check) {
12964  
12965 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12966 }
12967  
12968 # Get the values stored by $self->parse
12969 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12970 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12971 $expression = $self->ivShow('parseDataHash', 'expression');
12972  
12973 # Evaluate the first expression to get the Axmud internal variable, e.g.
12974 # "current.world.name"
12975 $expValue = $expression->evaluate();
12976 # Process the string representing the Axmud internal variable
12977 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12978 = $self->scriptObj->session->parsePeekPoke($expValue);
12979 if (! $successFlag) {
12980  
12981 return $self->scriptObj->setError(
12982 'PEEKPAIRS_operation_failure',
12983 $self->_objClass . '->implement',
12984 );
12985 }
12986  
12987 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12988 # or @array if $string refers to a list or hash value
12989 if (! $objFlag) {
12990  
12991 # This statement only accepts Perl hashes
12992 if (defined $var && ref($var) eq 'HASH') {
12993  
12994 %hash = %$var;
12995  
12996 } else {
12997  
12998 return $self->scriptObj->setError(
12999 'PEEKPAIRS_operation_expects_hash',
13000 $self->_objClass . '->implement',
13001 );
13002 }
13003  
13004 } else {
13005  
13006 return $self->scriptObj->setError(
13007 'PEEKPAIRS_cannot_import_object',
13008 $self->_objClass . '->implement',
13009 );
13010 }
13011  
13012 # Look up the LA::Variable
13013 $varObj = $self->fetchVar('PEEKPAIRS', $basicVarName, $parseArrayFlag);
13014 if (! $varObj) {
13015  
13016 # (self->scriptObj->setError already called)
13017 return undef;
13018 }
13019  
13020 # Now we can set the variable to PEEKPAIRS's return value
13021 if (! $parseArrayFlag) {
13022  
13023 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
13024 # necessary
13025 $self->importAsScalar($varObj, scalar(keys %hash));
13026  
13027 } else {
13028  
13029 # Import the list/hash into an Axbasic array, resizing it as necessary
13030 $self->importAsArray($varObj, scalar(keys %hash));
13031 }
13032  
13033 # Implementation complete
13034 return 1;
13035 }
13036 }
13037  
13038 { package Language::Axbasic::Statement::peekshow;
13039  
13040 use strict;
13041 use warnings;
13042 use diagnostics;
13043  
13044 use Glib qw(TRUE FALSE);
13045  
13046 @Language::Axbasic::Statement::peekshow::ISA = qw(
13047 Language::Axbasic
13048 Language::Axbasic::Statement
13049 );
13050  
13051 # PEEKSHOW variable-name = axmud-object-property, expression
13052 # PEEKSHOW ARRAY variable-name = axmud-object-property, expression
13053  
13054 ##################
13055 # Methods
13056  
13057 sub parse {
13058  
13059 # Called by LA::Line->parse directly after a call to LA::Statement->new
13060 #
13061 # Expected arguments
13062 # (none besides $self)
13063 #
13064 # Return values
13065 # 'undef' on improper arguments or if there is an error
13066 # 1 otherwise
13067  
13068 my ($self, $check) = @_;
13069  
13070 # Check for improper arguments
13071 if (defined $check) {
13072  
13073 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13074 }
13075  
13076 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
13077 # $self->parseDataHash, ready for $self->implement to access
13078 if (! $self->parsePeek(FALSE, TRUE)) {
13079  
13080 # ($self->scriptObj->setError has already been called)
13081 return undef;
13082 }
13083  
13084 # Parsing complete
13085 return 1;
13086 }
13087  
13088 sub implement {
13089  
13090 # Called by LA::Line->implement directly after a call to $self->parse
13091 #
13092 # Expected arguments
13093 # (none besides $self)
13094 #
13095 # Return values
13096 # 'undef' on improper arguments or if there is an error
13097 # 1 otherwise
13098  
13099 my ($self, $check) = @_;
13100  
13101 # Local variables
13102 my (
13103 # Standard
13104 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
13105 $var, $objFlag, $privFlag, $scalar, $varObj,
13106 @array,
13107 # Custom (set after $varObj is set)
13108 $keyExp, $hashKey, $hashValue,
13109 %hash,
13110 );
13111  
13112 # Check for improper arguments
13113 if (defined $check) {
13114  
13115 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13116 }
13117  
13118 # Get the values stored by $self->parse
13119 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13120 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
13121 $expression = $self->ivShow('parseDataHash', 'expression');
13122 $keyExp = $self->ivShow('parseDataHash', 'extra_exp');
13123  
13124 # Evaluate the first expression to get the Axmud internal variable, e.g.
13125 # "current.world.name"
13126 $expValue = $expression->evaluate();
13127 # Process the string representing the Axmud internal variable
13128 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13129 = $self->scriptObj->session->parsePeekPoke($expValue);
13130 if (! $successFlag) {
13131  
13132 return $self->scriptObj->setError(
13133 'PEEKSHOW_operation_failure',
13134 $self->_objClass . '->implement',
13135 );
13136 }
13137  
13138 # Evaluate the second expression to get a hash key, e.g. 'gold'
13139 $hashKey = $keyExp->evaluate();
13140  
13141 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
13142 # or @array if $string refers to a list or hash value
13143 if (! $objFlag) {
13144  
13145 # This statement only accepts Perl hashes
13146 if (defined $var && ref($var) eq 'HASH') {
13147  
13148 %hash = %$var;
13149  
13150 } else {
13151  
13152 return $self->scriptObj->setError(
13153 'PEEKSHOW_operation_expects_hash',
13154 $self->_objClass . '->implement',
13155 );
13156 }
13157  
13158 } else {
13159  
13160 return $self->scriptObj->setError(
13161 'PEEKSHOW_cannot_import_object',
13162 $self->_objClass . '->implement',
13163 );
13164 }
13165  
13166 # Look up the LA::Variable
13167 $varObj = $self->fetchVar('PEEKSHOW', $basicVarName, $parseArrayFlag);
13168 if (! $varObj) {
13169  
13170 # (self->scriptObj->setError already called)
13171 return undef;
13172 }
13173  
13174 # Now we can set the variable to PEEKSHOW's return values
13175 if (! exists $hash{$hashKey}) {
13176  
13177 # If $hashKey doesn't exist in the hash, then PEEKSHOW's return value is 0 or an empty
13178 # string
13179 if (ref($varObj) =~ m/Numeric/) {
13180 $hashValue = 0;
13181 } else {
13182 $hashValue = '';
13183 }
13184  
13185 } else {
13186  
13187 $hashValue = $hash{$hashKey};
13188  
13189 # If the corresponding value is actually 'undef', PEEKSHOW's return value is 0 or the
13190 # string "<<undef>>"
13191 if (! defined $hashValue) {
13192  
13193 # $hashKey's corresponding value might be 'undef', or the key might not exist in the
13194 # hash property at all. In both cases, PEEKSHOW's return value is 0 or an empty
13195 # string
13196 if (ref($varObj) =~ m/Numeric/) {
13197 $hashValue = 0;
13198 } else {
13199 $hashValue = '<<undef>>';
13200 }
13201 }
13202 }
13203  
13204 if (! $parseArrayFlag) {
13205  
13206 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
13207 # necessary
13208 $self->importAsScalar($varObj, $hashValue);
13209  
13210 } else {
13211  
13212 # Import the list/hash into an Axbasic array, resizing it as necessary
13213 $self->importAsArray($varObj, $hashValue);
13214 }
13215  
13216 # Implementation complete
13217 return 1;
13218 }
13219 }
13220  
13221 { package Language::Axbasic::Statement::peekvalues;
13222  
13223 use strict;
13224 use warnings;
13225 use diagnostics;
13226  
13227 use Glib qw(TRUE FALSE);
13228  
13229 @Language::Axbasic::Statement::peekvalues::ISA = qw(
13230 Language::Axbasic
13231 Language::Axbasic::Statement
13232 );
13233  
13234 # PEEKVALUES variable-name = axmud-object-property
13235 # PEEKVALUES ARRAY variable-name = axmud-object-property
13236  
13237 ##################
13238 # Methods
13239  
13240 sub parse {
13241  
13242 # Called by LA::Line->parse directly after a call to LA::Statement->new
13243 #
13244 # Expected arguments
13245 # (none besides $self)
13246 #
13247 # Return values
13248 # 'undef' on improper arguments or if there is an error
13249 # 1 otherwise
13250  
13251 my ($self, $check) = @_;
13252  
13253 # Check for improper arguments
13254 if (defined $check) {
13255  
13256 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13257 }
13258  
13259 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
13260 # $self->parseDataHash, ready for $self->implement to access
13261 if (! $self->parsePeek(TRUE, FALSE)) {
13262  
13263 # ($self->scriptObj->setError has already been called)
13264 return undef;
13265 }
13266  
13267 # Parsing complete
13268 return 1;
13269 }
13270  
13271 sub implement {
13272  
13273 # Called by LA::Line->implement directly after a call to $self->parse
13274 #
13275 # Expected arguments
13276 # (none besides $self)
13277 #
13278 # Return values
13279 # 'undef' on improper arguments or if there is an error
13280 # 1 otherwise
13281  
13282 my ($self, $check) = @_;
13283  
13284 # Local variables
13285 my (
13286 # Standard
13287 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
13288 $var, $objFlag, $privFlag, $scalar, $varObj,
13289 @array,
13290 # Custom (set after $varObj is set)
13291 );
13292  
13293 # Check for improper arguments
13294 if (defined $check) {
13295  
13296 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13297 }
13298  
13299 # Get the values stored by $self->parse
13300 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13301 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
13302 $expression = $self->ivShow('parseDataHash', 'expression');
13303  
13304 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
13305 $expValue = $expression->evaluate();
13306 # Process the string representing the Axmud internal variable
13307 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13308 = $self->scriptObj->session->parsePeekPoke($expValue);
13309 if (! $successFlag) {
13310  
13311 return $self->scriptObj->setError(
13312 'PEEKVALUES_operation_failure',
13313 $self->_objClass . '->implement',
13314 );
13315 }
13316  
13317 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
13318 # or @array if $string refers to a list or hash value
13319 if (! $objFlag) {
13320  
13321 # This statement only accepts Perl hashes
13322 if (defined $var && ref($var) eq 'HASH') {
13323  
13324 @array = values %$var;
13325  
13326 } else {
13327  
13328 return $self->scriptObj->setError(
13329 'PEEKVALUES_operation_expects_hash',
13330 $self->_objClass . '->implement',
13331 );
13332 }
13333  
13334 } else {
13335  
13336 return $self->scriptObj->setError(
13337 'PEEKVALUES_cannot_import_object',
13338 $self->_objClass . '->implement',
13339 );
13340 }
13341  
13342 # Look up the LA::Variable
13343 $varObj = $self->fetchVar('PEEKVALUES', $basicVarName, TRUE);
13344 if (! $varObj) {
13345  
13346 # (self->scriptObj->setError already called)
13347 return undef;
13348 }
13349  
13350 # Now we can set the variable to PEEKVALUES's return values ($parseArrayFlag is definitely
13351 # TRUE)
13352 # Import the list/hash into an Axbasic array, resizing it as necessary
13353 $self->importAsArray($varObj, @array);
13354  
13355 # Implementation complete
13356 return 1;
13357 }
13358 }
13359  
13360 { package Language::Axbasic::Statement::perl;
13361  
13362 use strict;
13363 use warnings;
13364 use diagnostics;
13365  
13366 use Glib qw(TRUE FALSE);
13367  
13368 @Language::Axbasic::Statement::perl::ISA = qw(
13369 Language::Axbasic
13370 Language::Axbasic::Statement
13371 );
13372  
13373 # PERL expression
13374  
13375 ##################
13376 # Methods
13377  
13378 sub parse {
13379  
13380 # Called by LA::Line->parse directly after a call to LA::Statement->new
13381 #
13382 # Expected arguments
13383 # (none besides $self)
13384 #
13385 # Return values
13386 # 'undef' on improper arguments or if there is an error
13387 # 1 otherwise
13388  
13389 my ($self, $check) = @_;
13390  
13391 # Local variables
13392 my $expression;
13393  
13394 # Check for improper arguments
13395 if (defined $check) {
13396  
13397 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13398 }
13399  
13400 # Get the expression and store it for ->implement to use
13401 $expression = Language::Axbasic::Expression::Arithmetic->new(
13402 $self->scriptObj,
13403 $self->tokenGroupObj,
13404 );
13405  
13406 if (! defined $expression) {
13407  
13408 return $self->scriptObj->setError(
13409 'missing_or_illegal_expression',
13410 $self->_objClass . '->parse',
13411 );
13412  
13413 } else {
13414  
13415 $self->ivAdd('parseDataHash', 'expression', $expression);
13416 }
13417  
13418 # There should be nothing after the expression
13419 if (! $self->tokenGroupObj->testStatementEnd()) {
13420  
13421 return $self->scriptObj->setError(
13422 'unexpected_keywords,_operators_or_expressions',
13423 $self->_objClass . '->parse',
13424 );
13425 }
13426  
13427 # Parsing complete
13428 return 1;
13429 }
13430  
13431 sub implement {
13432  
13433 # Called by LA::Line->implement directly after a call to $self->parse
13434 #
13435 # Expected arguments
13436 # (none besides $self)
13437 #
13438 # Return values
13439 # 'undef' on improper arguments or if there is an error
13440 # 1 otherwise
13441  
13442 my ($self, $check) = @_;
13443  
13444 # Local variables
13445 my ($expression, $string);
13446  
13447 # Check for improper arguments
13448 if (defined $check) {
13449  
13450 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13451 }
13452  
13453 # Retrieve the expression to be written
13454 $expression = $self->ivShow('parseDataHash', 'expression');
13455 # Evaluate the expression to get a scalar value
13456 $string = $expression->evaluate();
13457  
13458 # Run the expression as a Perl programme (using the Safe module)
13459 $self->scriptObj->session->perlCmd($string);
13460  
13461 # Implementation complete
13462 return 1;
13463 }
13464 }
13465  
13466 { package Language::Axbasic::Statement::play;
13467  
13468 use strict;
13469 use warnings;
13470 use diagnostics;
13471  
13472 use Glib qw(TRUE FALSE);
13473  
13474 @Language::Axbasic::Statement::play::ISA = qw(
13475 Language::Axbasic
13476 Language::Axbasic::Statement
13477 );
13478  
13479 # PLAY expression
13480  
13481 ##################
13482 # Methods
13483  
13484 sub parse {
13485  
13486 # Called by LA::Line->parse directly after a call to LA::Statement->new
13487 #
13488 # Expected arguments
13489 # (none besides $self)
13490 #
13491 # Return values
13492 # 'undef' on improper arguments or if there is an error
13493 # 1 otherwise
13494  
13495 my ($self, $check) = @_;
13496  
13497 # Local variables
13498 my $expression;
13499  
13500 # Check for improper arguments
13501 if (defined $check) {
13502  
13503 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13504 }
13505  
13506 # Get the expression and store it for ->implement to use
13507 $expression = Language::Axbasic::Expression::Arithmetic->new(
13508 $self->scriptObj,
13509 $self->tokenGroupObj,
13510 );
13511  
13512 if (! defined $expression) {
13513  
13514 return $self->scriptObj->setError(
13515 'missing_or_illegal_expression',
13516 $self->_objClass . '->parse',
13517 );
13518  
13519 } else {
13520  
13521 $self->ivAdd('parseDataHash', 'expression', $expression);
13522 }
13523  
13524 # There should be nothing after the expression
13525 if (! $self->tokenGroupObj->testStatementEnd()) {
13526  
13527 return $self->scriptObj->setError(
13528 'unexpected_keywords,_operators_or_expressions',
13529 $self->_objClass . '->parse',
13530 );
13531 }
13532  
13533 # Parsing complete
13534 return 1;
13535 }
13536  
13537 sub implement {
13538  
13539 # Called by LA::Line->implement directly after a call to $self->parse
13540 #
13541 # Expected arguments
13542 # (none besides $self)
13543 #
13544 # Return values
13545 # 'undef' on improper arguments or if there is an error
13546 # 1 otherwise
13547  
13548 my ($self, $check) = @_;
13549  
13550 # Local variables
13551 my ($expression, $effect);
13552  
13553 # Check for improper arguments
13554 if (defined $check) {
13555  
13556 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13557 }
13558  
13559 # Retrieve the expression to be played
13560 $expression = $self->ivShow('parseDataHash', 'expression');
13561 # Evaluate the expression to get an Axmud sound effect
13562 $effect = $expression->evaluate();
13563  
13564 # Check that the sound effect exists
13565 if (
13566 ! $effect
13567 || ! $axmud::CLIENT->ivExists('customSoundHash', $effect)
13568 || ! $axmud::CLIENT->ivShow('customSoundHash', $effect)
13569 ) {
13570 return $self->scriptObj->setError(
13571 'sound_not_available',
13572 $self->_objClass . '->implement',
13573 );
13574  
13575 } else {
13576  
13577 # Play the sound effect (if allowed)
13578 $axmud::CLIENT->playSound($effect);
13579 }
13580  
13581 # Implementation complete
13582 return 1;
13583 }
13584 }
13585  
13586 { package Language::Axbasic::Statement::poke;
13587  
13588 use strict;
13589 use warnings;
13590 use diagnostics;
13591  
13592 use Glib qw(TRUE FALSE);
13593  
13594 @Language::Axbasic::Statement::poke::ISA = qw(
13595 Language::Axbasic
13596 Language::Axbasic::Statement
13597 );
13598  
13599 # POKE axmud-object-property, expression
13600 # POKE axmud-object-property, variable-name
13601 # POKE ARRAY axmud-object-property, variable-name
13602  
13603 ##################
13604 # Methods
13605  
13606 sub parse {
13607  
13608 # Called by LA::Line->parse directly after a call to LA::Statement->new
13609 #
13610 # Expected arguments
13611 # (none besides $self)
13612 #
13613 # Return values
13614 # 'undef' on improper arguments or if there is an error
13615 # 1 otherwise
13616  
13617 my ($self, $check) = @_;
13618  
13619 # Local variables
13620 my ($token, $arrayFlag, $propExp, $varName, $varObj, $arithExp);
13621  
13622 # Check for improper arguments
13623 if (defined $check) {
13624  
13625 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13626 }
13627  
13628 # Extract the optional ARRAY keyword
13629 $token = $self->tokenGroupObj->shiftMatchingToken('array');
13630 if ($token) {
13631 $arrayFlag = TRUE;
13632 } else {
13633 $arrayFlag = FALSE;
13634 }
13635  
13636 # The first (compulsory) token is either an expression representing an Axmud internal
13637 # variable (a scalar, e.g. "current.world.name"; an array,
13638 # e.g. "current.world.statusFormatList"; or a hash, e.g. "current.world.currencyHash")
13639 $token = $self->tokenGroupObj->lookAhead();
13640 if (! defined $token) {
13641  
13642 return $self->scriptObj->setError(
13643 'syntax_error',
13644 $self->_objClass . '->parse',
13645 );
13646  
13647 } else {
13648  
13649 $propExp = Language::Axbasic::Expression::Arithmetic->new(
13650 $self->scriptObj,
13651 $self->tokenGroupObj,
13652 );
13653  
13654 if (! defined $propExp) {
13655  
13656 return $self->scriptObj->setError(
13657 'missing_or_illegal_expression',
13658 $self->_objClass . '->parse',
13659 );
13660 }
13661 }
13662  
13663 # Extract the comma
13664 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
13665  
13666 return $self->scriptObj->setError(
13667 'syntax_error',
13668 $self->_objClass . '->parse',
13669 );
13670 }
13671  
13672 # The second expression can be either a scalar variable, array or just a normal expression
13673 # Extract a token comprising a whole variable identifier (e.g. A, a$, array), if present
13674 $token = $self->tokenGroupObj->shiftTokenIfCategory('identifier');
13675 if ($token) {
13676  
13677 $varName = $token->tokenText;
13678  
13679 # Look up the LA::Variable. Use the local variable, if it exists. Otherwise use the
13680 # global variable, if it exists
13681 if (! $arrayFlag) {
13682  
13683 $varObj = Language::Axbasic::Variable->lookup($self->scriptObj, $varName);
13684  
13685 } else {
13686  
13687 # If it's an array, ->lookup expects a LA::Expression::Arglist; but we only need to
13688 # supply it with a defined value
13689 $varObj = Language::Axbasic::Variable->lookup(
13690 $self->scriptObj,
13691 $varName,
13692 'fake_arg_list'
13693 );
13694 }
13695  
13696 if (! $varObj) {
13697  
13698 # This shouldn't happen...
13699 return $self->scriptObj->setError(
13700 'syntax_error',
13701 $self->_objClass . '->parse',
13702 );
13703 }
13704  
13705 # Identifier not present, so extract a normal expression instead (but not in POKE ARRAY
13706 # statements)
13707 } elsif (! $arrayFlag) {
13708  
13709 $token = $self->tokenGroupObj->lookAhead();
13710 if (! defined $token) {
13711  
13712 return $self->scriptObj->setError(
13713 'syntax_error',
13714 $self->_objClass . '->parse',
13715 );
13716  
13717 } else {
13718  
13719 $arithExp = Language::Axbasic::Expression::Arithmetic->new(
13720 $self->scriptObj,
13721 $self->tokenGroupObj,
13722 );
13723  
13724 if (! defined $arithExp) {
13725  
13726 return $self->scriptObj->setError(
13727 'missing_or_illegal_expression',
13728 $self->_objClass . '->parse',
13729 );
13730 }
13731 }
13732  
13733 } else {
13734  
13735 return $self->scriptObj->setError(
13736 'syntax_error',
13737 $self->_objClass . '->parse',
13738 );
13739 }
13740  
13741 # There are no further expressions to extract
13742 if (! $self->tokenGroupObj->testStatementEnd()) {
13743  
13744 return $self->scriptObj->setError(
13745 'unexpected_keywords,_operators_or_expressions',
13746 $self->_objClass . '->parse',
13747 );
13748 }
13749  
13750 # Save the expressions so $self->implement can use them, if it is called
13751 $self->ivAdd('parseDataHash', 'array_flag', $arrayFlag);
13752 $self->ivAdd('parseDataHash', 'prop_exp', $propExp);
13753 $self->ivAdd('parseDataHash', 'var_name', $varName);
13754 $self->ivAdd('parseDataHash', 'var_obj', $varObj);
13755 $self->ivAdd('parseDataHash', 'arith_exp', $arithExp);
13756  
13757 # Parsing complete
13758 return 1;
13759 }
13760  
13761 sub implement {
13762  
13763 # Called by LA::Line->implement directly after a call to $self->parse
13764 #
13765 # Expected arguments
13766 # (none besides $self)
13767 #
13768 # Return values
13769 # 'undef' on improper arguments or if there is an error
13770 # 1 otherwise
13771  
13772 my ($self, $check) = @_;
13773  
13774 # Local variables
13775 my (
13776 $parseArrayFlag, $propExp, $internalVar, $varName, $varObj, $arithExp, $arithValue,
13777 $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
13778 @cellList, @valueList,
13779 );
13780  
13781 # Check for improper arguments
13782 if (defined $check) {
13783  
13784 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13785 }
13786  
13787 # Get the values stored by $self->parse
13788 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13789 $propExp = $self->ivShow('parseDataHash', 'prop_exp');
13790 $varName = $self->ivShow('parseDataHash', 'var_name');
13791 $varObj = $self->ivShow('parseDataHash', 'var_obj');
13792 $arithExp = $self->ivShow('parseDataHash', 'arith_exp');
13793  
13794 # Evaluate the first expression to get the Axmud internal variable, e.g.
13795 # "current.world.name"
13796 $internalVar = $propExp->evaluate();
13797 # Evaluate the optional arithmetic expression, if set
13798 if (defined $arithExp) {
13799  
13800 $arithValue = $arithExp->evaluate();
13801 }
13802  
13803 # Process the string representing the Axmud internal variable
13804 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13805 = $self->scriptObj->session->parsePeekPoke($internalVar);
13806 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
13807  
13808 return $self->scriptObj->setError(
13809 'POKE_operation_failure',
13810 $self->_objClass . '->implement',
13811 );
13812  
13813 } elsif ($objFlag) {
13814  
13815 return $self->scriptObj->setError(
13816 'POKE_cannot_export_to_object',
13817 $self->_objClass . '->implement',
13818 );
13819 }
13820  
13821 # POKE ARRAY statements require an Axmud list or hash property
13822 if (
13823 $parseArrayFlag
13824 && (! defined $var || (ref($var) ne 'ARRAY' && ref($var) eq 'HASH'))
13825 ) {
13826 return $self->scriptObj->setError(
13827 'POKE_ARRAY_operation_expects_list_or_hash', # Yes, POKE_ARRAY not POKE
13828 $self->_objClass . '->implement',
13829 );
13830 }
13831  
13832 # Perform the POKE operation
13833 # If the user specified an arithmetic expression, use it
13834 if (defined $arithExp) {
13835  
13836 $blessed->ivPoke($ivName, $arithValue);
13837  
13838 # Otherwise, use the specified variable
13839 } else {
13840  
13841 if (! $parseArrayFlag) {
13842  
13843 $blessed->ivPoke($ivName, $varObj->value);
13844  
13845 } else {
13846  
13847 @cellList = $varObj->cellList;
13848 # Take account of the first item in ->cellList, which is the lower bound
13849 shift @cellList;
13850  
13851 foreach my $arrayVar (@cellList) {
13852  
13853 push (@valueList, $arrayVar->value());
13854 }
13855  
13856 $blessed->ivPoke($ivName, @valueList);
13857 }
13858 }
13859  
13860 # Implementation complete
13861 return 1;
13862 }
13863 }
13864  
13865 { package Language::Axbasic::Statement::pokeadd;
13866  
13867 use strict;
13868 use warnings;
13869 use diagnostics;
13870  
13871 use Glib qw(TRUE FALSE);
13872  
13873 @Language::Axbasic::Statement::pokeadd::ISA = qw(
13874 Language::Axbasic
13875 Language::Axbasic::Statement
13876 );
13877  
13878 # POKEADD axmud-object-property, expression, expression
13879 # POKEADD axmud-object-property, expression
13880  
13881 ##################
13882 # Methods
13883  
13884 sub parse {
13885  
13886 # Called by LA::Line->parse directly after a call to LA::Statement->new
13887 #
13888 # Expected arguments
13889 # (none besides $self)
13890 #
13891 # Return values
13892 # 'undef' on improper arguments or if there is an error
13893 # 1 otherwise
13894  
13895 my ($self, $check) = @_;
13896  
13897 # Check for improper arguments
13898 if (defined $check) {
13899  
13900 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13901 }
13902  
13903 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
13904 # ready for $self->implement to access
13905 if (! $self->parsePoke(1, 2)) {
13906  
13907 # ($self->scriptObj->setError has already been called)
13908 return undef;
13909 }
13910  
13911 # Parsing complete
13912 return 1;
13913 }
13914  
13915 sub implement {
13916  
13917 # Called by LA::Line->implement directly after a call to $self->parse
13918 #
13919 # Expected arguments
13920 # (none besides $self)
13921 #
13922 # Return values
13923 # 'undef' on improper arguments or if there is an error
13924 # 1 otherwise
13925  
13926 my ($self, $check) = @_;
13927  
13928 # Local variables
13929 my (
13930 # Standard
13931 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
13932 # Custom
13933 $keyExp, $key, $valueExp, $value,
13934 );
13935  
13936 # Check for improper arguments
13937 if (defined $check) {
13938  
13939 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13940 }
13941  
13942 # Get the values stored by $self->parse
13943 $varExp = $self->ivShow('parseDataHash', 'var_exp');
13944 $keyExp = $self->ivShift('parseDataList');
13945 $valueExp = $self->ivShift('parseDataList');
13946  
13947 # Evaluate the first expression to get the Axmud internal variable, e.g.
13948 # "current.world.name"
13949 $internalVar = $varExp->evaluate();
13950 # Evaluate the other expressions
13951 $key = $keyExp->evaluate();
13952 if (defined $valueExp) {
13953  
13954 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
13955 $value = $valueExp->evaluate();
13956 }
13957  
13958 # Process the string representing the Axmud internal variable
13959 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13960 = $self->scriptObj->session->parsePeekPoke($internalVar);
13961 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
13962  
13963 return $self->scriptObj->setError(
13964 'POKEADD_operation_failure',
13965 $self->_objClass . '->implement',
13966 );
13967  
13968 } elsif ($objFlag) {
13969  
13970 return $self->scriptObj->setError(
13971 'POKEADD_cannot_export_to_object',
13972 $self->_objClass . '->implement',
13973 );
13974 }
13975  
13976 # This statement only accepts Perl hashes
13977 if (! defined $var || ref($var) ne 'HASH') {
13978  
13979 return $self->scriptObj->setError(
13980 'POKEADD_operation_expects_hash',
13981 $self->_objClass . '->implement',
13982 );
13983 }
13984  
13985 # Perform the POKEADD operation. If the minimum number of expressions was specified, $value
13986 # is 'undef'
13987 $blessed->ivAdd($ivName, $key, $value);
13988  
13989 # Implementation complete
13990 return 1;
13991 }
13992 }
13993  
13994 { package Language::Axbasic::Statement::pokedec;
13995  
13996 use strict;
13997 use warnings;
13998 use diagnostics;
13999  
14000 use Glib qw(TRUE FALSE);
14001  
14002 @Language::Axbasic::Statement::pokedec::ISA = qw(
14003 Language::Axbasic
14004 Language::Axbasic::Statement
14005 );
14006  
14007 # POKEDEC axmud-object-property
14008  
14009 ##################
14010 # Methods
14011  
14012 sub parse {
14013  
14014 # Called by LA::Line->parse directly after a call to LA::Statement->new
14015 #
14016 # Expected arguments
14017 # (none besides $self)
14018 #
14019 # Return values
14020 # 'undef' on improper arguments or if there is an error
14021 # 1 otherwise
14022  
14023 my ($self, $check) = @_;
14024  
14025 # Check for improper arguments
14026 if (defined $check) {
14027  
14028 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14029 }
14030  
14031 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14032 # ready for $self->implement to access
14033 if (! $self->parsePoke(0)) {
14034  
14035 # ($self->scriptObj->setError has already been called)
14036 return undef;
14037 }
14038  
14039 # Parsing complete
14040 return 1;
14041 }
14042  
14043 sub implement {
14044  
14045 # Called by LA::Line->implement directly after a call to $self->parse
14046 #
14047 # Expected arguments
14048 # (none besides $self)
14049 #
14050 # Return values
14051 # 'undef' on improper arguments or if there is an error
14052 # 1 otherwise
14053  
14054 my ($self, $check) = @_;
14055  
14056 # Local variables
14057 my (
14058 # Standard
14059 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14060 # Custom
14061 );
14062  
14063 # Check for improper arguments
14064 if (defined $check) {
14065  
14066 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14067 }
14068  
14069 # Get the values stored by $self->parse
14070 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14071  
14072 # Evaluate the first expression to get the Axmud internal variable, e.g.
14073 # "current.world.name"
14074 $internalVar = $varExp->evaluate();
14075  
14076 # Process the string representing the Axmud internal variable
14077 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14078 = $self->scriptObj->session->parsePeekPoke($internalVar);
14079 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14080  
14081 return $self->scriptObj->setError(
14082 'POKEDEC_operation_failure',
14083 $self->_objClass . '->implement',
14084 );
14085  
14086 } elsif ($objFlag) {
14087  
14088 return $self->scriptObj->setError(
14089 'POKEDEC_cannot_export_to_object',
14090 $self->_objClass . '->implement',
14091 );
14092 }
14093  
14094 # This statement only accepts Perl scalars whose values are integers
14095 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14096  
14097 return $self->scriptObj->setError(
14098 'POKEDEC_operation_expects_scalar',
14099 $self->_objClass . '->implement',
14100 );
14101 }
14102  
14103 if (! defined $blessed->$ivName || $blessed->$ivName =~ m/\D/) {
14104  
14105 return $self->scriptObj->setError(
14106 'POKEDEC_operation_expects_integer',
14107 $self->_objClass . '->implement',
14108 );
14109 }
14110  
14111 # Perform the POKEDEC operation
14112 $blessed->ivDecrement($ivName);
14113  
14114 # Implementation complete
14115 return 1;
14116 }
14117 }
14118  
14119 { package Language::Axbasic::Statement::pokedechash;
14120  
14121 use strict;
14122 use warnings;
14123 use diagnostics;
14124  
14125 use Glib qw(TRUE FALSE);
14126  
14127 @Language::Axbasic::Statement::pokedechash::ISA = qw(
14128 Language::Axbasic
14129 Language::Axbasic::Statement
14130 );
14131  
14132 # POKEDECHASH axmud-object-property, expression
14133  
14134 ##################
14135 # Methods
14136  
14137 sub parse {
14138  
14139 # Called by LA::Line->parse directly after a call to LA::Statement->new
14140 #
14141 # Expected arguments
14142 # (none besides $self)
14143 #
14144 # Return values
14145 # 'undef' on improper arguments or if there is an error
14146 # 1 otherwise
14147  
14148 my ($self, $check) = @_;
14149  
14150 # Check for improper arguments
14151 if (defined $check) {
14152  
14153 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14154 }
14155  
14156 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14157 # ready for $self->implement to access
14158 if (! $self->parsePoke(1)) {
14159  
14160 # ($self->scriptObj->setError has already been called)
14161 return undef;
14162 }
14163  
14164 # Parsing complete
14165 return 1;
14166 }
14167  
14168 sub implement {
14169  
14170 # Called by LA::Line->implement directly after a call to $self->parse
14171 #
14172 # Expected arguments
14173 # (none besides $self)
14174 #
14175 # Return values
14176 # 'undef' on improper arguments or if there is an error
14177 # 1 otherwise
14178  
14179 my ($self, $check) = @_;
14180  
14181 # Local variables
14182 my (
14183 # Standard
14184 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14185 # Custom
14186 $keyExp, $key, $keyValue,
14187 );
14188  
14189 # Check for improper arguments
14190 if (defined $check) {
14191  
14192 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14193 }
14194  
14195 # Get the values stored by $self->parse
14196 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14197 $keyExp = $self->ivShift('parseDataList');
14198  
14199 # Evaluate the first expression to get the Axmud internal variable, e.g.
14200 # "current.world.name"
14201 $internalVar = $varExp->evaluate();
14202 # Evaluate the other expressions
14203 $key = $keyExp->evaluate();
14204  
14205 # Process the string representing the Axmud internal variable
14206 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14207 = $self->scriptObj->session->parsePeekPoke($internalVar);
14208 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14209  
14210 return $self->scriptObj->setError(
14211 'POKEDECHASH_operation_failure',
14212 $self->_objClass . '->implement',
14213 );
14214  
14215 } elsif ($objFlag) {
14216  
14217 return $self->scriptObj->setError(
14218 'POKEDECHASH_cannot_export_to_object',
14219 $self->_objClass . '->implement',
14220 );
14221 }
14222  
14223 # This statement only accepts Perl hashes
14224 if (! defined $var || ref($var) ne 'HASH') {
14225  
14226 return $self->scriptObj->setError(
14227 'POKEDECHASH_operation_expects_hash',
14228 $self->_objClass . '->implement',
14229 );
14230 }
14231  
14232 # The key must exist in the hash, and its corresponding value must be an integer
14233 if (! $blessed->ivExists($ivName, $key)) {
14234  
14235 return $self->scriptObj->setError(
14236 'POKEDECHASH_key_not_found',
14237 $self->_objClass . '->implement',
14238 );
14239 }
14240  
14241 $keyValue = $blessed->ivShow($ivName, $key);
14242 if (! defined $keyValue || $keyValue =~ m/\D/) {
14243  
14244 return $self->scriptObj->setError(
14245 'POKEDECHASH_operation_expects_integer',
14246 $self->_objClass . '->implement',
14247 );
14248 }
14249  
14250 # Perform the POKEDECHASH operation
14251 $blessed->ivDecHash($ivName, $key);
14252  
14253 # Implementation complete
14254 return 1;
14255 }
14256 }
14257  
14258 { package Language::Axbasic::Statement::pokedelete;
14259  
14260 use strict;
14261 use warnings;
14262 use diagnostics;
14263  
14264 use Glib qw(TRUE FALSE);
14265  
14266 @Language::Axbasic::Statement::pokedelete::ISA = qw(
14267 Language::Axbasic
14268 Language::Axbasic::Statement
14269 );
14270  
14271 # POKEDELETE axmud-object-property, expression
14272  
14273 ##################
14274 # Methods
14275  
14276 sub parse {
14277  
14278 # Called by LA::Line->parse directly after a call to LA::Statement->new
14279 #
14280 # Expected arguments
14281 # (none besides $self)
14282 #
14283 # Return values
14284 # 'undef' on improper arguments or if there is an error
14285 # 1 otherwise
14286  
14287 my ($self, $check) = @_;
14288  
14289 # Check for improper arguments
14290 if (defined $check) {
14291  
14292 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14293 }
14294  
14295 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14296 # ready for $self->implement to access
14297 if (! $self->parsePoke(1)) {
14298  
14299 # ($self->scriptObj->setError has already been called)
14300 return undef;
14301 }
14302  
14303 # Parsing complete
14304 return 1;
14305 }
14306  
14307 sub implement {
14308  
14309 # Called by LA::Line->implement directly after a call to $self->parse
14310 #
14311 # Expected arguments
14312 # (none besides $self)
14313 #
14314 # Return values
14315 # 'undef' on improper arguments or if there is an error
14316 # 1 otherwise
14317  
14318 my ($self, $check) = @_;
14319  
14320 # Local variables
14321 my (
14322 # Standard
14323 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14324 # Custom
14325 $keyExp, $key,
14326 );
14327  
14328 # Check for improper arguments
14329 if (defined $check) {
14330  
14331 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14332 }
14333  
14334 # Get the values stored by $self->parse
14335 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14336 $keyExp = $self->ivShift('parseDataList');
14337  
14338 # Evaluate the first expression to get the Axmud internal variable, e.g.
14339 # "current.world.name"
14340 $internalVar = $varExp->evaluate();
14341 # Evaluate the other expressions
14342 $key = $keyExp->evaluate();
14343  
14344 # Process the string representing the Axmud internal variable
14345 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14346 = $self->scriptObj->session->parsePeekPoke($internalVar);
14347 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14348  
14349 return $self->scriptObj->setError(
14350 'POKEDELETE_operation_failure',
14351 $self->_objClass . '->implement',
14352 );
14353  
14354 } elsif ($objFlag) {
14355  
14356 return $self->scriptObj->setError(
14357 'POKEDELETE_cannot_export_to_object',
14358 $self->_objClass . '->implement',
14359 );
14360 }
14361  
14362 # This statement only accepts Perl hashes
14363 if (! defined $var || ref($var) ne 'HASH') {
14364  
14365 return $self->scriptObj->setError(
14366 'POKEDELETE_operation_expects_hash',
14367 $self->_objClass . '->implement',
14368 );
14369 }
14370  
14371 # The key must exist in the hash
14372 if (! $blessed->ivExists($ivName, $key)) {
14373  
14374 return $self->scriptObj->setError(
14375 'POKEDELETE_key_not_found',
14376 $self->_objClass . '->implement',
14377 );
14378 }
14379  
14380 # Perform the POKEDELETE operation
14381 $blessed->ivDelete($ivName, $key);
14382  
14383 # Implementation complete
14384 return 1;
14385 }
14386 }
14387  
14388 { package Language::Axbasic::Statement::pokedivide;
14389  
14390 use strict;
14391 use warnings;
14392 use diagnostics;
14393  
14394 use Glib qw(TRUE FALSE);
14395  
14396 @Language::Axbasic::Statement::pokedivide::ISA = qw(
14397 Language::Axbasic
14398 Language::Axbasic::Statement
14399 );
14400  
14401 # POKEDIVIDE axmud-object-property, expression
14402  
14403 ##################
14404 # Methods
14405  
14406 sub parse {
14407  
14408 # Called by LA::Line->parse directly after a call to LA::Statement->new
14409 #
14410 # Expected arguments
14411 # (none besides $self)
14412 #
14413 # Return values
14414 # 'undef' on improper arguments or if there is an error
14415 # 1 otherwise
14416  
14417 my ($self, $check) = @_;
14418  
14419 # Check for improper arguments
14420 if (defined $check) {
14421  
14422 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14423 }
14424  
14425 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14426 # ready for $self->implement to access
14427 if (! $self->parsePoke(1)) {
14428  
14429 # ($self->scriptObj->setError has already been called)
14430 return undef;
14431 }
14432  
14433 # Parsing complete
14434 return 1;
14435 }
14436  
14437 sub implement {
14438  
14439 # Called by LA::Line->implement directly after a call to $self->parse
14440 #
14441 # Expected arguments
14442 # (none besides $self)
14443 #
14444 # Return values
14445 # 'undef' on improper arguments or if there is an error
14446 # 1 otherwise
14447  
14448 my ($self, $check) = @_;
14449  
14450 # Local variables
14451 my (
14452 # Standard
14453 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14454 # Custom
14455 $valueExp, $value,
14456 );
14457  
14458 # Check for improper arguments
14459 if (defined $check) {
14460  
14461 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14462 }
14463  
14464 # Get the values stored by $self->parse
14465 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14466 $valueExp = $self->ivShift('parseDataList');
14467  
14468 # Evaluate the first expression to get the Axmud internal variable, e.g.
14469 # "current.world.name"
14470 $internalVar = $varExp->evaluate();
14471 # Evaluate the other expressions
14472 $value = $valueExp->evaluate();
14473 # The value of the expression must be a non-zero number
14474 if (
14475 ! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
14476 || $value == 0
14477 ) {
14478 return $self->scriptObj->setError(
14479 'invalid_expression_in_POKEDIVIDE_statement',
14480 $self->_objClass . '->implement',
14481 );
14482 }
14483  
14484 # Process the string representing the Axmud internal variable
14485 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14486 = $self->scriptObj->session->parsePeekPoke($internalVar);
14487 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14488  
14489 return $self->scriptObj->setError(
14490 'POKEDIVIDE_operation_failure',
14491 $self->_objClass . '->implement',
14492 );
14493  
14494 } elsif ($objFlag) {
14495  
14496 return $self->scriptObj->setError(
14497 'POKEDIVIDE_cannot_export_to_object',
14498 $self->_objClass . '->implement',
14499 );
14500 }
14501  
14502 # This statement only accepts Perl scalars whose values are numbers
14503 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14504  
14505 return $self->scriptObj->setError(
14506 'POKEDIVIDE_operation_expects_scalar',
14507 $self->_objClass . '->implement',
14508 );
14509 }
14510  
14511 if (
14512 ! defined $blessed->$ivName
14513 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
14514 ) {
14515 return $self->scriptObj->setError(
14516 'POKEDIVIDE_operation_expects_numeric',
14517 $self->_objClass . '->implement',
14518 );
14519 }
14520  
14521 # Perform the POKEDIVIDE operation
14522 $blessed->ivDivide($ivName, $value);
14523  
14524 # Implementation complete
14525 return 1;
14526 }
14527 }
14528  
14529 { package Language::Axbasic::Statement::pokeempty;
14530  
14531 use strict;
14532 use warnings;
14533 use diagnostics;
14534  
14535 use Glib qw(TRUE FALSE);
14536  
14537 @Language::Axbasic::Statement::pokeempty::ISA = qw(
14538 Language::Axbasic
14539 Language::Axbasic::Statement
14540 );
14541  
14542 # POKEEMPTY axmud-object-property
14543  
14544 ##################
14545 # Methods
14546  
14547 sub parse {
14548  
14549 # Called by LA::Line->parse directly after a call to LA::Statement->new
14550 #
14551 # Expected arguments
14552 # (none besides $self)
14553 #
14554 # Return values
14555 # 'undef' on improper arguments or if there is an error
14556 # 1 otherwise
14557  
14558 my ($self, $check) = @_;
14559  
14560 # Check for improper arguments
14561 if (defined $check) {
14562  
14563 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14564 }
14565  
14566 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14567 # ready for $self->implement to access
14568 if (! $self->parsePoke(0)) {
14569  
14570 # ($self->scriptObj->setError has already been called)
14571 return undef;
14572 }
14573  
14574 # Parsing complete
14575 return 1;
14576 }
14577  
14578 sub implement {
14579  
14580 # Called by LA::Line->implement directly after a call to $self->parse
14581 #
14582 # Expected arguments
14583 # (none besides $self)
14584 #
14585 # Return values
14586 # 'undef' on improper arguments or if there is an error
14587 # 1 otherwise
14588  
14589 my ($self, $check) = @_;
14590  
14591 # Local variables
14592 my (
14593 # Standard
14594 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14595 # Custom
14596 );
14597  
14598 # Check for improper arguments
14599 if (defined $check) {
14600  
14601 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14602 }
14603  
14604 # Get the values stored by $self->parse
14605 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14606  
14607 # Evaluate the first expression to get the Axmud internal variable, e.g.
14608 # "current.world.name"
14609 $internalVar = $varExp->evaluate();
14610  
14611 # Process the string representing the Axmud internal variable
14612 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14613 = $self->scriptObj->session->parsePeekPoke($internalVar);
14614 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14615  
14616 return $self->scriptObj->setError(
14617 'POKEEMPTY_operation_failure',
14618 $self->_objClass . '->implement',
14619 );
14620  
14621 } elsif ($objFlag) {
14622  
14623 return $self->scriptObj->setError(
14624 'POKEEMPTY_cannot_export_to_object',
14625 $self->_objClass . '->implement',
14626 );
14627 }
14628  
14629 # (This statement accepts Perl scalars, arrays and hashes)
14630  
14631 # Perform the POKEEMPTY operation
14632 $blessed->ivEmpty($ivName);
14633  
14634 # Implementation complete
14635 return 1;
14636 }
14637 }
14638  
14639 { package Language::Axbasic::Statement::pokefalse;
14640  
14641 use strict;
14642 use warnings;
14643 use diagnostics;
14644  
14645 use Glib qw(TRUE FALSE);
14646  
14647 @Language::Axbasic::Statement::pokefalse::ISA = qw(
14648 Language::Axbasic
14649 Language::Axbasic::Statement
14650 );
14651  
14652 # POKEFALSE axmud-object-property
14653  
14654 ##################
14655 # Methods
14656  
14657 sub parse {
14658  
14659 # Called by LA::Line->parse directly after a call to LA::Statement->new
14660 #
14661 # Expected arguments
14662 # (none besides $self)
14663 #
14664 # Return values
14665 # 'undef' on improper arguments or if there is an error
14666 # 1 otherwise
14667  
14668 my ($self, $check) = @_;
14669  
14670 # Check for improper arguments
14671 if (defined $check) {
14672  
14673 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14674 }
14675  
14676 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14677 # ready for $self->implement to access
14678 if (! $self->parsePoke(0)) {
14679  
14680 # ($self->scriptObj->setError has already been called)
14681 return undef;
14682 }
14683  
14684 # Parsing complete
14685 return 1;
14686 }
14687  
14688 sub implement {
14689  
14690 # Called by LA::Line->implement directly after a call to $self->parse
14691 #
14692 # Expected arguments
14693 # (none besides $self)
14694 #
14695 # Return values
14696 # 'undef' on improper arguments or if there is an error
14697 # 1 otherwise
14698  
14699 my ($self, $check) = @_;
14700  
14701 # Local variables
14702 my (
14703 # Standard
14704 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14705 # Custom
14706 );
14707  
14708 # Check for improper arguments
14709 if (defined $check) {
14710  
14711 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14712 }
14713  
14714 # Get the values stored by $self->parse
14715 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14716  
14717 # Evaluate the first expression to get the Axmud internal variable, e.g.
14718 # "current.world.name"
14719 $internalVar = $varExp->evaluate();
14720  
14721 # Process the string representing the Axmud internal variable
14722 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14723 = $self->scriptObj->session->parsePeekPoke($internalVar);
14724 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14725  
14726 return $self->scriptObj->setError(
14727 'POKEFALSE_operation_failure',
14728 $self->_objClass . '->implement',
14729 );
14730  
14731 } elsif ($objFlag) {
14732  
14733 return $self->scriptObj->setError(
14734 'POKEFALSE_cannot_export_to_object',
14735 $self->_objClass . '->implement',
14736 );
14737 }
14738  
14739 # This statement only accepts Perl scalars
14740 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14741  
14742 return $self->scriptObj->setError(
14743 'POKEFALSE_operation_expects_scalar',
14744 $self->_objClass . '->implement',
14745 );
14746 }
14747  
14748 # Perform the POKEFALSE operation
14749 $blessed->ivFalse($ivName);
14750  
14751 # Implementation complete
14752 return 1;
14753 }
14754 }
14755  
14756 { package Language::Axbasic::Statement::pokeinc;
14757  
14758 use strict;
14759 use warnings;
14760 use diagnostics;
14761  
14762 use Glib qw(TRUE FALSE);
14763  
14764 @Language::Axbasic::Statement::pokeinc::ISA = qw(
14765 Language::Axbasic
14766 Language::Axbasic::Statement
14767 );
14768  
14769 # POKEINC axmud-object-property
14770  
14771 ##################
14772 # Methods
14773  
14774 sub parse {
14775  
14776 # Called by LA::Line->parse directly after a call to LA::Statement->new
14777 #
14778 # Expected arguments
14779 # (none besides $self)
14780 #
14781 # Return values
14782 # 'undef' on improper arguments or if there is an error
14783 # 1 otherwise
14784  
14785 my ($self, $check) = @_;
14786  
14787 # Check for improper arguments
14788 if (defined $check) {
14789  
14790 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14791 }
14792  
14793 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14794 # ready for $self->implement to access
14795 if (! $self->parsePoke(0)) {
14796  
14797 # ($self->scriptObj->setError has already been called)
14798 return undef;
14799 }
14800  
14801 # Parsing complete
14802 return 1;
14803 }
14804  
14805 sub implement {
14806  
14807 # Called by LA::Line->implement directly after a call to $self->parse
14808 #
14809 # Expected arguments
14810 # (none besides $self)
14811 #
14812 # Return values
14813 # 'undef' on improper arguments or if there is an error
14814 # 1 otherwise
14815  
14816 my ($self, $check) = @_;
14817  
14818 # Local variables
14819 my (
14820 # Standard
14821 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14822 # Custom
14823 );
14824  
14825 # Check for improper arguments
14826 if (defined $check) {
14827  
14828 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14829 }
14830  
14831 # Get the values stored by $self->parse
14832 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14833  
14834 # Evaluate the first expression to get the Axmud internal variable, e.g.
14835 # "current.world.name"
14836 $internalVar = $varExp->evaluate();
14837  
14838 # Process the string representing the Axmud internal variable
14839 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14840 = $self->scriptObj->session->parsePeekPoke($internalVar);
14841 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14842  
14843 return $self->scriptObj->setError(
14844 'POKEINC_operation_failure',
14845 $self->_objClass . '->implement',
14846 );
14847  
14848 } elsif ($objFlag) {
14849  
14850 return $self->scriptObj->setError(
14851 'POKEINC_cannot_export_to_object',
14852 $self->_objClass . '->implement',
14853 );
14854 }
14855  
14856 # This statement only accepts Perl scalars whose values are integers
14857 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14858  
14859 return $self->scriptObj->setError(
14860 'POKEINC_operation_expects_scalar',
14861 $self->_objClass . '->implement',
14862 );
14863 }
14864  
14865 if (! defined $blessed->$ivName || $blessed->$ivName =~ m/\D/) {
14866  
14867 return $self->scriptObj->setError(
14868 'POKEINC_operation_expects_integer',
14869 $self->_objClass . '->implement',
14870 );
14871 }
14872  
14873 # Perform the POKEINC operation
14874 $blessed->ivIncrement($ivName);
14875  
14876 # Implementation complete
14877 return 1;
14878 }
14879 }
14880  
14881 { package Language::Axbasic::Statement::pokeinchash;
14882  
14883 use strict;
14884 use warnings;
14885 use diagnostics;
14886  
14887 use Glib qw(TRUE FALSE);
14888  
14889 @Language::Axbasic::Statement::pokeinchash::ISA = qw(
14890 Language::Axbasic
14891 Language::Axbasic::Statement
14892 );
14893  
14894 # POKEINCHASH axmud-object-property, expression
14895  
14896 ##################
14897 # Methods
14898  
14899 sub parse {
14900  
14901 # Called by LA::Line->parse directly after a call to LA::Statement->new
14902 #
14903 # Expected arguments
14904 # (none besides $self)
14905 #
14906 # Return values
14907 # 'undef' on improper arguments or if there is an error
14908 # 1 otherwise
14909  
14910 my ($self, $check) = @_;
14911  
14912 # Check for improper arguments
14913 if (defined $check) {
14914  
14915 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14916 }
14917  
14918 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14919 # ready for $self->implement to access
14920 if (! $self->parsePoke(1)) {
14921  
14922 # ($self->scriptObj->setError has already been called)
14923 return undef;
14924 }
14925  
14926 # Parsing complete
14927 return 1;
14928 }
14929  
14930 sub implement {
14931  
14932 # Called by LA::Line->implement directly after a call to $self->parse
14933 #
14934 # Expected arguments
14935 # (none besides $self)
14936 #
14937 # Return values
14938 # 'undef' on improper arguments or if there is an error
14939 # 1 otherwise
14940  
14941 my ($self, $check) = @_;
14942  
14943 # Local variables
14944 my (
14945 # Standard
14946 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14947 # Custom
14948 $keyExp, $key, $keyValue,
14949 );
14950  
14951 # Check for improper arguments
14952 if (defined $check) {
14953  
14954 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14955 }
14956  
14957 # Get the values stored by $self->parse
14958 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14959 $keyExp = $self->ivShift('parseDataList');
14960  
14961 # Evaluate the first expression to get the Axmud internal variable, e.g.
14962 # "current.world.name"
14963 $internalVar = $varExp->evaluate();
14964 # Evaluate the other expressions
14965 $key = $keyExp->evaluate();
14966  
14967 # Process the string representing the Axmud internal variable
14968 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14969 = $self->scriptObj->session->parsePeekPoke($internalVar);
14970 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14971  
14972 return $self->scriptObj->setError(
14973 'POKEINCHASH_operation_failure',
14974 $self->_objClass . '->implement',
14975 );
14976  
14977 } elsif ($objFlag) {
14978  
14979 return $self->scriptObj->setError(
14980 'POKEINCHASH_cannot_export_to_object',
14981 $self->_objClass . '->implement',
14982 );
14983 }
14984  
14985 # This statement only accepts Perl hashes
14986 if (! defined $var || ref($var) ne 'HASH') {
14987  
14988 return $self->scriptObj->setError(
14989 'POKEINCHASH_operation_expects_hash',
14990 $self->_objClass . '->implement',
14991 );
14992 }
14993  
14994 # The key must exist in the hash, and its corresponding value must be an integer
14995 if (! $blessed->ivExists($ivName, $key)) {
14996  
14997 return $self->scriptObj->setError(
14998 'POKEINCHASH_key_not_found',
14999 $self->_objClass . '->implement',
15000 );
15001 }
15002  
15003 $keyValue = $blessed->ivShow($ivName, $key);
15004 if (! defined $keyValue || $keyValue =~ m/\D/) {
15005  
15006 return $self->scriptObj->setError(
15007 'POKEINCHASH_operation_expects_integer',
15008 $self->_objClass . '->implement',
15009 );
15010 }
15011  
15012 # Perform the POKEINCHASH operation
15013 $blessed->ivIncHash($ivName, $key);
15014  
15015 # Implementation complete
15016 return 1;
15017 }
15018 }
15019  
15020 { package Language::Axbasic::Statement::pokeint;
15021  
15022 use strict;
15023 use warnings;
15024 use diagnostics;
15025  
15026 use Glib qw(TRUE FALSE);
15027  
15028 @Language::Axbasic::Statement::pokeint::ISA = qw(
15029 Language::Axbasic
15030 Language::Axbasic::Statement
15031 );
15032  
15033 # POKEINT axmud-object-property
15034  
15035 ##################
15036 # Methods
15037  
15038 sub parse {
15039  
15040 # Called by LA::Line->parse directly after a call to LA::Statement->new
15041 #
15042 # Expected arguments
15043 # (none besides $self)
15044 #
15045 # Return values
15046 # 'undef' on improper arguments or if there is an error
15047 # 1 otherwise
15048  
15049 my ($self, $check) = @_;
15050  
15051 # Check for improper arguments
15052 if (defined $check) {
15053  
15054 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15055 }
15056  
15057 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15058 # ready for $self->implement to access
15059 if (! $self->parsePoke(0)) {
15060  
15061 # ($self->scriptObj->setError has already been called)
15062 return undef;
15063 }
15064  
15065 # Parsing complete
15066 return 1;
15067 }
15068  
15069 sub implement {
15070  
15071 # Called by LA::Line->implement directly after a call to $self->parse
15072 #
15073 # Expected arguments
15074 # (none besides $self)
15075 #
15076 # Return values
15077 # 'undef' on improper arguments or if there is an error
15078 # 1 otherwise
15079  
15080 my ($self, $check) = @_;
15081  
15082 # Local variables
15083 my (
15084 # Standard
15085 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15086 # Custom
15087 );
15088  
15089 # Check for improper arguments
15090 if (defined $check) {
15091  
15092 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15093 }
15094  
15095 # Get the values stored by $self->parse
15096 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15097  
15098 # Evaluate the first expression to get the Axmud internal variable, e.g.
15099 # "current.world.name"
15100 $internalVar = $varExp->evaluate();
15101  
15102 # Process the string representing the Axmud internal variable
15103 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15104 = $self->scriptObj->session->parsePeekPoke($internalVar);
15105 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15106  
15107 return $self->scriptObj->setError(
15108 'POKEINT_operation_failure',
15109 $self->_objClass . '->implement',
15110 );
15111  
15112 } elsif ($objFlag) {
15113  
15114 return $self->scriptObj->setError(
15115 'POKEINT_cannot_export_to_object',
15116 $self->_objClass . '->implement',
15117 );
15118 }
15119  
15120 # This statement only accepts Perl scalars whose values are numbers
15121 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15122  
15123 return $self->scriptObj->setError(
15124 'POKEINT_operation_expects_scalar',
15125 $self->_objClass . '->implement',
15126 );
15127 }
15128  
15129 if (
15130 ! defined $blessed->$ivName
15131 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15132 ) {
15133 return $self->scriptObj->setError(
15134 'POKEINT_operation_expects_numeric',
15135 $self->_objClass . '->implement',
15136 );
15137 }
15138  
15139 # Perform the POKEINT operation
15140 $blessed->ivInt($ivName);
15141  
15142 # Implementation complete
15143 return 1;
15144 }
15145 }
15146  
15147 { package Language::Axbasic::Statement::pokeminus;
15148  
15149 use strict;
15150 use warnings;
15151 use diagnostics;
15152  
15153 use Glib qw(TRUE FALSE);
15154  
15155 @Language::Axbasic::Statement::pokeminus::ISA = qw(
15156 Language::Axbasic
15157 Language::Axbasic::Statement
15158 );
15159  
15160 # POKEMINUS axmud-object-property, expression
15161  
15162 ##################
15163 # Methods
15164  
15165 sub parse {
15166  
15167 # Called by LA::Line->parse directly after a call to LA::Statement->new
15168 #
15169 # Expected arguments
15170 # (none besides $self)
15171 #
15172 # Return values
15173 # 'undef' on improper arguments or if there is an error
15174 # 1 otherwise
15175  
15176 my ($self, $check) = @_;
15177  
15178 # Check for improper arguments
15179 if (defined $check) {
15180  
15181 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15182 }
15183  
15184 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15185 # ready for $self->implement to access
15186 if (! $self->parsePoke(1)) {
15187  
15188 # ($self->scriptObj->setError has already been called)
15189 return undef;
15190 }
15191  
15192 # Parsing complete
15193 return 1;
15194 }
15195  
15196 sub implement {
15197  
15198 # Called by LA::Line->implement directly after a call to $self->parse
15199 #
15200 # Expected arguments
15201 # (none besides $self)
15202 #
15203 # Return values
15204 # 'undef' on improper arguments or if there is an error
15205 # 1 otherwise
15206  
15207 my ($self, $check) = @_;
15208  
15209 # Local variables
15210 my (
15211 # Standard
15212 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15213 # Custom
15214 $valueExp, $value,
15215 );
15216  
15217 # Check for improper arguments
15218 if (defined $check) {
15219  
15220 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15221 }
15222  
15223 # Get the values stored by $self->parse
15224 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15225 $valueExp = $self->ivShift('parseDataList');
15226  
15227 # Evaluate the first expression to get the Axmud internal variable, e.g.
15228 # "current.world.name"
15229 $internalVar = $varExp->evaluate();
15230 # Evaluate the other expressions
15231 $value = $valueExp->evaluate();
15232 # The value of the expression must be a number
15233 if (! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)) {
15234  
15235 return $self->scriptObj->setError(
15236 'invalid_expression_in_POKEMINUS_statement',
15237 $self->_objClass . '->implement',
15238 );
15239 }
15240  
15241 # Process the string representing the Axmud internal variable
15242 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15243 = $self->scriptObj->session->parsePeekPoke($internalVar);
15244 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15245  
15246 return $self->scriptObj->setError(
15247 'POKEMINUS_operation_failure',
15248 $self->_objClass . '->implement',
15249 );
15250  
15251 } elsif ($objFlag) {
15252  
15253 return $self->scriptObj->setError(
15254 'POKEMINUS_cannot_export_to_object',
15255 $self->_objClass . '->implement',
15256 );
15257 }
15258  
15259 # This statement only accepts Perl scalars whose values are numbers
15260 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15261  
15262 return $self->scriptObj->setError(
15263 'POKEMINUS_operation_expects_scalar',
15264 $self->_objClass . '->implement',
15265 );
15266 }
15267  
15268 if (
15269 ! defined $blessed->$ivName
15270 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15271 ) {
15272 return $self->scriptObj->setError(
15273 'POKEMINUS_operation_expects_numeric',
15274 $self->_objClass . '->implement',
15275 );
15276 }
15277  
15278 # Perform the POKEMINUS operation
15279 $blessed->ivMinus($ivName, $value);
15280  
15281 # Implementation complete
15282 return 1;
15283 }
15284 }
15285  
15286 { package Language::Axbasic::Statement::pokemultiply;
15287  
15288 use strict;
15289 use warnings;
15290 use diagnostics;
15291  
15292 use Glib qw(TRUE FALSE);
15293  
15294 @Language::Axbasic::Statement::pokemultiply::ISA = qw(
15295 Language::Axbasic
15296 Language::Axbasic::Statement
15297 );
15298  
15299 # POKEMULTIPLY axmud-object-property, expression
15300  
15301 ##################
15302 # Methods
15303  
15304 sub parse {
15305  
15306 # Called by LA::Line->parse directly after a call to LA::Statement->new
15307 #
15308 # Expected arguments
15309 # (none besides $self)
15310 #
15311 # Return values
15312 # 'undef' on improper arguments or if there is an error
15313 # 1 otherwise
15314  
15315 my ($self, $check) = @_;
15316  
15317 # Check for improper arguments
15318 if (defined $check) {
15319  
15320 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15321 }
15322  
15323 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15324 # ready for $self->implement to access
15325 if (! $self->parsePoke(1)) {
15326  
15327 # ($self->scriptObj->setError has already been called)
15328 return undef;
15329 }
15330  
15331 # Parsing complete
15332 return 1;
15333 }
15334  
15335 sub implement {
15336  
15337 # Called by LA::Line->implement directly after a call to $self->parse
15338 #
15339 # Expected arguments
15340 # (none besides $self)
15341 #
15342 # Return values
15343 # 'undef' on improper arguments or if there is an error
15344 # 1 otherwise
15345  
15346 my ($self, $check) = @_;
15347  
15348 # Local variables
15349 my (
15350 # Standard
15351 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15352 # Custom
15353 $valueExp, $value,
15354 );
15355  
15356 # Check for improper arguments
15357 if (defined $check) {
15358  
15359 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15360 }
15361  
15362 # Get the values stored by $self->parse
15363 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15364 $valueExp = $self->ivShift('parseDataList');
15365  
15366 # Evaluate the first expression to get the Axmud internal variable, e.g.
15367 # "current.world.name"
15368 $internalVar = $varExp->evaluate();
15369 # Evaluate the other expressions
15370 $value = $valueExp->evaluate();
15371 # The value of the expression must be a number
15372 if (! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)) {
15373  
15374 return $self->scriptObj->setError(
15375 'invalid_expression_in_POKEMULTIPLY_statement',
15376 $self->_objClass . '->implement',
15377 );
15378 }
15379  
15380 # Process the string representing the Axmud internal variable
15381 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15382 = $self->scriptObj->session->parsePeekPoke($internalVar);
15383 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15384  
15385 return $self->scriptObj->setError(
15386 'POKEMULTIPLY_operation_failure',
15387 $self->_objClass . '->implement',
15388 );
15389  
15390 } elsif ($objFlag) {
15391  
15392 return $self->scriptObj->setError(
15393 'POKEMULTIPLY_cannot_export_to_object',
15394 $self->_objClass . '->implement',
15395 );
15396 }
15397  
15398 # This statement only accepts Perl scalars whose values are numbers
15399 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15400  
15401 return $self->scriptObj->setError(
15402 'POKEMULTIPLY_operation_expects_scalar',
15403 $self->_objClass . '->implement',
15404 );
15405 }
15406  
15407 if (
15408 ! defined $blessed->$ivName
15409 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15410 ) {
15411 return $self->scriptObj->setError(
15412 'POKEMULTIPLY_operation_expects_numeric',
15413 $self->_objClass . '->implement',
15414 );
15415 }
15416  
15417 # Perform the POKEMULTIPLY operation
15418 $blessed->ivMultiply($ivName, $value);
15419  
15420 # Implementation complete
15421 return 1;
15422 }
15423 }
15424  
15425 { package Language::Axbasic::Statement::pokeplus;
15426  
15427 use strict;
15428 use warnings;
15429 use diagnostics;
15430  
15431 use Glib qw(TRUE FALSE);
15432  
15433 @Language::Axbasic::Statement::pokeplus::ISA = qw(
15434 Language::Axbasic
15435 Language::Axbasic::Statement
15436 );
15437  
15438 # POKEPLUS axmud-object-property, expression
15439  
15440 ##################
15441 # Methods
15442  
15443 sub parse {
15444  
15445 # Called by LA::Line->parse directly after a call to LA::Statement->new
15446 #
15447 # Expected arguments
15448 # (none besides $self)
15449 #
15450 # Return values
15451 # 'undef' on improper arguments or if there is an error
15452 # 1 otherwise
15453  
15454 my ($self, $check) = @_;
15455  
15456 # Check for improper arguments
15457 if (defined $check) {
15458  
15459 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15460 }
15461  
15462 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15463 # ready for $self->implement to access
15464 if (! $self->parsePoke(1)) {
15465  
15466 # ($self->scriptObj->setError has already been called)
15467 return undef;
15468 }
15469  
15470 # Parsing complete
15471 return 1;
15472 }
15473  
15474 sub implement {
15475  
15476 # Called by LA::Line->implement directly after a call to $self->parse
15477 #
15478 # Expected arguments
15479 # (none besides $self)
15480 #
15481 # Return values
15482 # 'undef' on improper arguments or if there is an error
15483 # 1 otherwise
15484  
15485 my ($self, $check) = @_;
15486  
15487 # Local variables
15488 my (
15489 # Standard
15490 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15491 # Custom
15492 $valueExp, $value,
15493 );
15494  
15495 # Check for improper arguments
15496 if (defined $check) {
15497  
15498 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15499 }
15500  
15501 # Get the values stored by $self->parse
15502 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15503 $valueExp = $self->ivShift('parseDataList');
15504  
15505 # Evaluate the first expression to get the Axmud internal variable, e.g.
15506 # "current.world.name"
15507 $internalVar = $varExp->evaluate();
15508 # Evaluate the other expressions
15509 $value = $valueExp->evaluate();
15510 # The value of the expression must be a number
15511 if (! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)) {
15512  
15513 return $self->scriptObj->setError(
15514 'invalid_expression_in_POKEPLUS_statement',
15515 $self->_objClass . '->implement',
15516 );
15517 }
15518  
15519 # Process the string representing the Axmud internal variable
15520 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15521 = $self->scriptObj->session->parsePeekPoke($internalVar);
15522 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15523  
15524 return $self->scriptObj->setError(
15525 'POKEPLUS_operation_failure',
15526 $self->_objClass . '->implement',
15527 );
15528  
15529 } elsif ($objFlag) {
15530  
15531 return $self->scriptObj->setError(
15532 'POKEPLUS_cannot_export_to_object',
15533 $self->_objClass . '->implement',
15534 );
15535 }
15536  
15537 # This statement only accepts Perl scalars whose values are numbers
15538 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15539  
15540 return $self->scriptObj->setError(
15541 'POKEPLUS_operation_expects_scalar',
15542 $self->_objClass . '->implement',
15543 );
15544 }
15545  
15546 if (
15547 ! defined $blessed->$ivName
15548 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15549 ) {
15550 return $self->scriptObj->setError(
15551 'POKEPLUS_operation_expects_numeric',
15552 $self->_objClass . '->implement',
15553 );
15554 }
15555  
15556 # Perform the POKEPLUS operation
15557 $blessed->ivPlus($ivName, $value);
15558  
15559 # Implementation complete
15560 return 1;
15561 }
15562 }
15563  
15564 { package Language::Axbasic::Statement::pokepop;
15565  
15566 use strict;
15567 use warnings;
15568 use diagnostics;
15569  
15570 use Glib qw(TRUE FALSE);
15571  
15572 @Language::Axbasic::Statement::pokepop::ISA = qw(
15573 Language::Axbasic
15574 Language::Axbasic::Statement
15575 );
15576  
15577 # POKEPOP variable-name = axmud-object-property
15578 # POKEPOP ARRAY variable-name = axmud-object-property
15579  
15580 ##################
15581 # Methods
15582  
15583 sub parse {
15584  
15585 # Called by LA::Line->parse directly after a call to LA::Statement->new
15586 #
15587 # Expected arguments
15588 # (none besides $self)
15589 #
15590 # Return values
15591 # 'undef' on improper arguments or if there is an error
15592 # 1 otherwise
15593  
15594 my ($self, $check) = @_;
15595  
15596 # Check for improper arguments
15597 if (defined $check) {
15598  
15599 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15600 }
15601  
15602 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
15603 # $self->parseDataHash, ready for $self->implement to access
15604 # (NB POKEPOP is closer in format to a PEEK... statement, so we don't call ->parsePoke() )
15605 if (! $self->parsePeek()) {
15606  
15607 # ($self->scriptObj->setError has already been called)
15608 return undef;
15609 }
15610  
15611 # Parsing complete
15612 return 1;
15613 }
15614  
15615 sub implement {
15616  
15617 # Called by LA::Line->implement directly after a call to $self->parse
15618 #
15619 # Expected arguments
15620 # (none besides $self)
15621 #
15622 # Return values
15623 # 'undef' on improper arguments or if there is an error
15624 # 1 otherwise
15625  
15626 my ($self, $check) = @_;
15627  
15628 # Local variables
15629 my (
15630 # Standard
15631 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
15632 $var, $objFlag, $privFlag, $scalar, $varObj,
15633 @array,
15634 # Custom (set after $varObj is set)
15635 $popValue,
15636 );
15637  
15638 # Check for improper arguments
15639 if (defined $check) {
15640  
15641 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15642 }
15643  
15644 # Get the values stored by $self->parse
15645 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
15646 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
15647 $expression = $self->ivShow('parseDataHash', 'expression');
15648  
15649 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
15650 $expValue = $expression->evaluate();
15651 # Process the string representing the Axmud internal variable
15652 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15653 = $self->scriptObj->session->parsePeekPoke($expValue);
15654 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15655  
15656 return $self->scriptObj->setError(
15657 'POKEPOP_operation_failure',
15658 $self->_objClass . '->implement',
15659 );
15660 }
15661  
15662 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
15663 # or @array if $string refers to a list or hash value
15664 if (! $objFlag) {
15665  
15666 # This statement only accepts Perl lists
15667 if (defined $var && ref($var) eq 'ARRAY') {
15668  
15669 @array = @$var;
15670  
15671 } else {
15672  
15673 return $self->scriptObj->setError(
15674 'POKEPOP_operation_expects_list',
15675 $self->_objClass . '->implement',
15676 );
15677 }
15678  
15679 } else {
15680  
15681 return $self->scriptObj->setError(
15682 'POKEPOP_cannot_import_object',
15683 $self->_objClass . '->implement',
15684 );
15685 }
15686  
15687 # Look up the LA::Variable
15688 $varObj = $self->fetchVar('POKEPOP', $basicVarName, $parseArrayFlag);
15689 if (! $varObj) {
15690  
15691 # (self->scriptObj->setError already called)
15692 return undef;
15693 }
15694  
15695 # Now we can set the variable to POKEPOP's return value. If the list is empty, we use the
15696 # value 'undef' (which is converted by the call to ->importAsScalar or ->importAsList)
15697 $popValue = $blessed->ivPop($ivName);
15698  
15699 if (! $parseArrayFlag) {
15700  
15701 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
15702 # necessary
15703 $self->importAsScalar($varObj, $popValue);
15704  
15705 } else {
15706  
15707 # Import the list/hash into an Axbasic array, resizing it as necessary
15708 $self->importAsArray($varObj, $popValue);
15709 }
15710  
15711 # Implementation complete
15712 return 1;
15713 }
15714 }
15715  
15716 { package Language::Axbasic::Statement::pokepush;
15717  
15718 use strict;
15719 use warnings;
15720 use diagnostics;
15721  
15722 use Glib qw(TRUE FALSE);
15723  
15724 @Language::Axbasic::Statement::pokepush::ISA = qw(
15725 Language::Axbasic
15726 Language::Axbasic::Statement
15727 );
15728  
15729 # POKEPUSH axmud-object-property, expression
15730 # POKEPUSH axmud-object-property
15731  
15732 ##################
15733 # Methods
15734  
15735 sub parse {
15736  
15737 # Called by LA::Line->parse directly after a call to LA::Statement->new
15738 #
15739 # Expected arguments
15740 # (none besides $self)
15741 #
15742 # Return values
15743 # 'undef' on improper arguments or if there is an error
15744 # 1 otherwise
15745  
15746 my ($self, $check) = @_;
15747  
15748 # Check for improper arguments
15749 if (defined $check) {
15750  
15751 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15752 }
15753  
15754 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15755 # ready for $self->implement to access
15756 if (! $self->parsePoke(0, 1)) {
15757  
15758 # ($self->scriptObj->setError has already been called)
15759 return undef;
15760 }
15761  
15762 # Parsing complete
15763 return 1;
15764 }
15765  
15766 sub implement {
15767  
15768 # Called by LA::Line->implement directly after a call to $self->parse
15769 #
15770 # Expected arguments
15771 # (none besides $self)
15772 #
15773 # Return values
15774 # 'undef' on improper arguments or if there is an error
15775 # 1 otherwise
15776  
15777 my ($self, $check) = @_;
15778  
15779 # Local variables
15780 my (
15781 # Standard
15782 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15783 # Custom
15784 $valueExp, $value,
15785 );
15786  
15787 # Check for improper arguments
15788 if (defined $check) {
15789  
15790 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15791 }
15792  
15793 # Get the values stored by $self->parse
15794 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15795 $valueExp = $self->ivShift('parseDataList');
15796  
15797 # Evaluate the first expression to get the Axmud internal variable, e.g.
15798 # "current.world.name"
15799 $internalVar = $varExp->evaluate();
15800 # Evaluate the other expressions
15801 if (defined $valueExp) {
15802  
15803 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
15804 $value = $valueExp->evaluate();
15805 }
15806  
15807 # Process the string representing the Axmud internal variable
15808 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15809 = $self->scriptObj->session->parsePeekPoke($internalVar);
15810 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15811  
15812 return $self->scriptObj->setError(
15813 'POKEPUSH_operation_failure',
15814 $self->_objClass . '->implement',
15815 );
15816  
15817 } elsif ($objFlag) {
15818  
15819 return $self->scriptObj->setError(
15820 'POKEPUSH_cannot_export_to_object',
15821 $self->_objClass . '->implement',
15822 );
15823 }
15824  
15825 # This statement only accepts Perl lists
15826 if (! defined $var || ref($var) ne 'ARRAY') {
15827  
15828 return $self->scriptObj->setError(
15829 'POKEPUSH_operation_expects_list',
15830 $self->_objClass . '->implement',
15831 );
15832 }
15833  
15834 # Perform the POKEPUSH operation. If the minimum number of expressions was specified, $value
15835 # is 'undef'
15836 $blessed->ivPush($ivName, $value);
15837  
15838 # Implementation complete
15839 return 1;
15840 }
15841 }
15842  
15843 { package Language::Axbasic::Statement::pokereplace;
15844  
15845 use strict;
15846 use warnings;
15847 use diagnostics;
15848  
15849 use Glib qw(TRUE FALSE);
15850  
15851 @Language::Axbasic::Statement::pokereplace::ISA = qw(
15852 Language::Axbasic
15853 Language::Axbasic::Statement
15854 );
15855  
15856 # POKEREPLACE axmud-object-property, expression, expression
15857 # POKEREPLACE axmud-object-property, expression
15858  
15859 ##################
15860 # Methods
15861  
15862 sub parse {
15863  
15864 # Called by LA::Line->parse directly after a call to LA::Statement->new
15865 #
15866 # Expected arguments
15867 # (none besides $self)
15868 #
15869 # Return values
15870 # 'undef' on improper arguments or if there is an error
15871 # 1 otherwise
15872  
15873 my ($self, $check) = @_;
15874  
15875 # Check for improper arguments
15876 if (defined $check) {
15877  
15878 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15879 }
15880  
15881 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15882 # ready for $self->implement to access
15883 if (! $self->parsePoke(1, 2)) {
15884  
15885 # ($self->scriptObj->setError has already been called)
15886 return undef;
15887 }
15888  
15889 # Parsing complete
15890 return 1;
15891 }
15892  
15893 sub implement {
15894  
15895 # Called by LA::Line->implement directly after a call to $self->parse
15896 #
15897 # Expected arguments
15898 # (none besides $self)
15899 #
15900 # Return values
15901 # 'undef' on improper arguments or if there is an error
15902 # 1 otherwise
15903  
15904 my ($self, $check) = @_;
15905  
15906 # Local variables
15907 my (
15908 # Standard
15909 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15910 # Custom
15911 $indexExp, $index, $valueExp, $value,
15912 );
15913  
15914 # Check for improper arguments
15915 if (defined $check) {
15916  
15917 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15918 }
15919  
15920 # Get the values stored by $self->parse
15921 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15922 $indexExp = $self->ivShift('parseDataList');
15923 $valueExp = $self->ivShift('parseDataList');
15924  
15925 # Evaluate the first expression to get the Axmud internal variable, e.g.
15926 # "current.world.name"
15927 $internalVar = $varExp->evaluate();
15928 # Evaluate the other expressions
15929 $index = $indexExp->evaluate();
15930 if (defined $valueExp) {
15931  
15932 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
15933 $value = $valueExp->evaluate();
15934 }
15935  
15936 # Process the string representing the Axmud internal variable
15937 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15938 = $self->scriptObj->session->parsePeekPoke($internalVar);
15939 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15940  
15941 return $self->scriptObj->setError(
15942 'POKEREPLACE_operation_failure',
15943 $self->_objClass . '->implement',
15944 );
15945  
15946 } elsif ($objFlag) {
15947  
15948 return $self->scriptObj->setError(
15949 'POKEREPLACE_cannot_export_to_object',
15950 $self->_objClass . '->implement',
15951 );
15952 }
15953  
15954 # This statement only accepts Perl lists
15955 if (! defined $var || ref($var) ne 'ARRAY') {
15956  
15957 return $self->scriptObj->setError(
15958 'POKEREPLACE_operation_expects_list',
15959 $self->_objClass . '->implement',
15960 );
15961 }
15962  
15963 # $index must be a valid integer, and exist in the list property
15964 if (
15965 ! defined $index
15966 || $index =~ /\D/
15967 || $index < 0
15968 || $index >= $blessed->ivNumber($ivName)
15969 ) {
15970 return $self->scriptObj->setError(
15971 'invalid_index_NUM',
15972 $self->_objClass . '->implement',
15973 'NUM', $index,
15974 );
15975 }
15976  
15977 # Perform the POKEREPLACE operation. If the minimum number of expressions was specified,
15978 # $value is 'undef'
15979 $blessed->ivReplace($ivName, $index, $value);
15980  
15981 # Implementation complete
15982 return 1;
15983 }
15984 }
15985  
15986 { package Language::Axbasic::Statement::pokeset;
15987  
15988 use strict;
15989 use warnings;
15990 use diagnostics;
15991  
15992 use Glib qw(TRUE FALSE);
15993  
15994 @Language::Axbasic::Statement::pokeset::ISA = qw(
15995 Language::Axbasic
15996 Language::Axbasic::Statement
15997 );
15998  
15999 # POKESET axmud-object-property, expression
16000 # POKESET axmud-object-property
16001  
16002 ##################
16003 # Methods
16004  
16005 sub parse {
16006  
16007 # Called by LA::Line->parse directly after a call to LA::Statement->new
16008 #
16009 # Expected arguments
16010 # (none besides $self)
16011 #
16012 # Return values
16013 # 'undef' on improper arguments or if there is an error
16014 # 1 otherwise
16015  
16016 my ($self, $check) = @_;
16017  
16018 # Check for improper arguments
16019 if (defined $check) {
16020  
16021 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16022 }
16023  
16024 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16025 # ready for $self->implement to access
16026 if (! $self->parsePoke(0, 1)) {
16027  
16028 # ($self->scriptObj->setError has already been called)
16029 return undef;
16030 }
16031  
16032 # Parsing complete
16033 return 1;
16034 }
16035  
16036 sub implement {
16037  
16038 # Called by LA::Line->implement directly after a call to $self->parse
16039 #
16040 # Expected arguments
16041 # (none besides $self)
16042 #
16043 # Return values
16044 # 'undef' on improper arguments or if there is an error
16045 # 1 otherwise
16046  
16047 my ($self, $check) = @_;
16048  
16049 # Local variables
16050 my (
16051 # Standard
16052 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16053 # Custom
16054 $valueExp, $value,
16055 );
16056  
16057 # Check for improper arguments
16058 if (defined $check) {
16059  
16060 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16061 }
16062  
16063 # Get the values stored by $self->parse
16064 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16065 $valueExp = $self->ivShift('parseDataList');
16066  
16067 # Evaluate the first expression to get the Axmud internal variable, e.g.
16068 # "current.world.name"
16069 $internalVar = $varExp->evaluate();
16070 # Evaluate the other expressions
16071 if (defined $valueExp) {
16072  
16073 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
16074 $value = $valueExp->evaluate();
16075 }
16076  
16077 # Process the string representing the Axmud internal variable
16078 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16079 = $self->scriptObj->session->parsePeekPoke($internalVar);
16080 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16081  
16082 return $self->scriptObj->setError(
16083 'POKESET_operation_failure',
16084 $self->_objClass . '->implement',
16085 );
16086  
16087 } elsif ($objFlag) {
16088  
16089 return $self->scriptObj->setError(
16090 'POKESET_cannot_export_to_object',
16091 $self->_objClass . '->implement',
16092 );
16093 }
16094  
16095 # This statement only accepts Perl scalars
16096 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
16097  
16098 return $self->scriptObj->setError(
16099 'POKESET_operation_expects_scalar',
16100 $self->_objClass . '->implement',
16101 );
16102 }
16103  
16104 # Perform the POKESET operation. If the minimum number of expressions was specified, $value
16105 # is 'undef'
16106 $blessed->ivSet($ivName, $value);
16107  
16108 # Implementation complete
16109 return 1;
16110 }
16111 }
16112  
16113 { package Language::Axbasic::Statement::pokeshift;
16114  
16115 use strict;
16116 use warnings;
16117 use diagnostics;
16118  
16119 use Glib qw(TRUE FALSE);
16120  
16121 @Language::Axbasic::Statement::pokeshift::ISA = qw(
16122 Language::Axbasic
16123 Language::Axbasic::Statement
16124 );
16125  
16126 # POKESHIFT variable-name = axmud-object-property
16127 # POKESHIFT ARRAY variable-name = axmud-object-property
16128  
16129 ##################
16130 # Methods
16131  
16132 sub parse {
16133  
16134 # Called by LA::Line->parse directly after a call to LA::Statement->new
16135 #
16136 # Expected arguments
16137 # (none besides $self)
16138 #
16139 # Return values
16140 # 'undef' on improper arguments or if there is an error
16141 # 1 otherwise
16142  
16143 my ($self, $check) = @_;
16144  
16145 # Check for improper arguments
16146 if (defined $check) {
16147  
16148 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16149 }
16150  
16151 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
16152 # $self->parseDataHash, ready for $self->implement to access
16153 # (NB POKESHIFT is closer in format to a PEEK... statement, so we don't call ->parsePoke() )
16154 if (! $self->parsePeek()) {
16155  
16156 # ($self->scriptObj->setError has already been called)
16157 return undef;
16158 }
16159  
16160 # Parsing complete
16161 return 1;
16162 }
16163  
16164 sub implement {
16165  
16166 # Called by LA::Line->implement directly after a call to $self->parse
16167 #
16168 # Expected arguments
16169 # (none besides $self)
16170 #
16171 # Return values
16172 # 'undef' on improper arguments or if there is an error
16173 # 1 otherwise
16174  
16175 my ($self, $check) = @_;
16176  
16177 # Local variables
16178 my (
16179 # Standard
16180 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
16181 $var, $objFlag, $privFlag, $scalar, $varObj,
16182 @array,
16183 # Custom (set after $varObj is set)
16184 $shiftValue,
16185 );
16186  
16187 # Check for improper arguments
16188 if (defined $check) {
16189  
16190 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16191 }
16192  
16193 # Get the values stored by $self->parse
16194 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
16195 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
16196 $expression = $self->ivShow('parseDataHash', 'expression');
16197  
16198 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
16199 $expValue = $expression->evaluate();
16200 # Process the string representing the Axmud internal variable
16201 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16202 = $self->scriptObj->session->parsePeekPoke($expValue);
16203 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16204  
16205 return $self->scriptObj->setError(
16206 'POKESHIFT_operation_failure',
16207 $self->_objClass . '->implement',
16208 );
16209 }
16210  
16211 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
16212 # or @array if $string refers to a list or hash value
16213 if (! $objFlag) {
16214  
16215 # This statement only accepts Perl lists
16216 if (defined $var && ref($var) eq 'ARRAY') {
16217  
16218 @array = @$var;
16219  
16220 } else {
16221  
16222 return $self->scriptObj->setError(
16223 'POKESHIFT_operation_expects_list',
16224 $self->_objClass . '->implement',
16225 );
16226 }
16227  
16228 } else {
16229  
16230 return $self->scriptObj->setError(
16231 'POKESHIFT_cannot_import_object',
16232 $self->_objClass . '->implement',
16233 );
16234 }
16235  
16236 # Look up the LA::Variable
16237 $varObj = $self->fetchVar('POKESHIFT', $basicVarName, $parseArrayFlag);
16238 if (! $varObj) {
16239  
16240 # (self->scriptObj->setError already called)
16241 return undef;
16242 }
16243  
16244 # Now we can set the variable to POKESHIFT's return value. If the list is empty, we use the
16245 # value 'undef' (which is converted by the call to ->importAsScalar or ->importAsList)
16246 $shiftValue = $blessed->ivShift($ivName);
16247  
16248 if (! $parseArrayFlag) {
16249  
16250 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
16251 # necessary
16252 $self->importAsScalar($varObj, $shiftValue);
16253  
16254 } else {
16255  
16256 # Import the list/hash into an Axbasic array, resizing it as necessary
16257 $self->importAsArray($varObj, $shiftValue);
16258 }
16259  
16260 # Implementation complete
16261 return 1;
16262 }
16263 }
16264  
16265 { package Language::Axbasic::Statement::poketrue;
16266  
16267 use strict;
16268 use warnings;
16269 use diagnostics;
16270  
16271 use Glib qw(TRUE FALSE);
16272  
16273 @Language::Axbasic::Statement::poketrue::ISA = qw(
16274 Language::Axbasic
16275 Language::Axbasic::Statement
16276 );
16277  
16278 # POKETRUE axmud-object-property
16279  
16280 ##################
16281 # Methods
16282  
16283 sub parse {
16284  
16285 # Called by LA::Line->parse directly after a call to LA::Statement->new
16286 #
16287 # Expected arguments
16288 # (none besides $self)
16289 #
16290 # Return values
16291 # 'undef' on improper arguments or if there is an error
16292 # 1 otherwise
16293  
16294 my ($self, $check) = @_;
16295  
16296 # Check for improper arguments
16297 if (defined $check) {
16298  
16299 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16300 }
16301  
16302 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16303 # ready for $self->implement to access
16304 if (! $self->parsePoke(0)) {
16305  
16306 # ($self->scriptObj->setError has already been called)
16307 return undef;
16308 }
16309  
16310 # Parsing complete
16311 return 1;
16312 }
16313  
16314 sub implement {
16315  
16316 # Called by LA::Line->implement directly after a call to $self->parse
16317 #
16318 # Expected arguments
16319 # (none besides $self)
16320 #
16321 # Return values
16322 # 'undef' on improper arguments or if there is an error
16323 # 1 otherwise
16324  
16325 my ($self, $check) = @_;
16326  
16327 # Local variables
16328 my (
16329 # Standard
16330 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16331 # Custom
16332 );
16333  
16334 # Check for improper arguments
16335 if (defined $check) {
16336  
16337 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16338 }
16339  
16340 # Get the values stored by $self->parse
16341 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16342  
16343 # Evaluate the first expression to get the Axmud internal variable, e.g.
16344 # "current.world.name"
16345 $internalVar = $varExp->evaluate();
16346  
16347 # Process the string representing the Axmud internal variable
16348 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16349 = $self->scriptObj->session->parsePeekPoke($internalVar);
16350 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16351  
16352 return $self->scriptObj->setError(
16353 'POKETRUE_operation_failure',
16354 $self->_objClass . '->implement',
16355 );
16356  
16357 } elsif ($objFlag) {
16358  
16359 return $self->scriptObj->setError(
16360 'POKETRUE_cannot_export_to_object',
16361 $self->_objClass . '->implement',
16362 );
16363 }
16364  
16365 # This statement only accepts Perl scalars
16366 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
16367  
16368 return $self->scriptObj->setError(
16369 'POKETRUE_operation_expects_scalar',
16370 $self->_objClass . '->implement',
16371 );
16372 }
16373  
16374 # Perform the POKETRUE operation
16375 $blessed->ivTrue($ivName);
16376  
16377 # Implementation complete
16378 return 1;
16379 }
16380 }
16381  
16382 { package Language::Axbasic::Statement::pokeundef;
16383  
16384 use strict;
16385 use warnings;
16386 use diagnostics;
16387  
16388 use Glib qw(TRUE FALSE);
16389  
16390 @Language::Axbasic::Statement::pokeundef::ISA = qw(
16391 Language::Axbasic
16392 Language::Axbasic::Statement
16393 );
16394  
16395 # POKEUNDEF axmud-object-property
16396  
16397 ##################
16398 # Methods
16399  
16400 sub parse {
16401  
16402 # Called by LA::Line->parse directly after a call to LA::Statement->new
16403 #
16404 # Expected arguments
16405 # (none besides $self)
16406 #
16407 # Return values
16408 # 'undef' on improper arguments or if there is an error
16409 # 1 otherwise
16410  
16411 my ($self, $check) = @_;
16412  
16413 # Check for improper arguments
16414 if (defined $check) {
16415  
16416 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16417 }
16418  
16419 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16420 # ready for $self->implement to access
16421 if (! $self->parsePoke(0)) {
16422  
16423 # ($self->scriptObj->setError has already been called)
16424 return undef;
16425 }
16426  
16427 # Parsing complete
16428 return 1;
16429 }
16430  
16431 sub implement {
16432  
16433 # Called by LA::Line->implement directly after a call to $self->parse
16434 #
16435 # Expected arguments
16436 # (none besides $self)
16437 #
16438 # Return values
16439 # 'undef' on improper arguments or if there is an error
16440 # 1 otherwise
16441  
16442 my ($self, $check) = @_;
16443  
16444 # Local variables
16445 my (
16446 # Standard
16447 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16448 # Custom
16449 );
16450  
16451 # Check for improper arguments
16452 if (defined $check) {
16453  
16454 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16455 }
16456  
16457 # Get the values stored by $self->parse
16458 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16459  
16460 # Evaluate the first expression to get the Axmud internal variable, e.g.
16461 # "current.world.name"
16462 $internalVar = $varExp->evaluate();
16463  
16464 # Process the string representing the Axmud internal variable
16465 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16466 = $self->scriptObj->session->parsePeekPoke($internalVar);
16467 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16468  
16469 return $self->scriptObj->setError(
16470 'POKEUNDEF_operation_failure',
16471 $self->_objClass . '->implement',
16472 );
16473  
16474 } elsif ($objFlag) {
16475  
16476 return $self->scriptObj->setError(
16477 'POKEUNDEF_cannot_export_to_object',
16478 $self->_objClass . '->implement',
16479 );
16480 }
16481  
16482 # This statement only accepts Perl scalars
16483 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
16484  
16485 return $self->scriptObj->setError(
16486 'POKEUNDEF_operation_expects_scalar',
16487 $self->_objClass . '->implement',
16488 );
16489 }
16490  
16491 # Perform the POKEUNDEF operation
16492 $blessed->ivUndef($ivName);
16493  
16494 # Implementation complete
16495 return 1;
16496 }
16497 }
16498  
16499 { package Language::Axbasic::Statement::pokeunshift;
16500  
16501 use strict;
16502 use warnings;
16503 use diagnostics;
16504  
16505 use Glib qw(TRUE FALSE);
16506  
16507 @Language::Axbasic::Statement::pokeunshift::ISA = qw(
16508 Language::Axbasic
16509 Language::Axbasic::Statement
16510 );
16511  
16512 # POKEUNSHIFT axmud-object-property, expression
16513 # POKEUNSHIFT axmud-object-property
16514  
16515 ##################
16516 # Methods
16517  
16518 sub parse {
16519  
16520 # Called by LA::Line->parse directly after a call to LA::Statement->new
16521 #
16522 # Expected arguments
16523 # (none besides $self)
16524 #
16525 # Return values
16526 # 'undef' on improper arguments or if there is an error
16527 # 1 otherwise
16528  
16529 my ($self, $check) = @_;
16530  
16531 # Check for improper arguments
16532 if (defined $check) {
16533  
16534 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16535 }
16536  
16537 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16538 # ready for $self->implement to access
16539 if (! $self->parsePoke(0, 1)) {
16540  
16541 # ($self->scriptObj->setError has already been called)
16542 return undef;
16543 }
16544  
16545 # Parsing complete
16546 return 1;
16547 }
16548  
16549 sub implement {
16550  
16551 # Called by LA::Line->implement directly after a call to $self->parse
16552 #
16553 # Expected arguments
16554 # (none besides $self)
16555 #
16556 # Return values
16557 # 'undef' on improper arguments or if there is an error
16558 # 1 otherwise
16559  
16560 my ($self, $check) = @_;
16561  
16562 # Local variables
16563 my (
16564 # Standard
16565 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16566 # Custom
16567 $valueExp, $value,
16568 );
16569  
16570 # Check for improper arguments
16571 if (defined $check) {
16572  
16573 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16574 }
16575  
16576 # Get the values stored by $self->parse
16577 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16578 $valueExp = $self->ivShift('parseDataList');
16579  
16580 # Evaluate the first expression to get the Axmud internal variable, e.g.
16581 # "current.world.name"
16582 $internalVar = $varExp->evaluate();
16583 # Evaluate the other expressions
16584 if (defined $valueExp) {
16585  
16586 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
16587 $value = $valueExp->evaluate();
16588 }
16589  
16590 # Process the string representing the Axmud internal variable
16591 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16592 = $self->scriptObj->session->parsePeekPoke($internalVar);
16593 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16594  
16595 return $self->scriptObj->setError(
16596 'POKEUNSHIFT_operation_failure',
16597 $self->_objClass . '->implement',
16598 );
16599  
16600 } elsif ($objFlag) {
16601  
16602 return $self->scriptObj->setError(
16603 'POKEUNSHIFT_cannot_export_to_object',
16604 $self->_objClass . '->implement',
16605 );
16606 }
16607  
16608 # This statement only accepts Perl lists
16609 if (! defined $var || ref($var) ne 'ARRAY') {
16610  
16611 return $self->scriptObj->setError(
16612 'POKEUNSHIFT_operation_expects_list',
16613 $self->_objClass . '->implement',
16614 );
16615 }
16616  
16617 # Perform the POKEUNSHIFT operation. If the minimum number of expressions was specified,
16618 # $value is 'undef'
16619 $blessed->ivUnshift($ivName, $value);
16620  
16621 # Implementation complete
16622 return 1;
16623 }
16624 }
16625  
16626 { package Language::Axbasic::Statement::pop;
16627  
16628 use strict;
16629 use warnings;
16630 use diagnostics;
16631  
16632 use Glib qw(TRUE FALSE);
16633  
16634 @Language::Axbasic::Statement::pop::ISA = qw(
16635 Language::Axbasic
16636 Language::Axbasic::Statement
16637 );
16638  
16639 # POP array-name [ , variable-name ]
16640  
16641 ##################
16642 # Methods
16643  
16644 sub parse {
16645  
16646 # Called by LA::Line->parse directly after a call to LA::Statement->new
16647 #
16648 # Expected arguments
16649 # (none besides $self)
16650 #
16651 # Return values
16652 # 'undef' on improper arguments or if there is an error
16653 # 1 otherwise
16654  
16655 my ($self, $check) = @_;
16656  
16657 # Local variables
16658 my ($arrayExp, $scalarExp);
16659  
16660 # Check for improper arguments
16661 if (defined $check) {
16662  
16663 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16664 }
16665  
16666 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
16667 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
16668 # that created by
16669 # DIM var (10)
16670 # ...by a variable name that looks like a scalar, i.e.
16671 # SORT var
16672 $self->scriptObj->set_declareMode('simple');
16673  
16674 # Get the array variable name
16675 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
16676 $self->scriptObj,
16677 $self->tokenGroupObj,
16678 );
16679  
16680 if (! defined $arrayExp) {
16681  
16682 return $self->scriptObj->setError(
16683 'missing_or_illegal_array_variable',
16684 $self->_objClass . '->parse',
16685 );
16686 }
16687  
16688 # Reset the temporary IV
16689 $self->scriptObj->set_declareMode('default');
16690  
16691 # Extract the optional scalar variable name
16692 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
16693  
16694 $scalarExp = Language::Axbasic::Expression::Lvalue->new(
16695 $self->scriptObj,
16696 $self->tokenGroupObj,
16697 );
16698  
16699 if (! defined $scalarExp) {
16700  
16701 return $self->scriptObj->setError(
16702 'missing_or_illegal_expression',
16703 $self->_objClass . '->parse',
16704 );
16705 }
16706 }
16707  
16708 if (! $self->tokenGroupObj->testStatementEnd()) {
16709  
16710 return $self->scriptObj->setError(
16711 'unexpected_keywords,_operators_or_expressions',
16712 $self->_objClass . '->parse',
16713 );
16714 }
16715  
16716 # Save the expression objects so $self->implement can use them, if it is called
16717 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
16718 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
16719  
16720 # Parsing complete
16721 return 1;
16722 }
16723  
16724 sub implement {
16725  
16726 # Called by LA::Line->implement directly after a call to $self->parse
16727 #
16728 # Expected arguments
16729 # (none besides $self)
16730 #
16731 # Return values
16732 # 'undef' on improper arguments
16733 # 1 otherwise
16734  
16735 my ($self, $check) = @_;
16736  
16737 # Local variables
16738 my ($arrayExp, $scalarExp, $removedVar);
16739  
16740 # Check for improper arguments
16741 if (defined $check) {
16742  
16743 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16744 }
16745  
16746 # Retrieve the variables stored by ->parse
16747 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
16748 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
16749  
16750 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be popped. Multi-dimensional arrays
16751 # (e.g. DIM var (5, 5, 2) ) can't be popped
16752 if ($arrayExp->varObj->dimCount > 1) {
16753  
16754 return $self->scriptObj->setError(
16755 'POP_statement_cannot_operate_on_multi-dimensional_array',
16756 $self->_objClass . '->implement',
16757 );
16758 }
16759  
16760 # Cannot use a numeric array with a string scalar, and vice-versa
16761 if (
16762 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp->varObj) =~ m/Numeric/))
16763 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp->varObj) =~ m/String/))
16764 ) {
16765 return $self->scriptObj->setError(
16766 'type_mismatch_error',
16767 $self->_objClass . '->implement',
16768 );
16769 }
16770  
16771 # Pop the stack, and use the popped value to set the variable. (If the array is empty, we
16772 # get an empty string or zero, as appropriate)
16773 $removedVar = $arrayExp->varObj->doPop();
16774 if ($removedVar) {
16775  
16776 $scalarExp->varObj->set($removedVar->value);
16777 }
16778  
16779 # Implementation complete
16780 return 1;
16781 }
16782 }
16783  
16784 { package Language::Axbasic::Statement::print;
16785  
16786 use strict;
16787 use warnings;
16788 use diagnostics;
16789  
16790 use Glib qw(TRUE FALSE);
16791  
16792 @Language::Axbasic::Statement::print::ISA = qw(
16793 Language::Axbasic
16794 Language::Axbasic::Statement
16795 );
16796  
16797 # PRINT [ expression [ separator ] [ expression [ separator ] ... ] ]
16798 # PRINT #channel: expression [ separator ] [ expression [ separator ] ... ]
16799  
16800 ##################
16801 # Methods
16802  
16803 sub parse {
16804  
16805 # Called by LA::Line->parse directly after a call to LA::Statement->new
16806 #
16807 # Expected arguments
16808 # (none besides $self)
16809 #
16810 # Return values
16811 # 'undef' on improper arguments or if there is an error
16812 # 1 otherwise
16813  
16814 my ($self, $check) = @_;
16815  
16816 # Local variables
16817 my ($tokenGroupObj, $token, $channel);
16818  
16819 # Check for improper arguments
16820 if (defined $check) {
16821  
16822 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16823 }
16824  
16825 # Which token group to use - start with the existing one
16826 $tokenGroupObj = $self->tokenGroupObj;
16827  
16828 # If the first token is a file channel, extract it
16829 $token = $self->tokenGroupObj->lookAhead();
16830 if ($token && $token->category eq 'file_channel') {
16831  
16832 $self->tokenGroupObj->shiftToken();
16833  
16834 # For PRINT statements, the file channel must include a colon at the end (e.g. '#5:' )
16835 if (! ($token->tokenText =~ m/\:$/)) {
16836  
16837 return $self->scriptObj->setError(
16838 'syntax_error',
16839 $self->_objClass . '->parse',
16840 );
16841 }
16842  
16843 # Get the channel number
16844 $token->tokenText =~ m/([0-9]+)/;
16845 $channel = $1;
16846  
16847 # True BASIC specifies that the channel must be in the range 1-999; same range used by
16848 # Axbasic
16849 if ($channel < 1 || $channel > 999) {
16850  
16851 return $self->scriptObj->setError(
16852 'file_channel_NUM_out_of_range',
16853 $self->_objClass . '->parse',
16854 'NUM', $channel,
16855 );
16856  
16857 } else {
16858  
16859 # Store the channel number; this also informs $self->implement that we're reading
16860 # from a file, not the user's keyboard
16861 $self->ivAdd('parseDataHash', 'channel', $channel);
16862 }
16863 }
16864  
16865 # Deal with an empty print statement, i.e. <print> is taken to be <print "">
16866 if (defined $tokenGroupObj->testStatementEnd()) {
16867  
16868 # Create a token group to represent the implied null string
16869 $tokenGroupObj = Language::Axbasic::TokenGroup->new($self->scriptObj, '""');
16870 if (! defined $tokenGroupObj) {
16871  
16872 return $self->scriptObj->setDebug(
16873 'Can\'t create token group',
16874 $self->_objClass . '->parse',
16875 );
16876  
16877 } else {
16878  
16879 if (! $tokenGroupObj->lex()) {
16880  
16881 return undef;
16882 }
16883 }
16884 }
16885  
16886 do {
16887  
16888 my ($argListObj, $expression, $endChar);
16889  
16890 # Handle the pseudo-function TAB (), implemented in Axbasic as a weak keyword
16891 if (defined $tokenGroupObj->shiftMatchingToken('tab')) {
16892  
16893 # Get an argument list, which should contain exactly 1 argument
16894 $argListObj = Language::Axbasic::Expression::ArgList->new(
16895 $self->scriptObj,
16896 $tokenGroupObj,
16897 );
16898  
16899 if (! defined $argListObj || (scalar $argListObj->argList) != 1) {
16900  
16901 return $self->scriptObj->setError(
16902 'missing_or_invalid_argument_list',
16903 $self->_objClass . '->parse',
16904 );
16905 }
16906  
16907 # Otherwise, the next token is an expression
16908 } else {
16909  
16910 # Convert the <print> argument into an expression
16911 $expression = Language::Axbasic::Expression::Arithmetic->new(
16912 $self->scriptObj,
16913 $tokenGroupObj,
16914 );
16915  
16916 if (! defined $expression) {
16917  
16918 return $self->scriptObj->setError(
16919 'missing_or_illegal_expression',
16920 $self->_objClass . '->parse',
16921 );
16922 }
16923 }
16924  
16925 # Look for a comma or semicolon
16926 $token = $tokenGroupObj->shiftTokenIfCategory('separator');
16927 if (defined $token) {
16928  
16929 # It's a comma/semicolon
16930 $endChar = $token->tokenText;
16931  
16932 } elsif (defined $tokenGroupObj->testStatementEnd()) {
16933  
16934 # No comma or semicolon ending the print statement
16935 $endChar = '';
16936  
16937 } else {
16938  
16939 # Something else which shouldn't be there
16940 return $self->scriptObj->setError(
16941 'syntax_error',
16942 $self->_objClass . '->parse',
16943 );
16944 }
16945  
16946 # Save the arglist/expression and the end character (comma or semicolon) so that
16947 # $self->implement can use it, if it is called
16948 if (defined $argListObj) {
16949 $self->ivPush('parseDataList', $argListObj, $endChar);
16950 } else {
16951 $self->ivPush('parseDataList', $expression, $endChar);
16952 }
16953  
16954 } until (defined $tokenGroupObj->testStatementEnd());
16955  
16956 # Parsing complete
16957 return 1;
16958 }
16959  
16960 sub implement {
16961  
16962 # Called by LA::Line->implement directly after a call to $self->parse
16963 #
16964 # Expected arguments
16965 # (none besides $self)
16966 #
16967 # Return values
16968 # 'undef' on improper arguments or if there is an error
16969 # 1 otherwise
16970  
16971 my ($self, $check) = @_;
16972  
16973 # Local variables
16974 my (
16975 $channel, $session, $taskObj, $channelObj, $fileHandle, $line, $newLineCharFlag,
16976 @printList,
16977 );
16978  
16979 # Check for improper arguments
16980 if (defined $check) {
16981  
16982 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16983 }
16984  
16985 # Retrieve the components stored by $self->parse
16986 $channel = $self->ivShow('parseDataHash', 'channel');
16987 @printList = $self->parseDataList;
16988  
16989 # For convenience, import the GA::Session and Script task (if any)
16990 $session = $self->scriptObj->session;
16991 $taskObj = $self->scriptObj->parentTask;
16992  
16993 # Deal with writing to a file, if a file channel was specified
16994 if (defined $channel) {
16995  
16996 # Check that the file channel exists
16997 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
16998  
16999 return $self->scriptObj->setError(
17000 'file_channel_NUM_not_open',
17001 $self->_objClass . '->implement',
17002 'NUM', $channel,
17003 );
17004  
17005 } else {
17006  
17007 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
17008 $fileHandle = $channelObj->fileHandle;
17009 }
17010  
17011 # Check that writing to the file channel is allowed
17012 if ($channelObj->accessType eq 'input') {
17013  
17014 return $self->scriptObj->setError(
17015 'file_channel_NUM_is_read_only',
17016 $self->_objClass . '->implement',
17017 'NUM', $channel,
17018 );
17019 }
17020  
17021 # Prepare the line to write to the file channel
17022 $line = '';
17023 # End the line with a newline char, unless the expressions end with a ';' or ','
17024 $newLineCharFlag = TRUE;
17025  
17026 while (@printList) {
17027  
17028 my ($expression, $endChar, $string, $number);
17029  
17030 $expression = shift @printList;
17031 $endChar = shift @printList;
17032  
17033 # Evaluate the expression. If there's been an error, ->setError should already have
17034 # been called to display the error message (and $string) will be 'undef')
17035 $string = $expression->evaluate();
17036 if (! defined $string) {
17037  
17038 # Implementation complete
17039 return 1;
17040  
17041 } else {
17042  
17043 $line .= $string;
17044 }
17045  
17046 # (No space is added after a number, when writing to a file channel)
17047  
17048 if ($endChar eq ',') {
17049  
17050 $number = 14 - ((length $line) % 14);
17051 $line .= (' ' x $number);
17052 $newLineCharFlag = FALSE;
17053  
17054 } elsif ($endChar eq ';') {
17055  
17056 $newLineCharFlag = FALSE;
17057  
17058 } else {
17059  
17060 $newLineCharFlag = TRUE;
17061 }
17062 }
17063  
17064 # Write the line to the file channel
17065 if ($newLineCharFlag) {
17066  
17067 $line .= "\n";
17068 }
17069  
17070 print $fileHandle $line;
17071  
17072 } else {
17073  
17074 # Otherwise, display the expressions, one after the other
17075 while (@printList) {
17076  
17077 my ($expression, $argListObj, $arg, $columns, $endChar, $string, $before, $after);
17078  
17079 $expression = shift @printList;
17080 $endChar = shift @printList;
17081  
17082 # In the case of TAB (n), the expression could be a LA::Expression::ArgList
17083 if ($expression->isa('Language::Axbasic::Expression::ArgList')) {
17084  
17085 # Evaluate the first item in the arglist, n, which should be an integer
17086 # The documentation is a little inconsistent about what should happen for
17087 # non-integer values, and the authors have tested old BASIC programmes which
17088 # produce them
17089 # For that reason, round down any floating point numbers, and any use column 1
17090 # for any value less than one (the latter suggested by the True BASIC docs)
17091 $arg = $expression->ivIndex('argList', 0);
17092 $columns = $arg->evaluate();
17093  
17094 if (! ($columns =~ m/^[-]?\d+(\.\d*)?$/)) {
17095  
17096 return $self->scriptObj->setError(
17097 'invalid_TAB_column_NUM',
17098 $self->_objClass . '->implement',
17099 'NUM', $columns,
17100 );
17101  
17102 } elsif ($columns < 1) {
17103  
17104 $columns = 1;
17105  
17106 } else {
17107  
17108 $columns = int($columns);
17109 }
17110  
17111 # $columns is a column number. Decrement it so it uses the same column numbering
17112 # system as LA::Script->column
17113 $columns--;
17114 if ($columns > $self->scriptObj->column) {
17115  
17116 # Move the cursor by adding some space characters on the current line
17117 $string = ' ' x ($columns - $self->scriptObj->column);
17118  
17119 } elsif ($columns == $self->scriptObj->column) {
17120  
17121 # Cursor is already at the correct position
17122 $string = '';
17123  
17124 } else {
17125  
17126 # Skip to the next line, and add some space characters there
17127 $string = ' ' x $columns;
17128  
17129 if ($self->scriptObj->forcedWinFlag) {
17130 $taskObj->insertPrint('');
17131 } else {
17132 $session->writeText('');
17133 }
17134 }
17135  
17136 } else {
17137  
17138  
17139 # Evaluate the expression. If there's been an error, ->setError should already
17140 # have been called to display the error message (and $string) will be 'undef')
17141 $string = $expression->evaluate();
17142 if (! defined $string) {
17143  
17144 # Implementation complete
17145 return 1;
17146 }
17147 }
17148  
17149 # In the original BASIC dialects, numerical values are preceded by a minus sign or
17150 # a leading space; and always followed by a trailing space
17151 if (ref($expression) =~ m/Numeric/) {
17152  
17153 if ($string >= 0) {
17154  
17155 $string = ' ' . $string;
17156 }
17157  
17158 $string .= ' ';
17159 }
17160  
17161 # Display the expressions in the 'main' window (unless $self->forcedWinFlag is set,
17162 # in which case the output is redirected to the task window)
17163  
17164 # Handle the end character (comma or semicolon)
17165 if ($endChar eq ',') {
17166  
17167 $after = 14 - (length($string) % 14);
17168 if ($after < 14) {
17169  
17170 $string .= ' ' x $after;
17171 }
17172  
17173 $before = 14 - ($self->scriptObj->column % 14);
17174 if ($before < 14) {
17175  
17176 $string = (' ' x $before) . $string;
17177 }
17178  
17179 # Display the string without a trailing newline character and adjust the column
17180 # accordingly
17181 if ($self->scriptObj->forcedWinFlag) {
17182  
17183 # (If ->column is not 0, the previous PRINT expression must have used a ','
17184 # or ';' character. When writing to the task window, 'echo' means 'no
17185 # newline character after this text')
17186 if ($self->scriptObj->column) {
17187 $taskObj->insertPrint($string, 'echo');
17188 } else {
17189 $taskObj->insertPrint($string);
17190 }
17191  
17192 } else {
17193  
17194 # (When writing to the 'main' window, 'echo' means 'no newline character
17195 # before this text')
17196 $session->writeText($string, 'echo');
17197 }
17198  
17199 $self->scriptObj->set_column($self->scriptObj->column + length($string));
17200  
17201 } elsif ($endChar eq ';') {
17202  
17203 # Display the string without a trailing newline character and adjust the column
17204 # accordingly
17205 if ($self->scriptObj->forcedWinFlag) {
17206  
17207 if ($self->scriptObj->column) {
17208 $taskObj->insertPrint($string, 'echo');
17209 } else {
17210 $taskObj->insertPrint($string);
17211 }
17212  
17213 } else {
17214  
17215 $session->writeText($string, 'echo');
17216 }
17217  
17218 $self->scriptObj->set_column($self->scriptObj->column + length($string));
17219  
17220 } else {
17221  
17222 # Display the string with a trailing newline character
17223 if ($self->scriptObj->forcedWinFlag) {
17224  
17225 if ($self->scriptObj->column) {
17226 $taskObj->insertPrint($string, 'echo');
17227 } else {
17228 $taskObj->insertPrint($string);
17229 }
17230  
17231 } else {
17232  
17233 $session->writeText($string);
17234 }
17235  
17236 $self->scriptObj->set_column(0);
17237 }
17238 }
17239 }
17240  
17241 # Make sure the text is visible immediately
17242 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->implement');
17243  
17244 # Implementation complete
17245 return 1;
17246 }
17247 }
17248  
17249 { package Language::Axbasic::Statement::profile;
17250  
17251 use strict;
17252 use warnings;
17253 use diagnostics;
17254  
17255 use Glib qw(TRUE FALSE);
17256  
17257 @Language::Axbasic::Statement::profile::ISA = qw(
17258 Language::Axbasic
17259 Language::Axbasic::Statement
17260 );
17261  
17262 # PROFILE [ expression ]
17263  
17264 ##################
17265 # Methods
17266  
17267 sub parse {
17268  
17269 # Called by LA::Line->parse directly after a call to LA::Statement->new
17270 #
17271 # Expected arguments
17272 # (none besides $self)
17273 #
17274 # Return values
17275 # 'undef' on improper arguments or if there is an error
17276 # 1 otherwise
17277  
17278 my ($self, $check) = @_;
17279  
17280 # Local variables
17281 my $nameExp;
17282  
17283 # Check for improper arguments
17284 if (defined $check) {
17285  
17286 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17287 }
17288  
17289 if (! $self->tokenGroupObj->testStatementEnd()) {
17290  
17291 # Convert the name string into an expression
17292 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
17293 $self->scriptObj,
17294 $self->tokenGroupObj,
17295 );
17296  
17297 if (! defined $nameExp) {
17298  
17299 return $self->scriptObj->setError(
17300 'missing_or_illegal_expression',
17301 $self->_objClass . '->parse',
17302 );
17303 }
17304 }
17305  
17306 # Check that nothing more remains
17307 if (! $self->tokenGroupObj->testStatementEnd()) {
17308  
17309 return $self->scriptObj->setError(
17310 'unexpected_keywords,_operators_or_expressions',
17311 $self->_objClass . '->parse',
17312 );
17313 }
17314  
17315 if ($nameExp) {
17316  
17317 # Store the expression, so $self->implement can retrieve it
17318 $self->ivAdd('parseDataHash', 'name', $nameExp);
17319 }
17320  
17321 # Parsing complete
17322 return 1;
17323 }
17324  
17325 sub implement {
17326  
17327 # Called by LA::Line->implement directly after a call to $self->parse
17328 #
17329 # Expected arguments
17330 # (none besides $self)
17331 #
17332 # Return values
17333 # 'undef' on improper arguments or if there is an error
17334 # 1 otherwise
17335  
17336 my ($self, $check) = @_;
17337  
17338 # Local variables
17339 my ($nameExp, $name);
17340  
17341 # Check for improper arguments
17342 if (defined $check) {
17343  
17344 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17345 }
17346  
17347 # Retrieve the argument stored by $self->parse
17348 $nameExp = $self->ivShow('parseDataHash', 'name');
17349  
17350 if (defined $nameExp) {
17351  
17352 # Evaluate the expression
17353 $name = $nameExp->evaluate();
17354  
17355 # Check that the profile actually exists
17356 if (! $self->scriptObj->session->ivExists('profHash', $name)) {
17357  
17358 # It doesn't exist, so resume using the current world
17359 $self->scriptObj->set_useProfile($self->scriptObj->session->currentWorld->name);
17360  
17361 } else {
17362  
17363 # Use the specified profile
17364 $self->scriptObj->set_useProfile($name);
17365 }
17366  
17367 } else {
17368  
17369 # No profile specified, so resume using the current world
17370 $self->scriptObj->set_useProfile($self->scriptObj->session->currentWorld->name);
17371 }
17372  
17373 # Implementation complete
17374 return 1;
17375 }
17376 }
17377  
17378 { package Language::Axbasic::Statement::push;
17379  
17380 use strict;
17381 use warnings;
17382 use diagnostics;
17383  
17384 use Glib qw(TRUE FALSE);
17385  
17386 @Language::Axbasic::Statement::push::ISA = qw(
17387 Language::Axbasic
17388 Language::Axbasic::Statement
17389 );
17390  
17391 # PUSH array-name , expression
17392  
17393 ##################
17394 # Methods
17395  
17396 sub parse {
17397  
17398 # Called by LA::Line->parse directly after a call to LA::Statement->new
17399 #
17400 # Expected arguments
17401 # (none besides $self)
17402 #
17403 # Return values
17404 # 'undef' on improper arguments or if there is an error
17405 # 1 otherwise
17406  
17407 my ($self, $check) = @_;
17408  
17409 # Local variables
17410 my ($arrayExp, $scalarExp);
17411  
17412 # Check for improper arguments
17413 if (defined $check) {
17414  
17415 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17416 }
17417  
17418 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
17419 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
17420 # that created by
17421 # DIM var (10)
17422 # ...by a variable name that looks like a scalar, i.e.
17423 # SORT var
17424 $self->scriptObj->set_declareMode('simple');
17425  
17426 # Get the array variable name
17427 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
17428 $self->scriptObj,
17429 $self->tokenGroupObj,
17430 );
17431  
17432 if (! defined $arrayExp) {
17433  
17434 return $self->scriptObj->setError(
17435 'missing_or_illegal_array_variable',
17436 $self->_objClass . '->parse',
17437 );
17438 }
17439  
17440 # Reset the temporary IV
17441 $self->scriptObj->set_declareMode('default');
17442  
17443 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
17444  
17445 return $self->scriptObj->setError(
17446 'syntax_error',
17447 $self->_objClass . '->parse',
17448 );
17449 }
17450  
17451 # Extract the non-optional scalar expression
17452 $scalarExp = Language::Axbasic::Expression::Arithmetic->new(
17453 $self->scriptObj,
17454 $self->tokenGroupObj,
17455 );
17456  
17457 if (! defined $scalarExp) {
17458  
17459 return $self->scriptObj->setError(
17460 'missing_or_illegal_expression',
17461 $self->_objClass . '->parse',
17462 );
17463 }
17464  
17465 if (! $self->tokenGroupObj->testStatementEnd()) {
17466  
17467 return $self->scriptObj->setError(
17468 'unexpected_keywords,_operators_or_expressions',
17469 $self->_objClass . '->parse',
17470 );
17471 }
17472  
17473 # Save the expression objects so $self->implement can use them, if it is called
17474 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
17475 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
17476  
17477 # Parsing complete
17478 return 1;
17479 }
17480  
17481 sub implement {
17482  
17483 # Called by LA::Line->implement directly after a call to $self->parse
17484 #
17485 # Expected arguments
17486 # (none besides $self)
17487 #
17488 # Return values
17489 # 'undef' on improper arguments
17490 # 1 otherwise
17491  
17492 my ($self, $check) = @_;
17493  
17494 # Local variables
17495 my ($arrayExp, $scalarExp, $removedVar);
17496  
17497 # Check for improper arguments
17498 if (defined $check) {
17499  
17500 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17501 }
17502  
17503 # Retrieve the variables stored by ->parse
17504 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
17505 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
17506  
17507 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be pushed. Multi-dimensional arrays
17508 # (e.g. DIM var (5, 5, 2) ) can't be pushed
17509 if ($arrayExp->varObj->dimCount > 1) {
17510  
17511 return $self->scriptObj->setError(
17512 'PUSH_statement_cannot_operate_on_multi-dimensional_array',
17513 $self->_objClass . '->implement',
17514 );
17515 }
17516  
17517 # Cannot use a numeric array with a string scalar, and vice-versa
17518 if (
17519 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp) =~ m/Numeric/))
17520 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp) =~ m/String/))
17521 ) {
17522 return $self->scriptObj->setError(
17523 'type_mismatch_error',
17524 $self->_objClass . '->implement',
17525 );
17526 }
17527  
17528 # Evaluate the expression, and push it to the stack
17529 $arrayExp->varObj->doPush($scalarExp->evaluate());
17530  
17531 # Implementation complete
17532 return 1;
17533 }
17534 }
17535  
17536 { package Language::Axbasic::Statement::randomize;
17537  
17538 use strict;
17539 use warnings;
17540 use diagnostics;
17541  
17542 use Glib qw(TRUE FALSE);
17543  
17544 @Language::Axbasic::Statement::randomize::ISA = qw(
17545 Language::Axbasic
17546 Language::Axbasic::Statement
17547 );
17548  
17549 # RANDOMIZE
17550  
17551 ##################
17552 # Methods
17553  
17554 sub parse {
17555  
17556 # Called by LA::Line->parse directly after a call to LA::Statement->new
17557 #
17558 # Expected arguments
17559 # (none besides $self)
17560 #
17561 # Return values
17562 # 'undef' on improper arguments or if there is an error
17563 # 1 otherwise
17564  
17565 my ($self, $check) = @_;
17566  
17567 # Local variables
17568 my ($expression);
17569  
17570 # Check for improper arguments
17571 if (defined $check) {
17572  
17573 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17574 }
17575  
17576 # RANDOMIZE statements always appear on their own
17577 if (! $self->tokenGroupObj->testStatementEnd()) {
17578  
17579 return $self->scriptObj->setError(
17580 'unexpected_keywords,_operators_or_expressions',
17581 $self->_objClass . '->parse',
17582 );
17583 }
17584  
17585 # Parsing complete
17586 return 1;
17587 }
17588  
17589 # sub implement {} # ->implement method from LA::Statement inherited
17590 }
17591  
17592 { package Language::Axbasic::Statement::read;
17593  
17594 use strict;
17595 use warnings;
17596 use diagnostics;
17597  
17598 use Glib qw(TRUE FALSE);
17599  
17600 @Language::Axbasic::Statement::read::ISA = qw(
17601 Language::Axbasic
17602 Language::Axbasic::Statement
17603 );
17604  
17605 # READ variable-name [ , variable-name ... ]
17606  
17607 ##################
17608 # Methods
17609  
17610 sub parse {
17611  
17612 # Called by LA::Line->parse directly after a call to LA::Statement->new
17613 #
17614 # Expected arguments
17615 # (none besides $self)
17616 #
17617 # Return values
17618 # 'undef' on improper arguments or if there is an error
17619 # 1 otherwise
17620  
17621 my ($self, $check) = @_;
17622  
17623 # Check for improper arguments
17624 if (defined $check) {
17625  
17626 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17627 }
17628  
17629 # The rest of the statement is a list of lvalues
17630 do {
17631  
17632 my $expression = Language::Axbasic::Expression::Lvalue->new(
17633 $self->scriptObj,
17634 $self->tokenGroupObj,
17635 );
17636  
17637 if (! defined $expression) {
17638  
17639 return $self->scriptObj->setError(
17640 'missing_or_illegal_variable',
17641 $self->_objClass . '->parse',
17642 );
17643  
17644 } else {
17645  
17646 $self->ivPush('parseDataList', $expression);
17647 }
17648  
17649 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
17650  
17651 # Parsing complete
17652 return 1;
17653 }
17654  
17655 sub implement {
17656  
17657 # Called by LA::Line->implement directly after a call to $self->parse
17658 #
17659 # Expected arguments
17660 # (none besides $self)
17661 #
17662 # Return values
17663 # 'undef' on improper arguments or if there is an error
17664 # 1 otherwise
17665  
17666 my ($self, $check) = @_;
17667  
17668 # Local variables
17669 my @lvalueList;
17670  
17671 # Check for improper arguments
17672 if (defined $check) {
17673  
17674 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17675 }
17676  
17677 # Retrieve the list of lvalues stored by $self->parse
17678 @lvalueList = $self->parseDataList;
17679 foreach my $lvalue (@lvalueList) {
17680  
17681 my ($var, $data, $value);
17682  
17683 $var = $lvalue->variable;
17684 if (! $var) {
17685  
17686 # Subscript out of bounds, or similar error, has already been set
17687 return undef;
17688 }
17689  
17690 $data = $self->scriptObj->shift_readDataList();
17691  
17692 if (! defined $data) {
17693  
17694 return $self->scriptObj->setError(
17695 'reading_past_end_of_data',
17696 $self->_objClass . '->implement',
17697 );
17698 }
17699  
17700 # $data is a LA::Expression::Constant, but we still have to evaluate it
17701 $value = $data->evaluate();
17702 $var->set($value);
17703 }
17704  
17705 # Implementation complete
17706 return 1;
17707 }
17708 }
17709  
17710 { package Language::Axbasic::Statement::redim;
17711  
17712 use strict;
17713 use warnings;
17714 use diagnostics;
17715  
17716 use Glib qw(TRUE FALSE);
17717  
17718 @Language::Axbasic::Statement::redim::ISA = qw(
17719 Language::Axbasic
17720 Language::Axbasic::Statement
17721 );
17722  
17723 # REDIM variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
17724  
17725 ##################
17726 # Methods
17727  
17728 sub parse {
17729  
17730 # Called by LA::Line->parse directly after a call to LA::Statement->new
17731 #
17732 # Expected arguments
17733 # (none besides $self)
17734 #
17735 # Return values
17736 # 'undef' on improper arguments or if there is an error
17737 # 1 otherwise
17738  
17739 my ($self, $check) = @_;
17740  
17741 # Local variables
17742 my $specialFlag;
17743  
17744 # Check for improper arguments
17745 if (defined $check) {
17746  
17747 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17748 }
17749  
17750 if ($self->scriptObj->executionMode eq 'line_num') {
17751  
17752 # In programmes with line numbers, we don't allow DIM .. (10 TO 20)
17753 $specialFlag = FALSE;
17754  
17755 } else {
17756  
17757 # A TRUE argument tells LA::Expression::Lvalue->new to attempt to extract an
17758 # LA::Expression::SpecialArgList, rather than an an LA::Expression::ArgList
17759 $specialFlag = TRUE;
17760 }
17761  
17762 # Process each array in turn (if several appear on the same line, they are separated by
17763 # commas)
17764 do {
17765  
17766 my $expression = Language::Axbasic::Expression::Lvalue->new(
17767 $self->scriptObj,
17768 $self->tokenGroupObj,
17769 $specialFlag,
17770 );
17771  
17772 if (! defined $expression) {
17773  
17774 return $self->scriptObj->setError(
17775 'missing_or_illegal_expression',
17776 $self->_objClass . '->parse',
17777 );
17778  
17779 } else {
17780  
17781 # Save the expression object so $self->implement can use it, if it is called
17782 $self->ivPush('parseDataList', $expression);
17783 }
17784  
17785 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
17786  
17787 # Parsing complete
17788 return 1;
17789 }
17790  
17791 sub implement {
17792  
17793 # Called by LA::Line->implement directly after a call to $self->parse
17794 #
17795 # Expected arguments
17796 # (none besides $self)
17797 #
17798 # Return values
17799 # 'undef' on improper arguments or if there is an error
17800 # 1 otherwise
17801  
17802 my ($self, $check) = @_;
17803  
17804 # Local variables
17805 my @expList;
17806  
17807 # Check for improper arguments
17808 if (defined $check) {
17809  
17810 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17811 }
17812  
17813 # Import the list of expressions saved by $self->parse
17814 @expList = $self->parseDataList;
17815  
17816 # Redimension each array in turn
17817 foreach my $expression (@expList) {
17818  
17819 my (@upperList, @boundList, @flatList);
17820  
17821 # If the $expression appeared in a line like REDIM var, rather than the correct REDIM
17822 # var(10), then ->argListObj won't be defined
17823 if (! defined $expression->argListObj) {
17824  
17825 return $self->scriptObj->setError(
17826 'invalid_expression_in_REDIM_statement',
17827 $self->_objClass . '->implement',
17828 );
17829 }
17830  
17831 if ($self->scriptObj->executionMode eq 'line_num') {
17832  
17833 # Set up the array. ->evaluate returns a list of upper bounds
17834 @upperList = $expression->argListObj->evaluate();
17835  
17836 # Convert that to a flat list in groups of two, in the form
17837 # (lower, upper, lower, upper...)
17838 # For programmes with line numbers, the lower bound is always 0 (see the explanatory
17839 # comments in LA::Variable::Array->new)
17840 # For any expression that could not be evaluated, an 'undef' value was placed in
17841 # @boundList, so we need to check for that too
17842 foreach my $value (@upperList) {
17843  
17844 if (! defined $value || $value =~ m/\D/) {
17845  
17846 return $self->scriptObj->setError(
17847 'invalid_bound_for_array_dimension',
17848 $self->_objClass . '->implement',
17849 );
17850  
17851 } else {
17852  
17853 push (@flatList, 0, $value);
17854 }
17855 }
17856  
17857 } else {
17858  
17859 # Set up the array. ->evaluate returns a list of list references. Each list
17860 # reference represents a dimension and specifies the bounds of that dimension;
17861 # either in the form (upper) or (lower, upper)
17862 @boundList = $expression->argListObj->evaluate();
17863  
17864 # Convert that to a flat list in groups of two, in the form
17865 # (lower, upper, lower, upper...)
17866 # For programmes without line numbers, we use 1 as the lower bound, if not
17867 # specified
17868 # For any expression that could not be evaluated, an 'undef' value was placed in
17869 # @boundList, so we need to check for that too
17870 foreach my $listRef (@boundList) {
17871  
17872 foreach my $value (@$listRef) {
17873  
17874 if (! defined $value || ! ($value =~ m/^[-]?\d+$/)) {
17875  
17876 return $self->scriptObj->setError(
17877 'invalid_bound_for_array_dimension',
17878 $self->_objClass . '->implement',
17879 );
17880 }
17881 }
17882  
17883 if (scalar (@$listRef) == 1) {
17884  
17885 # If the lower bound is not specified, it is 1; therefore in that case, the
17886 # upper bound cannot be less than 1)
17887 if ($$listRef[0] < 1) {
17888  
17889 return $self->scriptObj->setError(
17890 'invalid_bound_for_array_dimension',
17891 $self->_objClass . '->implement',
17892 );
17893  
17894 } else {
17895  
17896 push (@flatList, 1);
17897 }
17898 }
17899  
17900 push (@flatList, @$listRef);
17901 }
17902 }
17903  
17904 # Redimension the array
17905 $expression->varObj->dimension(@flatList);
17906 }
17907  
17908 # Implementation complete
17909 return 1;
17910 }
17911 }
17912  
17913 { package Language::Axbasic::Statement::relay;
17914  
17915 use strict;
17916 use warnings;
17917 use diagnostics;
17918  
17919 use Glib qw(TRUE FALSE);
17920  
17921 @Language::Axbasic::Statement::relay::ISA = qw(
17922 Language::Axbasic
17923 Language::Axbasic::Statement
17924 );
17925  
17926 # RELAY expression [ , expression ]
17927  
17928 ##################
17929 # Methods
17930  
17931 sub parse {
17932  
17933 # Called by LA::Line->parse directly after a call to LA::Statement->new
17934 #
17935 # Expected arguments
17936 # (none besides $self)
17937 #
17938 # Return values
17939 # 'undef' on improper arguments or if there is an error
17940 # 1 otherwise
17941  
17942 my ($self, $check) = @_;
17943  
17944 # Local variables
17945 my ($cmdExp, $token, $obscureExp);
17946  
17947 # Check for improper arguments
17948 if (defined $check) {
17949  
17950 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17951 }
17952  
17953 # Get the expression and store it for ->implement to use
17954 $cmdExp = Language::Axbasic::Expression::Arithmetic->new(
17955 $self->scriptObj,
17956 $self->tokenGroupObj,
17957 );
17958  
17959 if (! defined $cmdExp) {
17960  
17961 return $self->scriptObj->setError(
17962 'missing_or_illegal_expression',
17963 $self->_objClass . '->parse',
17964 );
17965 }
17966  
17967 # Get the second expression, if specified
17968 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
17969  
17970 $token = $self->tokenGroupObj->lookAhead();
17971 if (defined $token) {
17972  
17973 $obscureExp = Language::Axbasic::Expression::Arithmetic->new(
17974 $self->scriptObj,
17975 $self->tokenGroupObj,
17976 );
17977  
17978 if (! defined $obscureExp) {
17979  
17980 return $self->scriptObj->setError(
17981 'missing_or_illegal_expression',
17982 $self->_objClass . '->parse',
17983 );
17984 }
17985 }
17986 }
17987  
17988 # There should be nothing after the expression
17989 if (! $self->tokenGroupObj->testStatementEnd()) {
17990  
17991 return $self->scriptObj->setError(
17992 'unexpected_keywords,_operators_or_expressions',
17993 $self->_objClass . '->parse',
17994 );
17995 }
17996  
17997 # Store the expressions, so $self->implement can retrieve them
17998 $self->ivAdd('parseDataHash', 'cmd_exp', $cmdExp);
17999 $self->ivAdd('parseDataHash', 'obscure_exp', $obscureExp); # May be 'undef'
18000  
18001 # Parsing complete
18002 return 1;
18003 }
18004  
18005 sub implement {
18006  
18007 # Called by LA::Line->implement directly after a call to $self->parse
18008 #
18009 # Expected arguments
18010 # (none besides $self)
18011 #
18012 # Return values
18013 # 'undef' on improper arguments or if there is an error
18014 # 1 otherwise
18015  
18016 my ($self, $check) = @_;
18017  
18018 # Local variables
18019 my ($cmdExp, $obscureExp, $cmd, $obscure);
18020  
18021 # Check for improper arguments
18022 if (defined $check) {
18023  
18024 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18025 }
18026  
18027 # Retrieve the arguments stored by $self->parse
18028 $cmdExp = $self->ivShow('parseDataHash', 'cmd_exp');
18029 $obscureExp = $self->ivShow('parseDataHash', 'obscure_exp');
18030  
18031 # Evaluate the expression to get a world command
18032 $cmd = $cmdExp->evaluate();
18033 if ($obscureExp) {
18034  
18035 $obscure = $obscureExp->evaluate();
18036 }
18037  
18038 # Send the command to the world
18039 if ($obscureExp) {
18040  
18041 # If some part of the command has to be obscured in the 'main' window, we don't have to
18042 # worry about classifying it as a non-movement command; the GA::Session doesn't store
18043 # it anywhere
18044 $self->scriptObj->session->worldCmd($cmd, $obscure);
18045  
18046 } else {
18047  
18048 # It's an ordinary relay command
18049 $self->scriptObj->session->relayCmd($cmd);
18050 }
18051  
18052 # Implementation complete
18053 return 1;
18054 }
18055 }
18056  
18057 { package Language::Axbasic::Statement::rem;
18058  
18059 use strict;
18060 use warnings;
18061 use diagnostics;
18062  
18063 use Glib qw(TRUE FALSE);
18064  
18065 @Language::Axbasic::Statement::rem::ISA = qw(
18066 Language::Axbasic
18067 Language::Axbasic::Statement
18068 );
18069  
18070 # REM [ ... ]
18071  
18072 ##################
18073 # Methods
18074  
18075 sub parse {
18076  
18077 # Called by LA::Line->parse directly after a call to LA::Statement->new
18078 #
18079 # Expected arguments
18080 # (none besides $self)
18081 #
18082 # Return values
18083 # 'undef' on improper arguments or if there is an error
18084 # 1 otherwise
18085  
18086 my ($self, $check) = @_;
18087  
18088 # Local variables
18089 my $token;
18090  
18091 # Check for improper arguments
18092 if (defined $check) {
18093  
18094 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18095 }
18096  
18097 # Every token on a line after a 'rem' statement is part of the remark, and must be ignored
18098 $self->tokenGroupObj->set_tokenList();
18099  
18100 return 1;
18101 }
18102  
18103 # sub implement {} # ->implement method from LA::Statement inherited
18104 }
18105  
18106 { package Language::Axbasic::Statement::reset;
18107  
18108 use strict;
18109 use warnings;
18110 use diagnostics;
18111  
18112 use Glib qw(TRUE FALSE);
18113  
18114 @Language::Axbasic::Statement::reset::ISA = qw(
18115 Language::Axbasic
18116 Language::Axbasic::Statement
18117 );
18118  
18119 # RESET #channel: BEGIN
18120 # RESET #channel: END
18121  
18122 ##################
18123 # Methods
18124  
18125 sub parse {
18126  
18127 # Called by LA::Line->parse directly after a call to LA::Statement->new
18128 #
18129 # Expected arguments
18130 # (none besides $self)
18131 #
18132 # Return values
18133 # 'undef' on improper arguments or if there is an error
18134 # 1 otherwise
18135  
18136 my ($self, $check) = @_;
18137  
18138 # Local variables
18139 my ($channelToken, $channel, $nextToken);
18140  
18141 # Check for improper arguments
18142 if (defined $check) {
18143  
18144 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18145 }
18146  
18147 # Get the channel token. For RESET statements, it must include a colon at the end
18148 # (e.g. '#5:' )
18149 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
18150 if (! defined $channelToken || ! ($channelToken->tokenText =~ m/\:$/)) {
18151  
18152 return $self->scriptObj->setError(
18153 'syntax_error',
18154 $self->_objClass . '->parse',
18155 );
18156  
18157 } else {
18158  
18159 # Store the channel number
18160 $channelToken->tokenText =~ m/([0-9]+)/;
18161 $channel = $1;
18162  
18163 # True BASIC specifies that the channel must be in the range 1-999; same range used by
18164 # Axbasic
18165 if ($channel < 1 || $channel > 999) {
18166  
18167 return $self->scriptObj->setError(
18168 'file_channel_NUM_out_of_range',
18169 $self->_objClass . '->parse',
18170 'NUM', $channel,
18171 );
18172  
18173 } else {
18174  
18175 $self->ivAdd('parseDataHash', 'channel', $channel);
18176 }
18177 }
18178  
18179 # The next token must be one of the keywords BEGIN or END
18180 $nextToken = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
18181 if (
18182 ! $nextToken
18183 || ($nextToken->tokenText ne 'begin' && $nextToken->tokenText ne 'end')
18184 ) {
18185 return $self->scriptObj->setError(
18186 'syntax_error',
18187 $self->_objClass . '->parse',
18188 );
18189  
18190 } else {
18191  
18192 $self->ivAdd('parseDataHash', 'type', $nextToken->tokenText);
18193 }
18194  
18195 # Check that nothing follows the BEGIN/END keywords
18196 if (! $self->tokenGroupObj->testStatementEnd()) {
18197  
18198 return $self->scriptObj->setError(
18199 'unexpected_keywords,_operators_or_expressions',
18200 $self->_objClass . '->parse',
18201 );
18202 }
18203  
18204 # Parsing complete
18205 return 1;
18206 }
18207  
18208 sub implement {
18209  
18210 # Called by LA::Line->implement directly after a call to $self->parse
18211 #
18212 # Expected arguments
18213 # (none besides $self)
18214 #
18215 # Return values
18216 # 'undef' on improper arguments or if there is an error
18217 # 1 otherwise
18218  
18219 my ($self, $check) = @_;
18220  
18221 # Local variables
18222 my ($channel, $type, $channelObj);
18223  
18224 # Check for improper arguments
18225 if (defined $check) {
18226  
18227 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18228 }
18229  
18230 # Retrieve the variables stored by ->parse
18231 $channel = $self->ivShow('parseDataHash', 'channel');
18232 $type = $self->ivShow('parseDataHash', 'type');
18233  
18234 # Check that the file channel is open
18235 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
18236  
18237 return $self->scriptObj->setError(
18238 'file_channel_NUM_not_open',
18239 $self->_objClass . '->implement',
18240 'NUM', $channel,
18241 );
18242  
18243 } else {
18244  
18245 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
18246 }
18247  
18248 # Move the pointer
18249 if ($type eq 'begin') {
18250 seek($channelObj->fileHandle, 0, Fcntl::SEEK_SET);
18251 } elsif ($type eq 'end') {
18252 seek($channelObj->fileHandle, 0, Fcntl::SEEK_END);
18253 }
18254  
18255 # Implementation complete
18256 return 1;
18257 }
18258 }
18259  
18260 { package Language::Axbasic::Statement::restore;
18261  
18262 use strict;
18263 use warnings;
18264 use diagnostics;
18265  
18266 use Glib qw(TRUE FALSE);
18267  
18268 @Language::Axbasic::Statement::restore::ISA = qw(
18269 Language::Axbasic
18270 Language::Axbasic::Statement
18271 );
18272  
18273 # RESTORE
18274  
18275 ##################
18276 # Methods
18277  
18278 sub parse {
18279  
18280 # Called by LA::Line->parse directly after a call to LA::Statement->new
18281 #
18282 # Expected arguments
18283 # (none besides $self)
18284 #
18285 # Return values
18286 # 'undef' on improper arguments or if there is an error
18287 # 1 otherwise
18288  
18289 my ($self, $check) = @_;
18290  
18291 # Check for improper arguments
18292 if (defined $check) {
18293  
18294 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18295 }
18296  
18297 # RESTORE statements always appear on their own
18298 if (! $self->tokenGroupObj->testStatementEnd()) {
18299  
18300 return $self->scriptObj->setError(
18301 'unexpected_keywords,_operators_or_expressions',
18302 $self->_objClass . '->parse',
18303 );
18304 }
18305  
18306 # Parsing complete
18307 return 1;
18308 }
18309  
18310 sub implement {
18311  
18312 # Called by LA::Line->implement directly after a call to $self->parse
18313 #
18314 # Expected arguments
18315 # (none besides $self)
18316 #
18317 # Return values
18318 # 'undef' on improper arguments or if there is an error
18319 # 1 otherwise
18320  
18321 my ($self, $check) = @_;
18322  
18323 # Check for improper arguments
18324 if (defined $check) {
18325  
18326 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18327 }
18328  
18329 # Reset the global data list
18330 $self->scriptObj->set_readDataList($self->scriptObj->globalDataList);
18331  
18332 # Implementation complete
18333 return 1;
18334 }
18335 }
18336  
18337 { package Language::Axbasic::Statement::return;
18338  
18339 use strict;
18340 use warnings;
18341 use diagnostics;
18342  
18343 use Glib qw(TRUE FALSE);
18344  
18345 @Language::Axbasic::Statement::return::ISA = qw(
18346 Language::Axbasic
18347 Language::Axbasic::Statement
18348 );
18349  
18350 # RETURN expression
18351 # RETURN
18352  
18353 ##################
18354 # Methods
18355  
18356 sub parse {
18357  
18358 # Called by LA::Line->parse directly after a call to LA::Statement->new
18359 #
18360 # Expected arguments
18361 # (none besides $self)
18362 #
18363 # Return values
18364 # 'undef' on improper arguments or if there is an error
18365 # 1 otherwise
18366  
18367 my ($self, $check) = @_;
18368  
18369 # Local variables
18370 my $expression;
18371  
18372 # Check for improper arguments
18373 if (defined $check) {
18374  
18375 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18376 }
18377  
18378 # No line numbers
18379 if ($self->scriptObj->executionMode eq 'no_line_num') {
18380  
18381 # Check that we're inside a subroutine declaration
18382 if (! $self->scriptObj->currentParseSub) {
18383  
18384 return $self->scriptObj->setError(
18385 'RETURN_statement_used_outside_subroutine',
18386 $self->_objClass . '->parse',
18387 );
18388 }
18389  
18390 # The rest of the statement is an expression to return
18391 $expression = Language::Axbasic::Expression::Arithmetic->new(
18392 $self->scriptObj,
18393 $self->tokenGroupObj,
18394 );
18395  
18396 if (! defined $expression) {
18397  
18398 return $self->scriptObj->setError(
18399 'missing_or_illegal_expression',
18400 $self->_objClass . '->parse',
18401 );
18402 }
18403  
18404 # Check that nothing follows the expression
18405 if (! $self->tokenGroupObj->testStatementEnd()) {
18406  
18407 return $self->scriptObj->setError(
18408 'unexpected_keywords,_operators_or_expressions',
18409 $self->_objClass . '->parse',
18410 );
18411 }
18412  
18413 # Store the GOSUB expression, so $self->implement can retrieve it
18414 $self->ivAdd('parseDataHash', 'expression', $expression);
18415  
18416 # Line numbers
18417 } else {
18418  
18419 # We only need to check that the 'return' keyword isn't followed by anything
18420 if (! $self->tokenGroupObj->testStatementEnd()) {
18421  
18422 return $self->scriptObj->setError(
18423 'unexpected_keywords,_operators_or_expressions',
18424 $self->_objClass . '->parse',
18425 );
18426 }
18427 }
18428  
18429 # Parsing complete
18430 return 1;
18431 }
18432  
18433 sub implement {
18434  
18435 # Called by LA::Line->implement directly after a call to $self->parse
18436 #
18437 # Expected arguments
18438 # (none besides $self)
18439 #
18440 # Return values
18441 # 'undef' on improper arguments
18442 # 1 otherwise
18443  
18444 my ($self, $check) = @_;
18445  
18446 # Local variables
18447 my ($subObj, $statementObj, $callStatement, $expression, $lineNumber);
18448  
18449 # Check for improper arguments
18450 if (defined $check) {
18451  
18452 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18453 }
18454  
18455 # No line numbers
18456 if ($self->scriptObj->executionMode eq 'no_line_num') {
18457  
18458 $subObj = $self->scriptObj->popSubStack();
18459 if (! defined $subObj) {
18460  
18461 return $self->scriptObj->setDebug(
18462 'Sub/func stack seems to be empty',
18463 $self->_objClass . '->implement',
18464 );
18465 }
18466  
18467 # Execution resumes at the first statement after the one that called the subroutine
18468 $callStatement = $subObj->callStatement;
18469  
18470 # The next statement to execute is the statement after that
18471 if (defined $callStatement->nextStatement) {
18472  
18473 # LA::Script->nextStatement is currently set to this statement; continue execution
18474 # as if this were the GOSUB statement
18475 $self->scriptObj->set_nextStatement($statementObj);
18476  
18477 } else {
18478  
18479 $self->scriptObj->set_nextStatement(undef);
18480 $self->scriptObj->set_nextLine($callStatement->lineObj->procLineNum + 1);
18481 }
18482  
18483 # If a return variable was specified (because the subroutine was called in a statement
18484 # like 'LET a$ = CALL mysub (args)' ), set its value
18485 if (defined $subObj->returnVar) {
18486  
18487 $expression = $self->ivShow('parseDataHash', 'expression');
18488 $subObj->returnVar->set($expression->evaluate());
18489 }
18490  
18491 # Line numbers
18492 } else {
18493  
18494 # Get the LA::Statement::gosub statement from the script's subroutine/function stack
18495 $statementObj = $self->scriptObj->pop_gosubStackList();
18496 if (! defined $statementObj) {
18497  
18498 return $self->scriptObj->setError(
18499 'RETURN_statement_without_matching_GOSUB',
18500 $self->_objClass . '->implement',
18501 );
18502 }
18503  
18504 # The next statement (or line) to be executed is the one after the gosub statement
18505 if (defined $statementObj->nextStatement) {
18506  
18507 $self->scriptObj->set_nextStatement($statementObj);
18508  
18509 } else {
18510  
18511 $self->scriptObj->set_nextStatement(undef);
18512 $self->scriptObj->set_nextLine($statementObj->lineObj->procLineNum + 1);
18513 }
18514 }
18515  
18516 # Implementation complete
18517 return 1;
18518 }
18519 }
18520  
18521 { package Language::Axbasic::Statement::revpath;
18522  
18523 use strict;
18524 use warnings;
18525 use diagnostics;
18526  
18527 use Glib qw(TRUE FALSE);
18528  
18529 @Language::Axbasic::Statement::revpath::ISA = qw(
18530 Language::Axbasic
18531 Language::Axbasic::Statement
18532 );
18533  
18534 # REVPATH variable-name
18535  
18536 ##################
18537 # Methods
18538  
18539 sub parse {
18540  
18541 # Called by LA::Line->parse directly after a call to LA::Statement->new
18542 #
18543 # Expected arguments
18544 # (none besides $self)
18545 #
18546 # Return values
18547 # 'undef' on improper arguments or if there is an error
18548 # 1 otherwise
18549  
18550 my ($self, $check) = @_;
18551  
18552 # Local variables
18553 my $lvalue;
18554  
18555 # Check for improper arguments
18556 if (defined $check) {
18557  
18558 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18559 }
18560  
18561 # (Copied from the SORT statement)
18562 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
18563 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
18564 # that created by
18565 # DIM path$ (10)
18566 # ...by a variable name that looks like a scalar, i.e.
18567 # REVPATH path$
18568 $self->scriptObj->set_declareMode('simple');
18569  
18570 # Get the variable name
18571 $lvalue = Language::Axbasic::Expression::Lvalue->new(
18572 $self->scriptObj,
18573 $self->tokenGroupObj,
18574 );
18575  
18576 if (! defined $lvalue) {
18577  
18578 return $self->scriptObj->setError(
18579 'missing_or_illegal_variable',
18580 $self->_objClass . '->parse',
18581 );
18582 }
18583  
18584 # Reset the temporary IV
18585 $self->scriptObj->set_declareMode('default');
18586  
18587 if (! $self->tokenGroupObj->testStatementEnd()) {
18588  
18589 return $self->scriptObj->setError(
18590 'unexpected_keywords,_operators_or_expressions',
18591 $self->_objClass . '->parse',
18592 );
18593 }
18594  
18595 # Store the variable for ->implement to use
18596 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
18597  
18598 # Parsing complete
18599 return 1;
18600 }
18601  
18602 sub implement {
18603  
18604 # Called by LA::Line->implement directly after a call to $self->parse
18605 #
18606 # Expected arguments
18607 # (none besides $self)
18608 #
18609 # Return values
18610 # 'undef' on improper arguments or if there is an error
18611 # 1 otherwise
18612  
18613 my ($self, $check) = @_;
18614  
18615 # Local variables
18616 my (
18617 $lvalue, $varObj, $count,
18618 @cellList, @valueList, @reversedList,
18619 );
18620  
18621 # Check for improper arguments
18622 if (defined $check) {
18623  
18624 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18625 }
18626  
18627 # Retrieve the array variable whose contents is to be reversed
18628 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
18629 $varObj = $lvalue->varObj;
18630  
18631 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be reversed. Multi-dimensional arrays
18632 # (e.g. DIM var (5, 5, 2) ) can't be reversed
18633 if ($varObj->dimCount > 1) {
18634  
18635 return $self->scriptObj->setError(
18636 'REVPATH_statement_cannot_operate_on_multi-dimensional_array',
18637 $self->_objClass . '->implement',
18638 );
18639 }
18640  
18641 # Import the values stored in the array, reverse them, and store them back in the array
18642 @cellList = $varObj->cellList;
18643  
18644 # Take account of the first item in ->cellList, which is the lower bound
18645 shift @cellList;
18646  
18647 if (@cellList) {
18648  
18649 # Get the values stored in the variables
18650 foreach my $var (@cellList) {
18651  
18652 push (@valueList, $var->value);
18653 }
18654  
18655 # The first arg, 0, instructs the function to not abbreviate anything and, for secondary
18656 # directions that have more than one possible opposite direction, to use the first one
18657 @reversedList = $self->scriptObj->session->worldModelObj->reversePath(
18658 $self->scriptObj->session,
18659 'no_abbrev',
18660 @valueList,
18661 );
18662  
18663 # Use the existing variables stored in the array, and simply change their values to the
18664 # reversed list of directions
18665 $count = -1;
18666 foreach my $var (@cellList) {
18667  
18668 $count++;
18669 $var->set($reversedList[$count]);
18670 }
18671 }
18672  
18673 # Implementation complete
18674 return 1;
18675 }
18676 }
18677  
18678 { package Language::Axbasic::Statement::select;
18679  
18680 use strict;
18681 use warnings;
18682 use diagnostics;
18683  
18684 use Glib qw(TRUE FALSE);
18685  
18686 @Language::Axbasic::Statement::select::ISA = qw(
18687 Language::Axbasic
18688 Language::Axbasic::Statement
18689 );
18690  
18691 # SELECT CASE variable-name
18692  
18693 ##################
18694 # Methods
18695  
18696 sub parse {
18697  
18698 # Called by LA::Line->parse directly after a call to LA::Statement->new
18699 #
18700 # Expected arguments
18701 # (none besides $self)
18702 #
18703 # Return values
18704 # 'undef' on improper arguments or if there is an error
18705 # 1 otherwise
18706  
18707 my ($self, $check) = @_;
18708  
18709 # Local variables
18710 my ($token, $expression, $subObj);
18711  
18712 # Check for improper arguments
18713 if (defined $check) {
18714  
18715 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18716 }
18717  
18718 # The 'select' keyword is not available in primitive numbering mode
18719 if ($self->scriptObj->executionMode ne 'no_line_num') {
18720  
18721 return $self->scriptObj->setError(
18722 'statement_not_available_with_line_numbers',
18723 $self->_objClass . '->parse',
18724 );
18725 }
18726  
18727 # The next token is always the keyword CASE
18728 $token = $self->tokenGroupObj->shiftMatchingToken('case');
18729 if (! defined $token) {
18730  
18731 return $self->scriptObj->setError(
18732 'syntax error',
18733 $self->_objClass . '->parse',
18734 );
18735 }
18736  
18737 # Read the variable name
18738 $expression = Language::Axbasic::Expression::Lvalue->new(
18739 $self->scriptObj,
18740 $self->tokenGroupObj,
18741 );
18742  
18743 if (! defined $expression) {
18744  
18745 return $self->scriptObj->setError(
18746 'missing_or_illegal_variable',
18747 $self->_objClass . '->parse',
18748 );
18749 }
18750  
18751 # Check there's nothing else in the statement after the variable
18752 if (! $self->tokenGroupObj->testStatementEnd()) {
18753  
18754 return $self->scriptObj->setError(
18755 'unexpected_keywords,_operators_or_expressions',
18756 $self->_objClass . '->parse',
18757 );
18758 }
18759  
18760 # Add this SELECT statement to the SELECT code block stack for the current subroutine
18761 $subObj = $self->scriptObj->returnCurrentSub();
18762 $subObj->push_selectStackList($self);
18763  
18764 # Store the iterator
18765 $self->ivAdd('parseDataHash', 'expression', $expression);
18766 # We don't know what the corresponding END SELECT (and, optionally, the CASE ELSE)
18767 # statements are, yet
18768 $self->ivAdd('parseDataHash', 'case_else_statement', undef);
18769 $self->ivAdd('parseDataHash', 'end_select_statement', undef);
18770  
18771 # Parsing complete
18772 return 1;
18773 }
18774  
18775 sub implement {
18776  
18777 # Called by LA::Line->implement directly after a call to $self->parse
18778 #
18779 # Expected arguments
18780 # (none besides $self)
18781 #
18782 # Return values
18783 # 'undef' on improper arguments or if there is an error
18784 # 1 otherwise
18785  
18786 my ($self, $check) = @_;
18787  
18788 # Local variables
18789 my (
18790 $expression, $value, $endStatement, $matchStatement, $caseElseStatement,
18791 $subObj,
18792 @caseStatementList,
18793 );
18794  
18795 # Check for improper arguments
18796 if (defined $check) {
18797  
18798 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18799 }
18800  
18801 # Retrieve the variable to test and the corresponding CASE and END SELECT statements
18802 $expression = $self->ivShow('parseDataHash', 'expression');
18803 $endStatement = $self->ivShow('parseDataHash', 'end_select_statement');
18804 @caseStatementList = $self->parseDataList;
18805  
18806 # Get the value of the variable
18807 $value = $expression->evaluate();
18808  
18809 # Each CASE statement contains, in its ->parseDataList, a list of constants.
18810 # Test each CASE statement's constant list. The CASE statement which contains the constant
18811 # matching the variable's value is the one to execute next
18812 OUTER: foreach my $caseStatement (@caseStatementList) {
18813  
18814 INNER: foreach my $constant ($caseStatement->parseDataList) {
18815  
18816 if ($value eq $constant) {
18817  
18818 $matchStatement = $caseStatement;
18819 last OUTER;
18820 }
18821 }
18822 }
18823  
18824 if (! $matchStatement) {
18825  
18826 # Use the CASE ELSE statement, if it was found during the ->parse stage
18827 $caseElseStatement = $self->ivShow('parseDataHash', 'case_else_statement');
18828 if (defined $caseElseStatement) {
18829  
18830 # The next statement to execute is the one after CASE ELSE
18831 if (defined $caseElseStatement->nextStatement) {
18832  
18833 # LA::Script->nextStatement is currently set to this statement; continue
18834 # execution as if this were the SELECT statement
18835 $self->scriptObj->set_nextStatement($caseElseStatement);
18836  
18837 } else {
18838  
18839 $self->scriptObj->set_nextStatement(undef);
18840 $self->scriptObj->set_nextLine($caseElseStatement->lineObj->procLineNum + 1);
18841 }
18842  
18843 } else {
18844  
18845 return $self->scriptObj->setError(
18846 'no_CASE_selected_and_no_CASE_ELSE',
18847 $self->_objClass . '->implement',
18848 );
18849 }
18850  
18851 } else {
18852  
18853 # The next statement to execute is the one after $matchStatement
18854 if (defined $matchStatement->nextStatement) {
18855  
18856 $self->scriptObj->ivPoke('nextStatement', $matchStatement);
18857  
18858 } else {
18859  
18860 $self->scriptObj->set_nextStatement(undef);
18861 $self->scriptObj->set_nextLine($matchStatement->lineObj->procLineNum + 1);
18862 }
18863 }
18864  
18865 # Add this SELECT CASE code block to the main code block stack, since we're going to execute
18866 # it now. The corresponding CASE/END SELECT statement will remove it.
18867 # NB The main ->blockStackList is used during ->implement for all kinds of code blocks;
18868 # ->selectStackList is used during ->parse for SELECT CASE..CASE..END SELECT blocks
18869 # only
18870 $subObj = $self->scriptObj->returnCurrentSub();
18871 $subObj->push_blockStackList($self);
18872  
18873 # Implementation complete
18874 return 1;
18875 }
18876 }
18877  
18878 { package Language::Axbasic::Statement::send;
18879  
18880 use strict;
18881 use warnings;
18882 use diagnostics;
18883  
18884 use Glib qw(TRUE FALSE);
18885  
18886 @Language::Axbasic::Statement::send::ISA = qw(
18887 Language::Axbasic
18888 Language::Axbasic::Statement
18889 );
18890  
18891 # SEND expression [ , expression [ , expression ... ] ]
18892  
18893 ##################
18894 # Methods
18895  
18896 sub parse {
18897  
18898 # Called by LA::Line->parse directly after a call to LA::Statement->new
18899 #
18900 # Expected arguments
18901 # (none besides $self)
18902 #
18903 # Return values
18904 # 'undef' on improper arguments or if there is an error
18905 # 1 otherwise
18906  
18907 my ($self, $check) = @_;
18908  
18909 # Local variables
18910 my (
18911 $cmdExp, $exitFlag,
18912 @otherExpList,
18913 );
18914  
18915 # Check for improper arguments
18916 if (defined $check) {
18917  
18918 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18919 }
18920  
18921 # Get the command expression
18922 $cmdExp = Language::Axbasic::Expression::Arithmetic->new(
18923 $self->scriptObj,
18924 $self->tokenGroupObj,
18925 );
18926  
18927 if (! defined $cmdExp) {
18928  
18929 return $self->scriptObj->setError(
18930 'missing_or_illegal_expression',
18931 $self->_objClass . '->parse',
18932 );
18933 }
18934  
18935 # Get the optional expressions
18936 do {
18937 my ($token, $otherExp);
18938  
18939 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
18940  
18941 $token = $self->tokenGroupObj->lookAhead();
18942 if (defined $token) {
18943  
18944 $otherExp = Language::Axbasic::Expression::Arithmetic->new(
18945 $self->scriptObj,
18946 $self->tokenGroupObj,
18947 );
18948  
18949 if (! defined $otherExp) {
18950  
18951 return $self->scriptObj->setError(
18952 'missing_or_illegal_expression',
18953 $self->_objClass . '->parse',
18954 );
18955  
18956 } else {
18957  
18958 push (@otherExpList, $otherExp);
18959 }
18960 }
18961  
18962 } else {
18963  
18964 $exitFlag = TRUE;
18965 }
18966  
18967 } until ($exitFlag);
18968  
18969 # Check that nothing follows the expressions
18970 if (! $self->tokenGroupObj->testStatementEnd()) {
18971  
18972 return $self->scriptObj->setError(
18973 'unexpected_keywords,_operators_or_expressions',
18974 $self->_objClass . '->parse',
18975 );
18976 }
18977  
18978 # Store the expressions, so $self->implement can retrieve them
18979 $self->ivAdd('parseDataHash', 'cmd_exp', $cmdExp);
18980 $self->ivPoke('parseDataList', @otherExpList);
18981  
18982 # Parsing complete
18983 return 1;
18984 }
18985  
18986 sub implement {
18987  
18988 # Called by LA::Line->implement directly after a call to $self->parse
18989 #
18990 # Expected arguments
18991 # (none besides $self)
18992 #
18993 # Return values
18994 # 'undef' on improper arguments or if there is an error
18995 # 1 otherwise
18996  
18997 my ($self, $check) = @_;
18998  
18999 # Local variables
19000 my (
19001 $cmdExp, $cmd, $newCmd,
19002 @otherExpList, @otherList,
19003 );
19004  
19005 # Check for improper arguments
19006 if (defined $check) {
19007  
19008 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19009 }
19010  
19011 # Retrieve the arguments stored by $self->parse
19012 $cmdExp = $self->ivShow('parseDataHash', 'cmd_exp');
19013 @otherExpList = $self->parseDataList;
19014  
19015 # Evaluate each expression
19016 $cmd = $cmdExp->evaluate();
19017 foreach my $exp (@otherExpList) {
19018  
19019 push (@otherList, $exp->evaluate());
19020 }
19021  
19022 # Interpolate the command using the (optional) arguments in @otherExpList
19023 $newCmd = $self->scriptObj->session->prepareCmd($cmd, @otherList);
19024 if (! $newCmd) {
19025  
19026 # The command couldn't be interpolated, so just send $cmd
19027 $newCmd = $cmd;
19028 }
19029  
19030 $self->scriptObj->session->worldCmd($newCmd);
19031  
19032 # Implementation complete
19033 return 1;
19034 }
19035 }
19036  
19037 { package Language::Axbasic::Statement::setalias;
19038  
19039 use strict;
19040 use warnings;
19041 use diagnostics;
19042  
19043 use Glib qw(TRUE FALSE);
19044  
19045 @Language::Axbasic::Statement::setalias::ISA = qw(
19046 Language::Axbasic
19047 Language::Axbasic::Statement
19048 );
19049  
19050 # SETALIAS expression [ , expression ]
19051  
19052 ##################
19053 # Methods
19054  
19055 sub parse {
19056  
19057 # Called by LA::Line->parse directly after a call to LA::Statement->new
19058 # when the first token in the statement is the keyword 'setalias'
19059 #
19060 # Expected arguments
19061 # (none besides $self)
19062 #
19063 # Return values
19064 # 'undef' on improper arguments or if there is an error
19065 # 1 otherwise
19066  
19067 my ($self, $check) = @_;
19068  
19069 # Check for improper arguments
19070 if (defined $check) {
19071  
19072 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19073 }
19074  
19075 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19076 # ready for $self->implement to access
19077 if (! $self->parseSetInterface()) {
19078  
19079 # ($self->scriptObj->setError has already been called)
19080 return undef;
19081 }
19082  
19083 # Parsing complete
19084 return 1;
19085 }
19086  
19087 sub implement {
19088  
19089 # Called by LA::Line->implement directly after a call to $self->parse
19090 #
19091 # Expected arguments
19092 # (none besides $self)
19093 #
19094 # Return values
19095 # 'undef' on improper arguments or if there is an error
19096 # 1 otherwise
19097  
19098 my ($self, $check) = @_;
19099  
19100 # Local variables
19101 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19102  
19103 # Check for improper arguments
19104 if (defined $check) {
19105  
19106 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19107 }
19108  
19109 # Retrieve the arguments stored by $self->parse
19110 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19111 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19112  
19113 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19114 # new script to call, ignore this statement altogether
19115 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19116  
19117 # Implementation complete. Execution resumes from the next statement
19118 return 1;
19119 }
19120  
19121 # Otherwise, evaluate the expressions
19122 $stimulus = $stimulusExp->evaluate();
19123 if (defined $newScriptExp) {
19124  
19125 $newScript = $newScriptExp->evaluate();
19126 }
19127  
19128 # Create the (dependent) alias
19129 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19130 'alias',
19131 $stimulus,
19132 $self->scriptObj->parentTask,
19133 'aliasNotifySeen',
19134 );
19135  
19136 if (defined $interfaceObj) {
19137  
19138 # Store the name of the new script to execute in the interface object
19139 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19140  
19141 # Add this alias to the list of interfaces created during the execution of the Axbasic
19142 # script
19143 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19144 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19145  
19146 } else {
19147  
19148 # Store the fact that creation of the interface failed
19149 $self->scriptObj->set_depInterfaceName(undef);
19150 }
19151  
19152 # Implementation complete
19153 return 1;
19154 }
19155 }
19156  
19157 { package Language::Axbasic::Statement::setgauge;
19158  
19159 use strict;
19160 use warnings;
19161 use diagnostics;
19162  
19163 use Glib qw(TRUE FALSE);
19164  
19165 @Language::Axbasic::Statement::setgauge::ISA = qw(
19166 Language::Axbasic
19167 Language::Axbasic::Statement
19168 );
19169  
19170 # SETGAUGE expression , expression , expression
19171  
19172 ##################
19173 # Methods
19174  
19175 sub parse {
19176  
19177 # Called by LA::Line->parse directly after a call to LA::Statement->new
19178 #
19179 # Expected arguments
19180 # (none besides $self)
19181 #
19182 # Return values
19183 # 'undef' on improper arguments or if there is an error
19184 # 1 otherwise
19185  
19186 my ($self, $check) = @_;
19187  
19188 # Local variables
19189 my ($numberExp, $valExp, $maxValExp);
19190  
19191 # Check for improper arguments
19192 if (defined $check) {
19193  
19194 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19195 }
19196  
19197 # Convert the arguments into expressions
19198 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
19199 $self->scriptObj,
19200 $self->tokenGroupObj,
19201 );
19202  
19203 if (! defined $numberExp) {
19204  
19205 return $self->scriptObj->setError(
19206 'missing_or_illegal_expression',
19207 $self->_objClass . '->parse',
19208 );
19209 }
19210  
19211 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19212  
19213 return $self->scriptObj->setError(
19214 'syntax_error',
19215 $self->_objClass . '->parse',
19216 );
19217 }
19218  
19219 $valExp = Language::Axbasic::Expression::Arithmetic->new(
19220 $self->scriptObj,
19221 $self->tokenGroupObj,
19222 );
19223  
19224 if (! defined $valExp) {
19225  
19226 return $self->scriptObj->setError(
19227 'missing_or_illegal_expression',
19228 $self->_objClass . '->parse',
19229 );
19230 }
19231  
19232 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19233  
19234 return $self->scriptObj->setError(
19235 'syntax_error',
19236 $self->_objClass . '->parse',
19237 );
19238 }
19239  
19240 $maxValExp = Language::Axbasic::Expression::Arithmetic->new(
19241 $self->scriptObj,
19242 $self->tokenGroupObj,
19243 );
19244  
19245 if (! defined $maxValExp) {
19246  
19247 return $self->scriptObj->setError(
19248 'missing_or_illegal_expression',
19249 $self->_objClass . '->parse',
19250 );
19251 }
19252  
19253 # Check that nothing follows the expressions
19254 if (! $self->tokenGroupObj->testStatementEnd()) {
19255  
19256 return $self->scriptObj->setError(
19257 'unexpected_keywords,_operators_or_expressions',
19258 $self->_objClass . '->parse',
19259 );
19260 }
19261  
19262 # Store the expressions, so $self->implement can retrieve them
19263 $self->ivAdd('parseDataHash', 'number', $numberExp);
19264 $self->ivAdd('parseDataHash', 'val', $valExp);
19265 $self->ivAdd('parseDataHash', 'max_val', $maxValExp);
19266  
19267 # Parsing complete
19268 return 1;
19269 }
19270  
19271 sub implement {
19272  
19273 # Called by LA::Line->implement directly after a call to $self->parse
19274 #
19275 # Expected arguments
19276 # (none besides $self)
19277 #
19278 # Return values
19279 # 'undef' on improper arguments or if there is an error
19280 # 1 otherwise
19281  
19282 my ($self, $check) = @_;
19283  
19284 # Local variables
19285 my ($numberExp, $valExp, $maxValExp, $number, $val, $maxVal);
19286  
19287 # Check for improper arguments
19288 if (defined $check) {
19289  
19290 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19291 }
19292  
19293 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
19294 if (! $self->scriptObj->parentTask) {
19295  
19296 # Implementation complete. Execution resumes from the next statement
19297 return 1;
19298 }
19299  
19300 # Retrieve the arguments stored by $self->parse
19301 $numberExp = $self->ivShow('parseDataHash', 'number');
19302 $valExp = $self->ivShow('parseDataHash', 'val');
19303 $maxValExp = $self->ivShow('parseDataHash', 'max_val');
19304  
19305 # Evaluate each expression
19306 $number = $numberExp->evaluate();
19307 $val = $valExp->evaluate();
19308 $maxVal = $maxValExp->evaluate();
19309  
19310 # $num must be an integer, >= 0 (but it doesn't need to be a gauge number which has
19311 # actually been created with an ADDGAUGE or ADDCONGAUGE statement)
19312 if ($number =~ m/\D/ || $number < 0) {
19313  
19314 return $self->scriptObj->setError(
19315 'invalid_gauge_number',
19316 $self->_objClass . '->implement',
19317 );
19318 }
19319  
19320 # $val and $maxVal must both be decimal numbers, otherwise we'll have to change them to
19321 # 'undef'
19322 if (! ($val =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19323  
19324 $val = undef;
19325 }
19326  
19327 if (! ($maxVal =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19328  
19329 $maxVal = undef;
19330 }
19331  
19332 # Tell the Script task to set the gauge's value
19333 $self->scriptObj->parentTask->setGauge($number, $val, $maxVal);
19334  
19335 # Implementation complete
19336 return 1;
19337 }
19338 }
19339  
19340 { package Language::Axbasic::Statement::sethook;
19341  
19342 use strict;
19343 use warnings;
19344 use diagnostics;
19345  
19346 use Glib qw(TRUE FALSE);
19347  
19348 @Language::Axbasic::Statement::sethook::ISA = qw(
19349 Language::Axbasic
19350 Language::Axbasic::Statement
19351 );
19352  
19353 # SETHOOK expression [ , expression ]
19354  
19355 ##################
19356 # Methods
19357  
19358 sub parse {
19359  
19360 # Called by LA::Line->parse directly after a call to LA::Statement->new
19361 # when the first token in the statement is the keyword 'sethook'
19362 #
19363 # Expected arguments
19364 # (none besides $self)
19365 #
19366 # Return values
19367 # 'undef' on improper arguments or if there is an error
19368 # 1 otherwise
19369  
19370 my ($self, $check) = @_;
19371  
19372 # Check for improper arguments
19373 if (defined $check) {
19374  
19375 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19376 }
19377  
19378 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19379 # ready for $self->implement to access
19380 if (! $self->parseSetInterface()) {
19381  
19382 # ($self->scriptObj->setError has already been called)
19383 return undef;
19384 }
19385  
19386 # Parsing complete
19387 return 1;
19388 }
19389  
19390 sub implement {
19391  
19392 # Called by LA::Line->implement directly after a call to $self->parse
19393 #
19394 # Expected arguments
19395 # (none besides $self)
19396 #
19397 # Return values
19398 # 'undef' on improper arguments or if there is an error
19399 # 1 otherwise
19400  
19401 my ($self, $check) = @_;
19402  
19403 # Local variables
19404 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19405  
19406 # Check for improper arguments
19407 if (defined $check) {
19408  
19409 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19410 }
19411  
19412 # Retrieve the arguments stored by $self->parse
19413 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19414 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19415  
19416 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19417 # new script to call, ignore this statement altogether
19418 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19419  
19420 # Implementation complete. Execution resumes from the next statement
19421 return 1;
19422 }
19423  
19424 # Otherwise, evaluate the expressions
19425 $stimulus = $stimulusExp->evaluate();
19426 if (defined $newScriptExp) {
19427  
19428 $newScript = $newScriptExp->evaluate();
19429 }
19430  
19431 # Create the (dependent) hook
19432 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19433 'hook',
19434 $stimulus,
19435 $self->scriptObj->parentTask,
19436 'hookNotifySeen',
19437 );
19438  
19439 if (defined $interfaceObj) {
19440  
19441 # Store the name of the new script to execute in the interface object
19442 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19443  
19444 # Add this hook to the list of interfaces created during the execution of the Axbasic
19445 # script
19446 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19447 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19448  
19449 } else {
19450  
19451 # Store the fact that creation of the interface failed
19452 $self->scriptObj->set_depInterfaceName(undef);
19453 }
19454  
19455 # Implementation complete
19456 return 1;
19457 }
19458 }
19459  
19460 { package Language::Axbasic::Statement::setmacro;
19461  
19462 use strict;
19463 use warnings;
19464 use diagnostics;
19465  
19466 use Glib qw(TRUE FALSE);
19467  
19468 @Language::Axbasic::Statement::setmacro::ISA = qw(
19469 Language::Axbasic
19470 Language::Axbasic::Statement
19471 );
19472  
19473 # SETMACRO expression [ , expression ]
19474  
19475 ##################
19476 # Methods
19477  
19478 sub parse {
19479  
19480 # Called by LA::Line->parse directly after a call to LA::Statement->new
19481 # when the first token in the statement is the keyword 'setmacro'
19482 #
19483 # Expected arguments
19484 # (none besides $self)
19485 #
19486 # Return values
19487 # 'undef' on improper arguments or if there is an error
19488 # 1 otherwise
19489  
19490 my ($self, $check) = @_;
19491  
19492 # Check for improper arguments
19493 if (defined $check) {
19494  
19495 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19496 }
19497  
19498 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19499 # ready for $self->implement to access
19500 if (! $self->parseSetInterface()) {
19501  
19502 # ($self->scriptObj->setError has already been called)
19503 return undef;
19504 }
19505  
19506 # Parsing complete
19507 return 1;
19508 }
19509  
19510 sub implement {
19511  
19512 # Called by LA::Line->implement directly after a call to $self->parse
19513 #
19514 # Expected arguments
19515 # (none besides $self)
19516 #
19517 # Return values
19518 # 'undef' on improper arguments or if there is an error
19519 # 1 otherwise
19520  
19521 my ($self, $check) = @_;
19522  
19523 # Local variables
19524 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19525  
19526 # Check for improper arguments
19527 if (defined $check) {
19528  
19529 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19530 }
19531  
19532 # Retrieve the arguments stored by $self->parse
19533 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19534 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19535  
19536 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19537 # new script to call, ignore this statement altogether
19538 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19539  
19540 # Implementation complete. Execution resumes from the next statement
19541 return 1;
19542 }
19543  
19544 # Otherwise, evaluate the expressions
19545 $stimulus = $stimulusExp->evaluate();
19546 if (defined $newScriptExp) {
19547  
19548 $newScript = $newScriptExp->evaluate();
19549 }
19550  
19551 # Create the (dependent) macro
19552 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19553 'macro',
19554 $stimulus,
19555 $self->scriptObj->parentTask,
19556 'macroNotifySeen',
19557 );
19558  
19559 if (defined $interfaceObj) {
19560  
19561 # Store the name of the new script to execute in the interface object
19562 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19563  
19564 # Add this macro to the list of interfaces created during the execution of the Axbasic
19565 # script
19566 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19567 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19568  
19569 } else {
19570  
19571 # Store the fact that creation of the interface failed
19572 $self->scriptObj->set_depInterfaceName(undef);
19573 }
19574  
19575 # Implementation complete
19576 return 1;
19577 }
19578 }
19579  
19580 { package Language::Axbasic::Statement::setstatus;
19581  
19582 use strict;
19583 use warnings;
19584 use diagnostics;
19585  
19586 use Glib qw(TRUE FALSE);
19587  
19588 @Language::Axbasic::Statement::setstatus::ISA = qw(
19589 Language::Axbasic
19590 Language::Axbasic::Statement
19591 );
19592  
19593 # SETSTATUS expression , expression , expression
19594  
19595 ##################
19596 # Methods
19597  
19598 sub parse {
19599  
19600 # Called by LA::Line->parse directly after a call to LA::Statement->new
19601 #
19602 # Expected arguments
19603 # (none besides $self)
19604 #
19605 # Return values
19606 # 'undef' on improper arguments or if there is an error
19607 # 1 otherwise
19608  
19609 my ($self, $check) = @_;
19610  
19611 # Local variables
19612 my ($numberExp, $valExp, $maxValExp);
19613  
19614 # Check for improper arguments
19615 if (defined $check) {
19616  
19617 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19618 }
19619  
19620 # Convert the arguments into expressions
19621 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
19622 $self->scriptObj,
19623 $self->tokenGroupObj,
19624 );
19625  
19626 if (! defined $numberExp) {
19627  
19628 return $self->scriptObj->setError(
19629 'missing_or_illegal_expression',
19630 $self->_objClass . '->parse',
19631 );
19632 }
19633  
19634 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19635  
19636 return $self->scriptObj->setError(
19637 'syntax_error',
19638 $self->_objClass . '->parse',
19639 );
19640 }
19641  
19642 $valExp = Language::Axbasic::Expression::Arithmetic->new(
19643 $self->scriptObj,
19644 $self->tokenGroupObj,
19645 );
19646  
19647 if (! defined $valExp) {
19648  
19649 return $self->scriptObj->setError(
19650 'missing_or_illegal_expression',
19651 $self->_objClass . '->parse',
19652 );
19653 }
19654  
19655 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19656  
19657 return $self->scriptObj->setError(
19658 'syntax_error',
19659 $self->_objClass . '->parse',
19660 );
19661 }
19662  
19663 $maxValExp = Language::Axbasic::Expression::Arithmetic->new(
19664 $self->scriptObj,
19665 $self->tokenGroupObj,
19666 );
19667  
19668 if (! defined $maxValExp) {
19669  
19670 return $self->scriptObj->setError(
19671 'missing_or_illegal_expression',
19672 $self->_objClass . '->parse',
19673 );
19674 }
19675  
19676 # Check that nothing follows the expressions
19677 if (! $self->tokenGroupObj->testStatementEnd()) {
19678  
19679 return $self->scriptObj->setError(
19680 'unexpected_keywords,_operators_or_expressions',
19681 $self->_objClass . '->parse',
19682 );
19683 }
19684  
19685 # Store the expressions, so $self->implement can retrieve them
19686 $self->ivAdd('parseDataHash', 'number', $numberExp);
19687 $self->ivAdd('parseDataHash', 'val', $valExp);
19688 $self->ivAdd('parseDataHash', 'max_val', $maxValExp);
19689  
19690 # Parsing complete
19691 return 1;
19692 }
19693  
19694 sub implement {
19695  
19696 # Called by LA::Line->implement directly after a call to $self->parse
19697 #
19698 # Expected arguments
19699 # (none besides $self)
19700 #
19701 # Return values
19702 # 'undef' on improper arguments or if there is an error
19703 # 1 otherwise
19704  
19705 my ($self, $check) = @_;
19706  
19707 # Local variables
19708 my ($numberExp, $valExp, $maxValExp, $number, $val, $maxVal);
19709  
19710 # Check for improper arguments
19711 if (defined $check) {
19712  
19713 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19714 }
19715  
19716 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
19717 if (! $self->scriptObj->parentTask) {
19718  
19719 # Implementation complete. Execution resumes from the next statement
19720 return 1;
19721 }
19722  
19723 # Retrieve the arguments stored by $self->parse
19724 $numberExp = $self->ivShow('parseDataHash', 'number');
19725 $valExp = $self->ivShow('parseDataHash', 'val');
19726 $maxValExp = $self->ivShow('parseDataHash', 'max_val');
19727  
19728 # Evaluate each expression
19729 $number = $numberExp->evaluate();
19730 $val = $valExp->evaluate();
19731 $maxVal = $maxValExp->evaluate();
19732  
19733 # $num must be an integer, >= 0 (but it doesn't need to be a status bar number which has
19734 # actually been created with an ADDSTATUS or ADDCONSTATUS statement)
19735 if ($number =~ m/\D/ || $number < 0) {
19736  
19737 return $self->scriptObj->setError(
19738 'invalid_status_bar_number',
19739 $self->_objClass . '->implement',
19740 );
19741 }
19742  
19743 # $val and $maxVal must both be decimal numbers, otherwise we'll have to change them to
19744 # 'undef'
19745 if (! ($val =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19746  
19747 $val = undef;
19748 }
19749  
19750 if (! ($maxVal =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19751  
19752 $maxVal = undef;
19753 }
19754  
19755 # Tell the Script task to set the status bar's text
19756 $self->scriptObj->parentTask->setStatusBar($number, $val, $maxVal);
19757  
19758 # Implementation complete
19759 return 1;
19760 }
19761 }
19762  
19763 { package Language::Axbasic::Statement::settimer;
19764  
19765 use strict;
19766 use warnings;
19767 use diagnostics;
19768  
19769 use Glib qw(TRUE FALSE);
19770  
19771 @Language::Axbasic::Statement::settimer::ISA = qw(
19772 Language::Axbasic
19773 Language::Axbasic::Statement
19774 );
19775  
19776 # SETTIMER expression [ , expression ]
19777  
19778 ##################
19779 # Methods
19780  
19781 sub parse {
19782  
19783 # Called by LA::Line->parse directly after a call to LA::Statement->new
19784 # when the first token in the statement is the keyword 'settimer'
19785 #
19786 # Expected arguments
19787 # (none besides $self)
19788 #
19789 # Return values
19790 # 'undef' on improper arguments or if there is an error
19791 # 1 otherwise
19792  
19793 my ($self, $check) = @_;
19794  
19795 # Check for improper arguments
19796 if (defined $check) {
19797  
19798 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19799 }
19800  
19801 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19802 # ready for $self->implement to access
19803 if (! $self->parseSetInterface()) {
19804  
19805 # ($self->scriptObj->setError has already been called)
19806 return undef;
19807 }
19808  
19809 # Parsing complete
19810 return 1;
19811 }
19812  
19813 sub implement {
19814  
19815 # Called by LA::Line->implement directly after a call to $self->parse
19816 #
19817 # Expected arguments
19818 # (none besides $self)
19819 #
19820 # Return values
19821 # 'undef' on improper arguments or if there is an error
19822 # 1 otherwise
19823  
19824 my ($self, $check) = @_;
19825  
19826 # Local variables
19827 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19828  
19829 # Check for improper arguments
19830 if (defined $check) {
19831  
19832 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19833 }
19834  
19835 # Retrieve the arguments stored by $self->parse
19836 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19837 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19838  
19839 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19840 # new script to call, ignore this statement altogether
19841 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19842  
19843 # Implementation complete. Execution resumes from the next statement
19844 return 1;
19845 }
19846  
19847 # Otherwise, evaluate the expressions
19848 $stimulus = $stimulusExp->evaluate();
19849 if (defined $newScriptExp) {
19850  
19851 $newScript = $newScriptExp->evaluate();
19852 }
19853  
19854 # Create the (dependent) timer
19855 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19856 'timer',
19857 $stimulus,
19858 $self->scriptObj->parentTask,
19859 'timerNotifySeen',
19860 );
19861  
19862 if (defined $interfaceObj) {
19863  
19864 # Store the name of the new script to execute in the interface object
19865 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19866  
19867 # Add this timer to the list of interfaces created during the execution of the Axbasic
19868 # script
19869 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19870 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19871  
19872 } else {
19873  
19874 # Store the fact that creation of the interface failed
19875 $self->scriptObj->set_depInterfaceName(undef);
19876 }
19877  
19878 # Implementation complete
19879 return 1;
19880 }
19881 }
19882  
19883 { package Language::Axbasic::Statement::settrig;
19884  
19885 use strict;
19886 use warnings;
19887 use diagnostics;
19888  
19889 use Glib qw(TRUE FALSE);
19890  
19891 @Language::Axbasic::Statement::settrig::ISA = qw(
19892 Language::Axbasic
19893 Language::Axbasic::Statement
19894 );
19895  
19896 # SETTRIG expression [ , expression ]
19897  
19898 ##################
19899 # Methods
19900  
19901 sub parse {
19902  
19903 # Called by LA::Line->parse directly after a call to LA::Statement->new
19904 # when the first token in the statement is the keyword 'settrig'
19905 #
19906 # Expected arguments
19907 # (none besides $self)
19908 #
19909 # Return values
19910 # 'undef' on improper arguments or if there is an error
19911 # 1 otherwise
19912  
19913 my ($self, $check) = @_;
19914  
19915 # Check for improper arguments
19916 if (defined $check) {
19917  
19918 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19919 }
19920  
19921 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19922 # ready for $self->implement to access
19923 if (! $self->parseSetInterface()) {
19924  
19925 # ($self->scriptObj->setError has already been called)
19926 return undef;
19927 }
19928  
19929 # Parsing complete
19930 return 1;
19931 }
19932  
19933 sub implement {
19934  
19935 # Called by LA::Line->implement directly after a call to $self->parse
19936 #
19937 # Expected arguments
19938 # (none besides $self)
19939 #
19940 # Return values
19941 # 'undef' on improper arguments or if there is an error
19942 # 1 otherwise
19943  
19944 my ($self, $check) = @_;
19945  
19946 # Local variables
19947 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19948  
19949 # Check for improper arguments
19950 if (defined $check) {
19951  
19952 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19953 }
19954  
19955 # Retrieve the arguments stored by $self->parse
19956 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19957 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19958  
19959 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19960 # new script to call, ignore this statement altogether
19961 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19962  
19963 # Implementation complete. Execution resumes from the next statement
19964 return 1;
19965 }
19966  
19967 # Otherwise, evaluate the expressions
19968 $stimulus = $stimulusExp->evaluate();
19969 if (defined $newScriptExp) {
19970  
19971 $newScript = $newScriptExp->evaluate();
19972 }
19973  
19974 # Create the (dependent) trigger
19975 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19976 'trigger',
19977 $stimulus,
19978 $self->scriptObj->parentTask,
19979 'triggerNotifySeen',
19980 );
19981  
19982 if (defined $interfaceObj) {
19983  
19984 # Store the name of the new script to execute in the interface object
19985 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19986  
19987 # Add this trigger to the list of interfaces created during the execution of the Axbasic
19988 # script
19989 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19990 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19991  
19992 } else {
19993  
19994 # Store the fact that creation of the interface failed
19995 $self->scriptObj->set_depInterfaceName(undef);
19996 }
19997  
19998 # Implementation complete
19999 return 1;
20000 }
20001 }
20002  
20003 { package Language::Axbasic::Statement::shift;
20004  
20005 use strict;
20006 use warnings;
20007 use diagnostics;
20008  
20009 use Glib qw(TRUE FALSE);
20010  
20011 @Language::Axbasic::Statement::shift::ISA = qw(
20012 Language::Axbasic
20013 Language::Axbasic::Statement
20014 );
20015  
20016 # SHIFT array-name [ , variable-name ]
20017  
20018 ##################
20019 # Methods
20020  
20021 sub parse {
20022  
20023 # Called by LA::Line->parse directly after a call to LA::Statement->new
20024 #
20025 # Expected arguments
20026 # (none besides $self)
20027 #
20028 # Return values
20029 # 'undef' on improper arguments or if there is an error
20030 # 1 otherwise
20031  
20032 my ($self, $check) = @_;
20033  
20034 # Local variables
20035 my ($arrayExp, $scalarExp);
20036  
20037 # Check for improper arguments
20038 if (defined $check) {
20039  
20040 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20041 }
20042  
20043 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20044 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20045 # that created by
20046 # DIM var (10)
20047 # ...by a variable name that looks like a scalar, i.e.
20048 # SORT var
20049 $self->scriptObj->set_declareMode('simple');
20050  
20051 # Get the array variable name
20052 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
20053 $self->scriptObj,
20054 $self->tokenGroupObj,
20055 );
20056  
20057 if (! defined $arrayExp) {
20058  
20059 return $self->scriptObj->setError(
20060 'missing_or_illegal_array_variable',
20061 $self->_objClass . '->parse',
20062 );
20063 }
20064  
20065 # Reset the temporary IV
20066 $self->scriptObj->set_declareMode('default');
20067  
20068 # Extract the optional scalar variable name
20069 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
20070  
20071 $scalarExp = Language::Axbasic::Expression::Lvalue->new(
20072 $self->scriptObj,
20073 $self->tokenGroupObj,
20074 );
20075  
20076 if (! defined $scalarExp) {
20077  
20078 return $self->scriptObj->setError(
20079 'missing_or_illegal_expression',
20080 $self->_objClass . '->parse',
20081 );
20082 }
20083 }
20084  
20085 if (! $self->tokenGroupObj->testStatementEnd()) {
20086  
20087 return $self->scriptObj->setError(
20088 'unexpected_keywords,_operators_or_expressions',
20089 $self->_objClass . '->parse',
20090 );
20091 }
20092  
20093 # Save the expression objects so $self->implement can use them, if it is called
20094 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
20095 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
20096  
20097 # Parsing complete
20098 return 1;
20099 }
20100  
20101 sub implement {
20102  
20103 # Called by LA::Line->implement directly after a call to $self->parse
20104 #
20105 # Expected arguments
20106 # (none besides $self)
20107 #
20108 # Return values
20109 # 'undef' on improper arguments
20110 # 1 otherwise
20111  
20112 my ($self, $check) = @_;
20113  
20114 # Local variables
20115 my ($arrayExp, $scalarExp, $removedVar);
20116  
20117 # Check for improper arguments
20118 if (defined $check) {
20119  
20120 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20121 }
20122  
20123 # Retrieve the variables stored by ->parse
20124 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
20125 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
20126  
20127 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be shifted. Multi-dimensional arrays
20128 # (e.g. DIM var (5, 5, 2) ) can't be shifted
20129 if ($arrayExp->varObj->dimCount > 1) {
20130  
20131 return $self->scriptObj->setError(
20132 'SHIFT_statement_cannot_operate_on_multi-dimensional_array',
20133 $self->_objClass . '->implement',
20134 );
20135 }
20136  
20137 # Cannot use a numeric array with a string scalar, and vice-versa
20138 if (
20139 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp->varObj) =~ m/Numeric/))
20140 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp->varObj) =~ m/String/))
20141 ) {
20142 return $self->scriptObj->setError(
20143 'type_mismatch_error',
20144 $self->_objClass . '->implement',
20145 );
20146 }
20147  
20148 # Shift the stack, and use the shifted value to set the variable. (If the array is empty, we
20149 # get an empty string or zero, as appropriate)
20150 $removedVar = $arrayExp->varObj->doShift();
20151 if ($removedVar) {
20152  
20153 $scalarExp->varObj->set($removedVar->value);
20154 }
20155  
20156 # Implementation complete
20157 return 1;
20158 }
20159 }
20160  
20161 { package Language::Axbasic::Statement::skipiface;
20162  
20163 use strict;
20164 use warnings;
20165 use diagnostics;
20166  
20167 use Glib qw(TRUE FALSE);
20168  
20169 @Language::Axbasic::Statement::skipiface::ISA = qw(
20170 Language::Axbasic
20171 Language::Axbasic::Statement
20172 );
20173  
20174 # SKIPIFACE
20175  
20176 ##################
20177 # Methods
20178  
20179 sub parse {
20180  
20181 # Called by LA::Line->parse directly after a call to LA::Statement->new
20182 #
20183 # Expected arguments
20184 # (none besides $self)
20185 #
20186 # Return values
20187 # 'undef' on improper arguments or if there is an error
20188 # 1 otherwise
20189  
20190 my ($self, $check) = @_;
20191  
20192 # Local variables
20193 my ($subObj, $whileStatement);
20194  
20195 # Check for improper arguments
20196 if (defined $check) {
20197  
20198 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20199 }
20200  
20201 # SKIPIFACE statements always appear on their own
20202 if (! $self->tokenGroupObj->testStatementEnd()) {
20203  
20204 return $self->scriptObj->setError(
20205 'unexpected_keywords,_operators_or_expressions',
20206 $self->_objClass . '->parse',
20207 );
20208 }
20209  
20210 # Parsing complete
20211 return 1;
20212 }
20213  
20214 sub implement {
20215  
20216 # Called by LA::Line->implement directly after a call to $self->parse
20217 #
20218 # Expected arguments
20219 # (none besides $self)
20220 #
20221 # Return values
20222 # 'undef' on improper arguments or if there is an error
20223 # 1 otherwise
20224  
20225 my ($self, $check) = @_;
20226  
20227 # Local variables
20228 my $count;
20229  
20230 # Check for improper arguments
20231 if (defined $check) {
20232  
20233 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20234 }
20235  
20236 # Get the size of the notification list
20237 $count = $self->scriptObj->ivNumber('notificationList');
20238  
20239 # Do nothing, if the interface notification list is empty or if it contains only one
20240 # notification
20241 if ($count < 2) {
20242  
20243 # Implementation complete
20244 return 1;
20245  
20246 } else {
20247  
20248 if ($self->scriptObj->currentNotification == ($count - 1)) {
20249  
20250 # At the end of the list
20251 $self->scriptObj->set_currentNotification(0);
20252  
20253 } else {
20254  
20255 # Move along one position
20256 $self->scriptObj->inc_currentNotification();
20257 }
20258  
20259 # Implementation complete
20260 return 1;
20261 }
20262 }
20263 }
20264  
20265 { package Language::Axbasic::Statement::sort;
20266  
20267 use strict;
20268 use warnings;
20269 use diagnostics;
20270  
20271 use Glib qw(TRUE FALSE);
20272  
20273 @Language::Axbasic::Statement::sort::ISA = qw(
20274 Language::Axbasic
20275 Language::Axbasic::Statement
20276 );
20277  
20278 # SORT variable-name
20279  
20280 ##################
20281 # Methods
20282  
20283 sub parse {
20284  
20285 # Called by LA::Line->parse directly after a call to LA::Statement->new
20286 #
20287 # Expected arguments
20288 # (none besides $self)
20289 #
20290 # Return values
20291 # 'undef' on improper arguments or if there is an error
20292 # 1 otherwise
20293  
20294 my ($self, $check) = @_;
20295  
20296 # Local variables
20297 my $expression;
20298  
20299 # Check for improper arguments
20300 if (defined $check) {
20301  
20302 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20303 }
20304  
20305 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20306 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20307 # that created by
20308 # DIM var (10)
20309 # ...by a variable name that looks like a scalar, i.e.
20310 # SORT var
20311 $self->scriptObj->set_declareMode('simple');
20312  
20313 # Get the variable name
20314 $expression = Language::Axbasic::Expression::Lvalue->new(
20315 $self->scriptObj,
20316 $self->tokenGroupObj,
20317 );
20318  
20319 if (! defined $expression) {
20320  
20321 return $self->scriptObj->setError(
20322 'missing_or_illegal_variable',
20323 $self->_objClass . '->parse',
20324 );
20325 }
20326  
20327 # Reset the temporary IV
20328 $self->scriptObj->set_declareMode('default');
20329  
20330 if (! $self->tokenGroupObj->testStatementEnd()) {
20331  
20332 return $self->scriptObj->setError(
20333 'unexpected_keywords,_operators_or_expressions',
20334 $self->_objClass . '->parse',
20335 );
20336 }
20337  
20338 # Store the variable for ->implement to use
20339 $self->ivAdd('parseDataHash', 'expression', $expression);
20340  
20341 # Parsing complete
20342 return 1;
20343 }
20344  
20345 sub implement {
20346  
20347 # Called by LA::Line->implement directly after a call to $self->parse
20348 #
20349 # Expected arguments
20350 # (none besides $self)
20351 #
20352 # Return values
20353 # 'undef' on improper arguments or if there is an error
20354 # 1 otherwise
20355  
20356 my ($self, $check) = @_;
20357  
20358 # Local variables
20359 my (
20360 $expression, $varObj, $lowerBound,
20361 @list, @sortedList,
20362 );
20363  
20364 # Check for improper arguments
20365 if (defined $check) {
20366  
20367 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20368 }
20369  
20370 # Retrieve the array variable to sort
20371 $expression = $self->ivShow('parseDataHash', 'expression');
20372 $varObj = $expression->varObj;
20373  
20374 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20375 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20376 if ($varObj->dimCount > 1) {
20377  
20378 return $self->scriptObj->setError(
20379 'SORT_statement_cannot_operate_on_multi-dimensional_array',
20380 $self->_objClass . '->implement',
20381 );
20382 }
20383  
20384 # Import the values stored in the array, sort them, and store them back in the array
20385 @list = $varObj->cellList;
20386  
20387 # Take account of the first item in ->cellList, which is the lower bound
20388 $lowerBound = shift @list;
20389  
20390 if (ref($varObj) =~ m/Numeric/) {
20391  
20392 # It's a numeric array
20393 @sortedList = sort {$a->value <=> $b->value} (@list);
20394  
20395 } else {
20396  
20397 # It's a string array
20398 @sortedList = sort {$a->value cmp $b->value} (@list);
20399 }
20400  
20401 # Restore the lower bound to its previous place
20402 unshift(@sortedList, $lowerBound);
20403 $varObj->ivPoke('cellList', @sortedList);
20404  
20405 # Implementation complete
20406 return 1;
20407 }
20408 }
20409  
20410 { package Language::Axbasic::Statement::sortcase;
20411  
20412 use strict;
20413 use warnings;
20414 use diagnostics;
20415  
20416 use Glib qw(TRUE FALSE);
20417  
20418 @Language::Axbasic::Statement::sortcase::ISA = qw(
20419 Language::Axbasic
20420 Language::Axbasic::Statement
20421 );
20422  
20423 # SORTCASE variable-name
20424  
20425 ##################
20426 # Methods
20427  
20428 sub parse {
20429  
20430 # Called by LA::Line->parse directly after a call to LA::Statement->new
20431 #
20432 # Expected arguments
20433 # (none besides $self)
20434 #
20435 # Return values
20436 # 'undef' on improper arguments or if there is an error
20437 # 1 otherwise
20438  
20439 my ($self, $check) = @_;
20440  
20441 # Local variables
20442 my $expression;
20443  
20444 # Check for improper arguments
20445 if (defined $check) {
20446  
20447 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20448 }
20449  
20450 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20451 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20452 # that created by
20453 # DIM var (10)
20454 # ...by a variable name that looks like a scalar, i.e.
20455 # SORT var
20456 $self->scriptObj->set_declareMode('simple');
20457  
20458 # Get the variable name
20459 $expression = Language::Axbasic::Expression::Lvalue->new(
20460 $self->scriptObj,
20461 $self->tokenGroupObj,
20462 );
20463  
20464 if (! defined $expression) {
20465  
20466 return $self->scriptObj->setError(
20467 'missing_or_illegal_variable',
20468 $self->_objClass . '->parse',
20469 );
20470 }
20471  
20472 # Reset the temporary IV
20473 $self->scriptObj->set_declareMode('default');
20474  
20475 if (! $self->tokenGroupObj->testStatementEnd()) {
20476  
20477 return $self->scriptObj->setError(
20478 'unexpected_keywords,_operators_or_expressions',
20479 $self->_objClass . '->parse',
20480 );
20481 }
20482  
20483 # Store the variable for ->implement to use
20484 $self->ivAdd('parseDataHash', 'expression', $expression);
20485  
20486 # Parsing complete
20487 return 1;
20488 }
20489  
20490 sub implement {
20491  
20492 # Called by LA::Line->implement directly after a call to $self->parse
20493 #
20494 # Expected arguments
20495 # (none besides $self)
20496 #
20497 # Return values
20498 # 'undef' on improper arguments or if there is an error
20499 # 1 otherwise
20500  
20501 my ($self, $check) = @_;
20502  
20503 # Local variables
20504 my (
20505 $expression, $varObj, $lowerBound,
20506 @list, @sortedList,
20507 );
20508  
20509 # Check for improper arguments
20510 if (defined $check) {
20511  
20512 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20513 }
20514  
20515 # Retrieve the array variable to sort
20516 $expression = $self->ivShow('parseDataHash', 'expression');
20517 $varObj = $expression->varObj;
20518  
20519 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20520 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20521 if ($varObj->dimCount > 1) {
20522  
20523 return $self->scriptObj->setError(
20524 'SORTCASE_statement_cannot_operate_on_multi-dimensional_array',
20525 $self->_objClass . '->implement',
20526 );
20527 }
20528  
20529 # Import the values stored in the array, sort them, and store them back in the array
20530 @list = $varObj->cellList;
20531  
20532 # Take account of the first item in ->cellList, which is the lower bound
20533 $lowerBound = shift @list;
20534  
20535 if (ref($varObj) =~ m/Numeric/) {
20536  
20537 # It's a numeric array
20538 @sortedList = sort {$a->value <=> $b->value} (@list);
20539  
20540 } else {
20541  
20542 # It's a string array
20543 @sortedList = sort {lc($a->value) cmp ($b->value)} (@list);
20544 }
20545  
20546 # Restore the lower bound to its previous place
20547 unshift(@sortedList, $lowerBound);
20548 $varObj->ivPoke('cellList', @sortedList);
20549  
20550 # Implementation complete
20551 return 1;
20552 }
20553 }
20554  
20555 { package Language::Axbasic::Statement::sortcaser;
20556  
20557 use strict;
20558 use warnings;
20559 use diagnostics;
20560  
20561 use Glib qw(TRUE FALSE);
20562  
20563 @Language::Axbasic::Statement::sortcaser::ISA = qw(
20564 Language::Axbasic
20565 Language::Axbasic::Statement
20566 );
20567  
20568 # SORTCASER variable-name
20569  
20570 ##################
20571 # Methods
20572  
20573 sub parse {
20574  
20575 # Called by LA::Line->parse directly after a call to LA::Statement->new
20576 #
20577 # Expected arguments
20578 # (none besides $self)
20579 #
20580 # Return values
20581 # 'undef' on improper arguments or if there is an error
20582 # 1 otherwise
20583  
20584 my ($self, $check) = @_;
20585  
20586 # Local variables
20587 my $expression;
20588  
20589 # Check for improper arguments
20590 if (defined $check) {
20591  
20592 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20593 }
20594  
20595 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20596 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20597 # that created by
20598 # DIM var (10)
20599 # ...by a variable name that looks like a scalar, i.e.
20600 # SORT var
20601 $self->scriptObj->set_declareMode('simple');
20602  
20603 # Get the variable name
20604 $expression = Language::Axbasic::Expression::Lvalue->new(
20605 $self->scriptObj,
20606 $self->tokenGroupObj,
20607 );
20608  
20609 if (! defined $expression) {
20610  
20611 return $self->scriptObj->setError(
20612 'missing_or_illegal_variable',
20613 $self->_objClass . '->parse',
20614 );
20615 }
20616  
20617 # Reset the temporary IV
20618 $self->scriptObj->set_declareMode('default');
20619  
20620 if (! $self->tokenGroupObj->testStatementEnd()) {
20621  
20622 return $self->scriptObj->setError(
20623 'unexpected_keywords,_operators_or_expressions',
20624 $self->_objClass . '->parse',
20625 );
20626 }
20627  
20628 # Store the variable for ->implement to use
20629 $self->ivAdd('parseDataHash', 'expression', $expression);
20630  
20631 # Parsing complete
20632 return 1;
20633 }
20634  
20635 sub implement {
20636  
20637 # Called by LA::Line->implement directly after a call to $self->parse
20638 #
20639 # Expected arguments
20640 # (none besides $self)
20641 #
20642 # Return values
20643 # 'undef' on improper arguments or if there is an error
20644 # 1 otherwise
20645  
20646 my ($self, $check) = @_;
20647  
20648 # Local variables
20649 my (
20650 $expression, $varObj, $lowerBound,
20651 @list, @sortedList,
20652 );
20653  
20654 # Check for improper arguments
20655 if (defined $check) {
20656  
20657 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20658 }
20659  
20660 # Retrieve the array variable to sort
20661 $expression = $self->ivShow('parseDataHash', 'expression');
20662 $varObj = $expression->varObj;
20663  
20664 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20665 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20666 if ($varObj->dimCount > 1) {
20667  
20668 return $self->scriptObj->setError(
20669 'SORTCASER_statement_cannot_operate_on_multi-dimensional_array',
20670 $self->_objClass . '->implement',
20671 );
20672 }
20673  
20674 # Import the values stored in the array, sort them, and store them back in the array
20675 @list = $varObj->cellList;
20676  
20677 # Take account of the first item in ->cellList, which is the lower bound
20678 $lowerBound = shift @list;
20679  
20680 if (ref($varObj) =~ m/Numeric/) {
20681  
20682 # It's a numeric array
20683 @sortedList = sort {$b->value <=> $a->value} (@list);
20684  
20685 } else {
20686  
20687 # It's a string array
20688 @sortedList = sort {lc($b->value) cmp lc($a->value)} (@list);
20689 }
20690  
20691 # Restore the lower bound to its previous place
20692 unshift(@sortedList, $lowerBound);
20693 $varObj->ivPoke('cellList', @sortedList);
20694  
20695 # Implementation complete
20696 return 1;
20697 }
20698 }
20699  
20700 { package Language::Axbasic::Statement::sortr;
20701  
20702 use strict;
20703 use warnings;
20704 use diagnostics;
20705  
20706 use Glib qw(TRUE FALSE);
20707  
20708 @Language::Axbasic::Statement::sortr::ISA = qw(
20709 Language::Axbasic
20710 Language::Axbasic::Statement
20711 );
20712  
20713 # SORTR variable-name
20714  
20715 ##################
20716 # Methods
20717  
20718 sub parse {
20719  
20720 # Called by LA::Line->parse directly after a call to LA::Statement->new
20721 #
20722 # Expected arguments
20723 # (none besides $self)
20724 #
20725 # Return values
20726 # 'undef' on improper arguments or if there is an error
20727 # 1 otherwise
20728  
20729 my ($self, $check) = @_;
20730  
20731 # Local variables
20732 my $expression;
20733  
20734 # Check for improper arguments
20735 if (defined $check) {
20736  
20737 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20738 }
20739  
20740 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20741 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20742 # that created by
20743 # DIM var (10)
20744 # ...by a variable name that looks like a scalar, i.e.
20745 # SORT var
20746 $self->scriptObj->set_declareMode('simple');
20747  
20748 # Get the variable name
20749 $expression = Language::Axbasic::Expression::Lvalue->new(
20750 $self->scriptObj,
20751 $self->tokenGroupObj,
20752 );
20753  
20754 if (! defined $expression) {
20755  
20756 return $self->scriptObj->setError(
20757 'missing_or_illegal_variable',
20758 $self->_objClass . '->parse',
20759 );
20760 }
20761  
20762 # Reset the temporary IV
20763 $self->scriptObj->set_declareMode('default');
20764  
20765 if (! $self->tokenGroupObj->testStatementEnd()) {
20766  
20767 return $self->scriptObj->setError(
20768 'unexpected_keywords,_operators_or_expressions',
20769 $self->_objClass . '->parse',
20770 );
20771 }
20772  
20773 # Store the variable for ->implement to use
20774 $self->ivAdd('parseDataHash', 'expression', $expression);
20775  
20776 # Parsing complete
20777 return 1;
20778 }
20779  
20780 sub implement {
20781  
20782 # Called by LA::Line->implement directly after a call to $self->parse
20783 #
20784 # Expected arguments
20785 # (none besides $self)
20786 #
20787 # Return values
20788 # 'undef' on improper arguments or if there is an error
20789 # 1 otherwise
20790  
20791 my ($self, $check) = @_;
20792  
20793 # Local variables
20794 my (
20795 $expression, $varObj, $lowerBound,
20796 @list, @sortedList,
20797 );
20798  
20799 # Check for improper arguments
20800 if (defined $check) {
20801  
20802 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20803 }
20804  
20805 # Retrieve the array variable to sort
20806 $expression = $self->ivShow('parseDataHash', 'expression');
20807 $varObj = $expression->varObj;
20808  
20809 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20810 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20811 if ($varObj->dimCount > 1) {
20812  
20813 return $self->scriptObj->setError(
20814 'SORTR_statement_cannot_operate_on_multi-dimensional_array',
20815 $self->_objClass . '->implement',
20816 );
20817 }
20818  
20819 # Import the values stored in the array, sort them, and store them back in the array
20820 @list = $varObj->cellList;
20821  
20822 # Take account of the first item in ->cellList, which is the lower bound
20823 $lowerBound = shift @list;
20824  
20825 if (ref($varObj) =~ m/Numeric/) {
20826  
20827 # It's a numeric array
20828 @sortedList = sort {$b->value <=> $a->value} (@list);
20829  
20830 } else {
20831  
20832 # It's a string array
20833 @sortedList = sort {$b->value cmp $a->value} (@list);
20834 }
20835  
20836 # Restore the lower bound to its previous place
20837 unshift(@sortedList, $lowerBound);
20838 $varObj->ivPoke('cellList', @sortedList);
20839  
20840 # Implementation complete
20841 return 1;
20842 }
20843 }
20844  
20845 { package Language::Axbasic::Statement::speak;
20846  
20847 use strict;
20848 use warnings;
20849 use diagnostics;
20850  
20851 use Glib qw(TRUE FALSE);
20852  
20853 @Language::Axbasic::Statement::speak::ISA = qw(
20854 Language::Axbasic
20855 Language::Axbasic::Statement
20856 );
20857  
20858 # SPEAK expression [ , expression ]
20859  
20860 ##################
20861 # Methods
20862  
20863 sub parse {
20864  
20865 # Called by LA::Line->parse directly after a call to LA::Statement->new
20866 #
20867 # Expected arguments
20868 # (none besides $self)
20869 #
20870 # Return values
20871 # 'undef' on improper arguments or if there is an error
20872 # 1 otherwise
20873  
20874 my ($self, $check) = @_;
20875  
20876 # Local variables
20877 my ($textExp, $configExp, $token);
20878  
20879 # Check for improper arguments
20880 if (defined $check) {
20881  
20882 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20883 }
20884  
20885 # Convert the text and configuration strings into expressions
20886 $textExp = Language::Axbasic::Expression::Arithmetic->new(
20887 $self->scriptObj,
20888 $self->tokenGroupObj,
20889 );
20890  
20891 if (! defined $textExp) {
20892  
20893 return $self->scriptObj->setError(
20894 'missing_or_illegal_expression',
20895 $self->_objClass . '->parse',
20896 );
20897 }
20898  
20899 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
20900  
20901 $configExp = Language::Axbasic::Expression::Arithmetic->new(
20902 $self->scriptObj,
20903 $self->tokenGroupObj,
20904 );
20905  
20906 if (! defined $configExp) {
20907  
20908 return $self->scriptObj->setError(
20909 'missing_or_illegal_expression',
20910 $self->_objClass . '->parse',
20911 );
20912 }
20913 }
20914  
20915 # Check that nothing follows the expressions
20916 if (! $self->tokenGroupObj->testStatementEnd()) {
20917  
20918 return $self->scriptObj->setError(
20919 'unexpected_keywords,_operators_or_expressions',
20920 $self->_objClass . '->parse',
20921 );
20922 }
20923  
20924 # Store the expressions, so $self->implement can retrieve them
20925 $self->ivAdd('parseDataHash', 'text', $textExp);
20926 $self->ivAdd('parseDataHash', 'config', $configExp);
20927  
20928 # Parsing complete
20929 return 1;
20930 }
20931  
20932 sub implement {
20933  
20934 # Called by LA::Line->implement directly after a call to $self->parse
20935 #
20936 # Expected arguments
20937 # (none besides $self)
20938 #
20939 # Return values
20940 # 'undef' on improper arguments or if there is an error
20941 # 1 otherwise
20942  
20943 my ($self, $check) = @_;
20944  
20945 # Local variables
20946 my ($textExp, $text, $configExp, $configuration, $cmd);
20947  
20948 # Check for improper arguments
20949 if (defined $check) {
20950  
20951 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20952 }
20953  
20954 # Retrieve the arguments stored by $self->parse
20955 $textExp = $self->ivShow('parseDataHash', 'text');
20956 $configExp = $self->ivShow('parseDataHash', 'config');
20957  
20958 # Evaluate each expression
20959 $text = $textExp->evaluate();
20960 if (defined $configExp) {
20961  
20962 $configuration = $configExp->evaluate();
20963 }
20964  
20965 # Prepare the client command
20966 $cmd = 'speak <' . $text . '>';
20967 if ($configuration) {
20968  
20969 $cmd .= ' -n ' . $configuration;
20970 }
20971  
20972 # Send the command
20973 $self->scriptObj->session->pseudoCmd($cmd, $self->scriptObj->pseudoCmdMode);
20974  
20975 # Implementation complete
20976 return 1;
20977 }
20978 }
20979  
20980 { package Language::Axbasic::Statement::speed;
20981  
20982 use strict;
20983 use warnings;
20984 use diagnostics;
20985  
20986 use Glib qw(TRUE FALSE);
20987  
20988 @Language::Axbasic::Statement::speed::ISA = qw(
20989 Language::Axbasic
20990 Language::Axbasic::Statement
20991 );
20992  
20993 # SPEED expression
20994  
20995 ##################
20996 # Methods
20997  
20998 sub parse {
20999  
21000 # Called by LA::Line->parse directly after a call to LA::Statement->new
21001 #
21002 # Expected arguments
21003 # (none besides $self)
21004 #
21005 # Return values
21006 # 'undef' on improper arguments or if there is an error
21007 # 1 otherwise
21008  
21009 my ($self, $check) = @_;
21010  
21011 # Local variables
21012 my $expression;
21013  
21014 # Check for improper arguments
21015 if (defined $check) {
21016  
21017 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21018 }
21019  
21020 # Get the expression and store it for ->implement to use
21021 $expression = Language::Axbasic::Expression::Arithmetic->new(
21022 $self->scriptObj,
21023 $self->tokenGroupObj,
21024 );
21025  
21026 if (! defined $expression) {
21027  
21028 return $self->scriptObj->setError(
21029 'missing_or_illegal_expression',
21030 $self->_objClass . '->parse',
21031 );
21032  
21033 } else {
21034  
21035 $self->ivAdd('parseDataHash', 'expression', $expression);
21036 }
21037  
21038 # There should be nothing after the expression
21039 if (! $self->tokenGroupObj->testStatementEnd()) {
21040  
21041 return $self->scriptObj->setError(
21042 'unexpected_keywords,_operators_or_expressions',
21043 $self->_objClass . '->parse',
21044 );
21045 }
21046  
21047 # Parsing complete
21048 return 1;
21049 }
21050  
21051 sub implement {
21052  
21053 # Called by LA::Line->implement directly after a call to $self->parse
21054 #
21055 # Expected arguments
21056 # (none besides $self)
21057 #
21058 # Return values
21059 # 'undef' on improper arguments or if there is an error
21060 # 1 otherwise
21061  
21062 my ($self, $check) = @_;
21063  
21064 # Local variables
21065 my ($expression, $string);
21066  
21067 # Check for improper arguments
21068 if (defined $check) {
21069  
21070 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21071 }
21072  
21073 # Retrieve the expression to be written
21074 $expression = $self->ivShow('parseDataHash', 'expression');
21075 # Evaluate the expression to get a scalar value
21076 $string = $expression->evaluate();
21077  
21078 # Execute the expression as a speedwalk command
21079 $self->scriptObj->session->speedWalkCmd($string);
21080  
21081 # Implementation complete
21082 return 1;
21083 }
21084 }
21085  
21086 { package Language::Axbasic::Statement::stop;
21087  
21088 use strict;
21089 use warnings;
21090 use diagnostics;
21091  
21092 use Glib qw(TRUE FALSE);
21093  
21094 @Language::Axbasic::Statement::stop::ISA = qw(
21095 Language::Axbasic
21096 Language::Axbasic::Statement
21097 );
21098  
21099 # STOP
21100  
21101 ##################
21102 # Methods
21103  
21104 sub parse {
21105  
21106 # Called by LA::Line->parse directly after a call to LA::Statement->new
21107 #
21108 # Expected arguments
21109 # (none besides $self)
21110 #
21111 # Return values
21112 # 'undef' on improper arguments or if there is an error
21113 # 1 otherwise
21114  
21115 my ($self, $check) = @_;
21116  
21117 # Check for improper arguments
21118 if (defined $check) {
21119  
21120 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21121 }
21122  
21123 # STOP statements always appear on their own
21124 if (! $self->tokenGroupObj->testStatementEnd()) {
21125  
21126 return $self->scriptObj->setError(
21127 'unexpected_keywords,_operators_or_expressions',
21128 $self->_objClass . '->parse',
21129 );
21130 }
21131  
21132 # Parsing complete
21133 return 1;
21134 }
21135  
21136 sub implement {
21137  
21138 # Called by LA::Line->implement directly after a call to $self->parse
21139 #
21140 # Expected arguments
21141 # (none besides $self)
21142 #
21143 # Return values
21144 # 'undef' on improper arguments or if there is an error
21145 # 1 otherwise
21146  
21147 my ($self, $check) = @_;
21148  
21149 # Check for improper arguments
21150 if (defined $check) {
21151  
21152 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21153 }
21154  
21155 # Execution of the Axbasic script can now stop
21156 if ($self->scriptObj->executionStatus ne 'finished') {
21157  
21158 # 'wait_input' means that parsing/implementation of the script has finished
21159 $self->scriptObj->set_executionStatus('finished');
21160 # 'finished' means that parsing/implementation finished without an error
21161 $self->scriptObj->set_scriptStatus('finished');
21162 }
21163  
21164 # Implementation complete
21165 return 1;
21166 }
21167 }
21168  
21169 { package Language::Axbasic::Statement::sub;
21170  
21171 use strict;
21172 use warnings;
21173 use diagnostics;
21174  
21175 use Glib qw(TRUE FALSE);
21176  
21177 @Language::Axbasic::Statement::sub::ISA = qw(
21178 Language::Axbasic
21179 Language::Axbasic::Statement
21180 );
21181  
21182 # SUB NUMERIC subroutine-name
21183 # SUB NUMERIC subroutine-name ( [ parameter-list ] )
21184 # SUB subroutine-name
21185 # SUB subroutine-name ( [ parameter-list ] )
21186 # SUB STRING subroutine-name
21187 # SUB STRING subroutine-name ( [ parameter-list ] )
21188  
21189 ##################
21190 # Methods
21191  
21192 sub parse {
21193  
21194 # Called by LA::Line->parse directly after a call to LA::Statement->new
21195 #
21196 # Expected arguments
21197 # (none besides $self)
21198 #
21199 # Return values
21200 # 'undef' on improper arguments or if there is an error
21201 # 1 otherwise
21202  
21203 my ($self, $check) = @_;
21204  
21205 # Local variables
21206 my ($subExpression, $type, $subObj, $expression);
21207  
21208 # Check for improper arguments
21209 if (defined $check) {
21210  
21211 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21212 }
21213  
21214 # The SUB keyword is not available in primitive numbering mode
21215 if ($self->scriptObj->executionMode ne 'no_line_num') {
21216  
21217 return $self->scriptObj->setError(
21218 'statement_not_available_with_line_numbers',
21219 $self->_objClass . '->parse',
21220 );
21221 }
21222  
21223 # Look for the keywords NUMERIC or STRING, which define what type of return value the
21224 # subroutine will produce. If neither occurs, the subroutine returns a numeric value
21225 if (defined $self->tokenGroupObj->shiftMatchingToken('string')) {
21226  
21227 $type = 'string';
21228  
21229 } else {
21230  
21231 $self->tokenGroupObj->shiftMatchingToken('numeric');
21232 $type = 'numeric';
21233 }
21234  
21235 # Temporarily set the IV that allows undeclared variables to be created
21236 $self->scriptObj->set_declareMode('local_scalar');
21237  
21238 # The subroutine name, and its arguments, consist of all the tokens up until the close
21239 # parenthesis
21240 if ($type eq 'numeric') {
21241  
21242 $subExpression = Language::Axbasic::Expression::Subroutine::Numeric->new(
21243 $self->scriptObj,
21244 $self->tokenGroupObj,
21245 );
21246  
21247 } else {
21248  
21249 $subExpression = Language::Axbasic::Expression::Subroutine::String->new(
21250 $self->scriptObj,
21251 $self->tokenGroupObj,
21252 );
21253 }
21254  
21255 # Reset the temporary IV
21256 $self->scriptObj->set_declareMode('default');
21257  
21258 if (! defined $subExpression) {
21259  
21260 return $self->scriptObj->setError(
21261 'subroutine_declaration_error',
21262 $self->_objClass . '->parse',
21263 );
21264 }
21265  
21266 # Check that there is nothing after the list of arguments (except for the statement
21267 # separator, :)
21268 if (! defined $self->tokenGroupObj->testStatementEnd()) {
21269  
21270 return $self->scriptObj->setError(
21271 'unexpected_keywords,_operators_or_expressions',
21272 $self->_objClass . '->parse',
21273 );
21274 }
21275  
21276 # Subroutines cannot be declared inside another one (except for the implied *main
21277 # subroutine, in which any number of subroutines can be declared)
21278 if ($self->scriptObj->currentParseSub) {
21279  
21280 return $self->scriptObj->setError(
21281 'subroutine_declared_inside_another',
21282 $self->_objClass . '->parse',
21283 );
21284 }
21285  
21286 # We don't actually want the LA::Expression, just the LA::Subroutine object we've declared
21287 $subObj = $subExpression->subObj;
21288 # Store it in the script's list of subroutines
21289 $self->scriptObj->add_subName($subObj->name, $subObj);
21290  
21291 # Save the function object - ->implement needs it
21292 $self->ivAdd('parseDataHash', 'sub_obj', $subObj);
21293  
21294 # Tell LA::Script->parse that it's parsing statements inside a subroutine declaration now
21295 $self->scriptObj->set_currentParseSub($subObj);
21296 # Tell the subroutine in which statement it is declared
21297 $subObj->set_declareStatement($self);
21298 # Tell the subroutine what kind of return value it is going to send
21299 $subObj->set_returnVarType($type);
21300  
21301 # Parsing complete
21302 return 1;
21303 }
21304  
21305 sub implement {
21306  
21307 # Called by LA::Line->implement directly after a call to $self->parse
21308 #
21309 # Expected arguments
21310 # (none besides $self)
21311 #
21312 # Return values
21313 # 'undef' on improper arguments or if there is an error
21314 # 1 otherwise
21315  
21316 my ($self, $check) = @_;
21317  
21318 # Local variables
21319 my ($subObj, $endStatement);
21320  
21321 # Check for improper arguments
21322 if (defined $check) {
21323  
21324 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21325 }
21326  
21327 # SUB statements are ->implemented in the following situation
21328 #
21329 # PRINT "Hello world!"
21330 # SUB STRING test (var$)
21331 # ...
21332 # END SUB
21333 # PRINT "Goodbye cruel world!"
21334 # END
21335 #
21336 # ...namely, when a subroutine declaration occurs before the END statement
21337 # After executing the PRINT "Hello world!", this function locates the correct
21338 # LA::Subroutine, finds the END SUB statement, and marks the next statement
21339 # after that - in this case, the PRINT "Goodbye cruel world!" - as the
21340 # next statement to execute. Everything between SUB...END SUB is ignored
21341  
21342 $subObj = $self->ivShow('parseDataHash', 'sub_obj');
21343  
21344 # Find the subroutine's END SUB statement
21345 $endStatement = $subObj->terminateStatement;
21346  
21347 # The next statement to execute is the statement after that
21348 if (defined $endStatement->nextStatement) {
21349  
21350 # LA::Script->nextStatement is currently set to this statement; continue execution
21351 # as if this were the END statement
21352 $self->scriptObj->set_nextStatement($endStatement);
21353  
21354 } else {
21355  
21356 $self->scriptObj->set_nextStatement(undef);
21357 $self->scriptObj->set_nextLine($endStatement->lineObj->procLineNum + 1);
21358 }
21359  
21360 # Implementation complete
21361 return 1;
21362 }
21363 }
21364  
21365 { package Language::Axbasic::Statement::titlewin;
21366  
21367 use strict;
21368 use warnings;
21369 use diagnostics;
21370  
21371 use Glib qw(TRUE FALSE);
21372  
21373 @Language::Axbasic::Statement::titlewin::ISA = qw(
21374 Language::Axbasic
21375 Language::Axbasic::Statement
21376 );
21377  
21378 # TITLEWIN expression
21379  
21380 ##################
21381 # Methods
21382  
21383 sub parse {
21384  
21385 # Called by LA::Line->parse directly after a call to LA::Statement->new
21386 #
21387 # Expected arguments
21388 # (none besides $self)
21389 #
21390 # Return values
21391 # 'undef' on improper arguments or if there is an error
21392 # 1 otherwise
21393  
21394 my ($self, $check) = @_;
21395  
21396 # Local variables
21397 my $expression;
21398  
21399 # Check for improper arguments
21400 if (defined $check) {
21401  
21402 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21403 }
21404  
21405 # Get the expression and store it for ->implement to use
21406 $expression = Language::Axbasic::Expression::Arithmetic->new(
21407 $self->scriptObj,
21408 $self->tokenGroupObj,
21409 );
21410  
21411 if (! defined $expression) {
21412  
21413 return $self->scriptObj->setError(
21414 'missing_or_illegal_expression',
21415 $self->_objClass . '->parse',
21416 );
21417  
21418 } else {
21419  
21420 $self->ivAdd('parseDataHash', 'expression', $expression);
21421 }
21422  
21423 # There should be nothing after the expression
21424 if (! $self->tokenGroupObj->testStatementEnd()) {
21425  
21426 return $self->scriptObj->setError(
21427 'unexpected_keywords,_operators_or_expressions',
21428 $self->_objClass . '->parse',
21429 );
21430 }
21431  
21432 # Parsing complete
21433 return 1;
21434 }
21435  
21436 sub implement {
21437  
21438 # Called by LA::Line->implement directly after a call to $self->parse
21439 #
21440 # Expected arguments
21441 # (none besides $self)
21442 #
21443 # Return values
21444 # 'undef' on improper arguments or if there is an error
21445 # 1 otherwise
21446  
21447 my ($self, $check) = @_;
21448  
21449 # Local variables
21450 my ($expression, $string);
21451  
21452 # Check for improper arguments
21453 if (defined $check) {
21454  
21455 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21456 }
21457  
21458 # Retrieve the expression to be used as a title
21459 $expression = $self->ivShow('parseDataHash', 'expression');
21460 # Evaluate the expression to get a string
21461 $string = $expression->evaluate();
21462  
21463 # If the Axbasic script is being run from within an Axmud task and the task window is open,
21464 # set its title. Otherwise, do nothing
21465 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
21466  
21467 # Write to the window. If $string is an empty string, restore the original title
21468 if ($string) {
21469 $self->scriptObj->parentTask->setTitle($string);
21470 } else {
21471 $self->scriptObj->parentTask->setTitle();
21472 }
21473 }
21474  
21475 # Implementation complete
21476 return 1;
21477 }
21478 }
21479  
21480 { package Language::Axbasic::Statement::unflashwin;
21481  
21482 use strict;
21483 use warnings;
21484 use diagnostics;
21485  
21486 use Glib qw(TRUE FALSE);
21487  
21488 @Language::Axbasic::Statement::unflashwin::ISA = qw(
21489 Language::Axbasic
21490 Language::Axbasic::Statement
21491 );
21492  
21493 # UNFLASHWIN
21494  
21495 ##################
21496 # Methods
21497  
21498 sub parse {
21499  
21500 # Called by LA::Line->parse directly after a call to LA::Statement->new
21501 #
21502 # Expected arguments
21503 # (none besides $self)
21504 #
21505 # Return values
21506 # 'undef' on improper arguments or if there is an error
21507 # 1 otherwise
21508  
21509 my ($self, $check) = @_;
21510  
21511 # Local variables
21512 my ($expression);
21513  
21514 # Check for improper arguments
21515 if (defined $check) {
21516  
21517 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21518 }
21519  
21520 # UNFLASHWIN statements always appear on their own
21521 if (! $self->tokenGroupObj->testStatementEnd()) {
21522  
21523 return $self->scriptObj->setError(
21524 'unexpected_keywords,_operators_or_expressions',
21525 $self->_objClass . '->parse',
21526 );
21527 }
21528  
21529 # Parsing complete
21530 return 1;
21531 }
21532  
21533 sub implement {
21534  
21535 # Called by LA::Line->implement directly after a call to $self->parse
21536 #
21537 # Expected arguments
21538 # (none besides $self)
21539 #
21540 # Return values
21541 # 'undef' on improper arguments or if there is an error
21542 # 1 otherwise
21543  
21544 my ($self, $check) = @_;
21545  
21546 # Local variables
21547  
21548 # Check for improper arguments
21549 if (defined $check) {
21550  
21551 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21552 }
21553  
21554 # If the Axbasic script is being run from within an Axmud task and the task window is open,
21555 # reset the window's urgency hint. Otherwise, do nothing
21556 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->winObj) {
21557  
21558 # Sets the window urgency hint
21559 $self->scriptObj->parentTask->winObj->resetUrgent();
21560 }
21561  
21562 # Implementation complete
21563 return 1;
21564 }
21565 }
21566  
21567 { package Language::Axbasic::Statement::unshift;
21568  
21569 use strict;
21570 use warnings;
21571 use diagnostics;
21572  
21573 use Glib qw(TRUE FALSE);
21574  
21575 @Language::Axbasic::Statement::unshift::ISA = qw(
21576 Language::Axbasic
21577 Language::Axbasic::Statement
21578 );
21579  
21580 # UNSHIFT array-name , expression
21581  
21582 ##################
21583 # Methods
21584  
21585 sub parse {
21586  
21587 # Called by LA::Line->parse directly after a call to LA::Statement->new
21588 #
21589 # Expected arguments
21590 # (none besides $self)
21591 #
21592 # Return values
21593 # 'undef' on improper arguments or if there is an error
21594 # 1 otherwise
21595  
21596 my ($self, $check) = @_;
21597  
21598 # Local variables
21599 my ($arrayExp, $scalarExp);
21600  
21601 # Check for improper arguments
21602 if (defined $check) {
21603  
21604 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21605 }
21606  
21607 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
21608 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
21609 # that created by
21610 # DIM var (10)
21611 # ...by a variable name that looks like a scalar, i.e.
21612 # SORT var
21613 $self->scriptObj->set_declareMode('simple');
21614  
21615 # Get the array variable name
21616 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
21617 $self->scriptObj,
21618 $self->tokenGroupObj,
21619 );
21620  
21621 if (! defined $arrayExp) {
21622  
21623 return $self->scriptObj->setError(
21624 'missing_or_illegal_array_variable',
21625 $self->_objClass . '->parse',
21626 );
21627 }
21628  
21629 # Reset the temporary IV
21630 $self->scriptObj->set_declareMode('default');
21631  
21632 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
21633  
21634 return $self->scriptObj->setError(
21635 'syntax_error',
21636 $self->_objClass . '->parse',
21637 );
21638 }
21639  
21640 # Extract the non-optional scalar expression
21641 $scalarExp = Language::Axbasic::Expression::Arithmetic->new(
21642 $self->scriptObj,
21643 $self->tokenGroupObj,
21644 );
21645  
21646 if (! defined $scalarExp) {
21647  
21648 return $self->scriptObj->setError(
21649 'missing_or_illegal_expression',
21650 $self->_objClass . '->parse',
21651 );
21652 }
21653  
21654 if (! $self->tokenGroupObj->testStatementEnd()) {
21655  
21656 return $self->scriptObj->setError(
21657 'unexpected_keywords,_operators_or_expressions',
21658 $self->_objClass . '->parse',
21659 );
21660 }
21661  
21662 # Save the expression objects so $self->implement can use them, if it is called
21663 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
21664 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
21665  
21666 # Parsing complete
21667 return 1;
21668 }
21669  
21670 sub implement {
21671  
21672 # Called by LA::Line->implement directly after a call to $self->parse
21673 #
21674 # Expected arguments
21675 # (none besides $self)
21676 #
21677 # Return values
21678 # 'undef' on improper arguments
21679 # 1 otherwise
21680  
21681 my ($self, $check) = @_;
21682  
21683 # Local variables
21684 my ($arrayExp, $scalarExp, $removedVar);
21685  
21686 # Check for improper arguments
21687 if (defined $check) {
21688  
21689 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21690 }
21691  
21692 # Retrieve the variables stored by ->parse
21693 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
21694 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
21695  
21696 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be unshifted. Multi-dimensional arrays
21697 # (e.g. DIM var (5, 5, 2) ) can't be unshifted
21698 if ($arrayExp->varObj->dimCount > 1) {
21699  
21700 return $self->scriptObj->setError(
21701 'UNSHIFT_statement_cannot_operate_on_multi-dimensional_array',
21702 $self->_objClass . '->implement',
21703 );
21704 }
21705  
21706 # Cannot use a numeric array with a string scalar, and vice-versa
21707 if (
21708 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp) =~ m/Numeric/))
21709 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp) =~ m/String/))
21710 ) {
21711 return $self->scriptObj->setError(
21712 'type_mismatch_error',
21713 $self->_objClass . '->implement',
21714 );
21715 }
21716  
21717 # Evaluate the expression, and unshift it from the stack
21718 $arrayExp->varObj->doUnshift($scalarExp->evaluate());
21719  
21720 # Implementation complete
21721 return 1;
21722 }
21723 }
21724  
21725 { package Language::Axbasic::Statement::until;
21726  
21727 use strict;
21728 use warnings;
21729 use diagnostics;
21730  
21731 use Glib qw(TRUE FALSE);
21732  
21733 @Language::Axbasic::Statement::until::ISA = qw(
21734 Language::Axbasic
21735 Language::Axbasic::Statement
21736 );
21737  
21738 # UNTIL condition
21739 # UNTIL expression
21740  
21741 ##################
21742 # Methods
21743  
21744 sub parse {
21745  
21746 # Called by LA::Line->parse directly after a call to LA::Statement->new
21747 #
21748 # Expected arguments
21749 # (none besides $self)
21750 #
21751 # Return values
21752 # 'undef' on improper arguments or if there is an error
21753 # 1 otherwise
21754  
21755 my ($self, $check) = @_;
21756  
21757 # Local variables
21758 my ($condition, $subObj, $doStatement);
21759  
21760 # Check for improper arguments
21761 if (defined $check) {
21762  
21763 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21764 }
21765  
21766 # The 'until' keyword is not available in primitive numbering mode
21767 if ($self->scriptObj->executionMode ne 'no_line_num') {
21768  
21769 return $self->scriptObj->setError(
21770 'statement_not_available_with_line_numbers',
21771 $self->_objClass . '->parse',
21772 );
21773 }
21774  
21775 # Read a conditional expression
21776 $condition = Language::Axbasic::Expression::LogicalOr->new(
21777 $self->scriptObj,
21778 $self->tokenGroupObj,
21779 'maybe_arithmetic',
21780 );
21781  
21782 if (! defined $condition) {
21783  
21784 return $self->scriptObj->setError(
21785 'missing_or_illegal_conditional_expression',
21786 $self->_objClass . '->parse',
21787 );
21788  
21789 } else {
21790  
21791 # Store the condition expression, so $self->implement can retrieve it
21792 $self->ivAdd('parseDataHash', 'condition', $condition);
21793 }
21794  
21795 # Check there's nothing else in the statement after the condition expression
21796 if (! $self->tokenGroupObj->testStatementEnd()) {
21797  
21798 return $self->scriptObj->setError(
21799 'unexpected_keywords,_operators_or_expressions',
21800 $self->_objClass . '->parse',
21801 );
21802 }
21803  
21804 # Find the matching DO statement, which should already have been parsed
21805 $subObj = $self->scriptObj->returnCurrentSub();
21806 if (! $subObj->doStackList) {
21807  
21808 return $self->scriptObj->setError(
21809 'UNTIL_statement_without_matching_DO',
21810 $self->_objClass . '->parse',
21811 );
21812  
21813 } else {
21814  
21815 $doStatement = $subObj->pop_doStackList();
21816  
21817 # Tell the DO statement's ->implement what its matching LOOP statement (i.e. this one)
21818 # is
21819 $doStatement->add_parseDataHash('until_statement', $self);
21820 }
21821  
21822 # Parsing complete
21823 return 1;
21824 }
21825  
21826 sub implement {
21827  
21828 # Called by LA::Line->implement directly after a call to $self->parse
21829 #
21830 # Expected arguments
21831 # (none besides $self)
21832 #
21833 # Return values
21834 # 'undef' on improper arguments or if there is an error
21835 # 1 otherwise
21836  
21837 my ($self, $check) = @_;
21838  
21839 # Local variables
21840 my ($condition, $subObj, $doStatement, $exitFlag);
21841  
21842 # Check for improper arguments
21843 if (defined $check) {
21844  
21845 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21846 }
21847  
21848 # Retrieve the condition expression stored by $self->parse
21849 $condition = $self->ivShow('parseDataHash', 'condition');
21850  
21851 # Get the corresponding DO statement from the current subroutine's code block stack. Keep
21852 # removing code blocks from the top of the stack until we get the right one
21853 $subObj = $self->scriptObj->returnCurrentSub();
21854 if (! $subObj->blockStackList) {
21855  
21856 return $self->scriptObj->setError(
21857 'UNTIL_statement_without_matching_DO',
21858 $self->_objClass . '->implement',
21859 );
21860 }
21861  
21862 do {
21863 $doStatement = $subObj->pop_blockStackList();
21864  
21865 # Check that it's a DO statement - not the start of another kind of code block
21866 if ($doStatement->keyword eq 'do') {
21867  
21868 # We've found the statement we're looking for
21869 $exitFlag = TRUE;
21870 }
21871  
21872 } until ($exitFlag || ! $subObj->blockStackList);
21873  
21874 if (! $exitFlag) {
21875  
21876 return $self->scriptObj->setError(
21877 'UNTIL_statement_without_matching_DO',
21878 $self->_objClass . '->implement',
21879 );
21880 }
21881  
21882 # Evaluate the condition expression
21883 if (! $condition->evaluate()) {
21884  
21885 # The condition expression is false, so we need to perform another iteration of the loop
21886 if (defined $doStatement->nextStatement) {
21887  
21888 # LA::Script->nextStatement is currently set to this statement; continue execution
21889 # as if this were the DO statement
21890 $self->scriptObj->set_nextStatement($doStatement);
21891  
21892 } else {
21893  
21894 $self->scriptObj->set_nextStatement(undef);
21895 $self->scriptObj->set_nextLine($doStatement->lineObj->procLineNum + 1);
21896 }
21897  
21898 # Put the corresponding DO statement back into the current subroutine's code block stack
21899 $subObj->push_blockStackList($doStatement);
21900 }
21901  
21902 # Implementation complete
21903 return 1;
21904 }
21905 }
21906  
21907 { package Language::Axbasic::Statement::waitactive;
21908  
21909 use strict;
21910 use warnings;
21911 use diagnostics;
21912  
21913 use Glib qw(TRUE FALSE);
21914  
21915 @Language::Axbasic::Statement::waitactive::ISA = qw(
21916 Language::Axbasic
21917 Language::Axbasic::Statement
21918 );
21919  
21920 # WAITACTIVE expression
21921  
21922 ##################
21923 # Methods
21924  
21925 sub parse {
21926  
21927 # Called by LA::Line->parse directly after a call to LA::Statement->new
21928 #
21929 # Expected arguments
21930 # (none besides $self)
21931 #
21932 # Return values
21933 # 'undef' on improper arguments or if there is an error
21934 # 1 otherwise
21935  
21936 my ($self, $check) = @_;
21937  
21938 # Local variables
21939 my $taskNameExp;
21940  
21941 # Check for improper arguments
21942 if (defined $check) {
21943  
21944 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21945 }
21946  
21947 # Convert the task string into an expression
21948 $taskNameExp = Language::Axbasic::Expression::Arithmetic->new(
21949 $self->scriptObj,
21950 $self->tokenGroupObj,
21951 );
21952  
21953 if (! defined $taskNameExp) {
21954  
21955 return $self->scriptObj->setError(
21956 'missing_or_illegal_expression',
21957 $self->_objClass . '->parse',
21958 );
21959 }
21960  
21961 # Check that nothing follows the expression(s)
21962 if (! $self->tokenGroupObj->testStatementEnd()) {
21963  
21964 return $self->scriptObj->setError(
21965 'unexpected_keywords,_operators_or_expressions',
21966 $self->_objClass . '->parse',
21967 );
21968 }
21969  
21970 # Store the expression, so $self->implement can retrieve it
21971 $self->ivAdd('parseDataHash', 'task_name', $taskNameExp);
21972  
21973 # Parsing complete
21974 return 1;
21975 }
21976  
21977 sub implement {
21978  
21979 # Called by LA::Line->implement directly after a call to $self->parse
21980 #
21981 # Expected arguments
21982 # (none besides $self)
21983 #
21984 # Return values
21985 # 'undef' on improper arguments or if there is an error
21986 # 1 otherwise
21987  
21988 my ($self, $check) = @_;
21989  
21990 # Local variables
21991 my ($taskNameExp, $taskName, $taskObj);
21992  
21993 # Check for improper arguments
21994 if (defined $check) {
21995  
21996 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21997 }
21998  
21999 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22000 if (! $self->scriptObj->parentTask) {
22001  
22002 # Implementation complete. Execution resumes from the next statement
22003 return 1;
22004 }
22005  
22006 # Otherwise, retrieve the argument stored by $self->parse
22007 $taskNameExp = $self->ivShow('parseDataHash', 'task_name');
22008  
22009 # Evaluate the expression(s)
22010 $taskName = $taskNameExp->evaluate();
22011  
22012 # Look for a task matching $taskName. GA::Generic::Cmd->findTask recognises task labels
22013 # (stored in GA::Client->taskLabelHash), tasks' formal names (stored in
22014 # GA::Client->taskPackageHash), or task unique names in the current tasklist (stored in
22015 # GA::Session->currentTaskHash)
22016 ($taskObj) = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $taskName);
22017 if (! $taskObj) {
22018  
22019 # No matching task in the current tasklist
22020 return $self->scriptObj->setError(
22021 'WAITACTIVE_operation_failure',
22022 $self->_objClass . '->parse',
22023 );
22024 }
22025  
22026 # Inform the LA::Script's parent task that it should start waiting
22027 $self->scriptObj->parentTask->setUpMonitoring('task_active', $taskObj->uniqueName);
22028  
22029 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22030 $self->scriptObj->set_scriptStatus('wait_active');
22031  
22032 # Implementation complete
22033 return 1;
22034 }
22035 }
22036  
22037 { package Language::Axbasic::Statement::waitalias;
22038  
22039 use strict;
22040 use warnings;
22041 use diagnostics;
22042  
22043 use Glib qw(TRUE FALSE);
22044  
22045 @Language::Axbasic::Statement::waitalias::ISA = qw(
22046 Language::Axbasic
22047 Language::Axbasic::Statement
22048 );
22049  
22050 # WAITALIAS expression [ , expression ]
22051  
22052 ##################
22053 # Methods
22054  
22055 sub parse {
22056  
22057 # Called by LA::Line->parse directly after a call to LA::Statement->new
22058 #
22059 # Expected arguments
22060 # (none besides $self)
22061 #
22062 # Return values
22063 # 'undef' on improper arguments or if there is an error
22064 # 1 otherwise
22065  
22066 my ($self, $check) = @_;
22067  
22068 # Check for improper arguments
22069 if (defined $check) {
22070  
22071 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22072 }
22073  
22074 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
22075 # ready for $self->implement to access
22076 if (! $self->parseWaitInterface()) {
22077  
22078 # ($self->scriptObj->setError has already been called)
22079 return undef;
22080 }
22081  
22082 # Parsing complete
22083 return 1;
22084 }
22085  
22086 sub implement {
22087  
22088 # Called by LA::Line->implement directly after a call to $self->parse
22089 #
22090 # Expected arguments
22091 # (none besides $self)
22092 #
22093 # Return values
22094 # 'undef' on improper arguments or if there is an error
22095 # 1 otherwise
22096  
22097 my ($self, $check) = @_;
22098  
22099 # Check for improper arguments
22100 if (defined $check) {
22101  
22102 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22103 }
22104  
22105 # Implement the statement, haveing parsed it
22106 if (! $self->implementWaitInterface('alias')) {
22107  
22108 # ($self->scriptObj->setError has already been called)
22109 return undef;
22110 }
22111  
22112 # Implementation complete
22113 return 1;
22114 }
22115 }
22116  
22117 { package Language::Axbasic::Statement::waitalive;
22118  
22119 use strict;
22120 use warnings;
22121 use diagnostics;
22122  
22123 use Glib qw(TRUE FALSE);
22124  
22125 @Language::Axbasic::Statement::waitalive::ISA = qw(
22126 Language::Axbasic
22127 Language::Axbasic::Statement
22128 );
22129  
22130 # WAITALIVE [ expression ]
22131  
22132 ##################
22133 # Methods
22134  
22135 sub parse {
22136  
22137 # Called by LA::Line->parse directly after a call to LA::Statement->new
22138 #
22139 # Expected arguments
22140 # (none besides $self)
22141 #
22142 # Return values
22143 # 'undef' on improper arguments or if there is an error
22144 # 1 otherwise
22145  
22146 my ($self, $check) = @_;
22147  
22148 # Local variables
22149 my $timeoutExp;
22150  
22151 # Check for improper arguments
22152 if (defined $check) {
22153  
22154 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22155 }
22156  
22157 # Get the timeout, if specified, and convert it into an expression
22158 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22159  
22160 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22161 $self->scriptObj,
22162 $self->tokenGroupObj,
22163 );
22164  
22165 if (! defined $timeoutExp) {
22166  
22167 return $self->scriptObj->setError(
22168 'missing_or_illegal_expression',
22169 $self->_objClass . '->parse',
22170 );
22171 }
22172 }
22173  
22174 # Check that nothing follows the expression(s)
22175 if (! $self->tokenGroupObj->testStatementEnd()) {
22176  
22177 return $self->scriptObj->setError(
22178 'unexpected_keywords,_operators_or_expressions',
22179 $self->_objClass . '->parse',
22180 );
22181 }
22182  
22183 # Store the expression (if specified), so $self->implement can retrieve it
22184 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22185  
22186 # Parsing complete
22187 return 1;
22188 }
22189  
22190 sub implement {
22191  
22192 # Called by LA::Line->implement directly after a call to $self->parse
22193 #
22194 # Expected arguments
22195 # (none besides $self)
22196 #
22197 # Return values
22198 # 'undef' on improper arguments or if there is an error
22199 # 1 otherwise
22200  
22201 my ($self, $check) = @_;
22202  
22203 # Local variables
22204 my ($timeoutExp, $timeout);
22205  
22206 # Check for improper arguments
22207 if (defined $check) {
22208  
22209 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22210 }
22211  
22212 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22213 if (! $self->scriptObj->parentTask) {
22214  
22215 # Implementation complete. Execution resumes from the next statement
22216 return 1;
22217 }
22218  
22219 # Otherwise, retrieve the argument (if any) stored by $self->parse
22220 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22221  
22222 # Evaluate the expression, if specified
22223 if (defined $timeoutExp) {
22224  
22225 $timeout = $timeoutExp->evaluate();
22226  
22227 if (! ($timeout =~ /^\d+$/)) {
22228  
22229 return $self->scriptObj->setError(
22230 'invalid_integer',
22231 $self->_objClass . '->implement',
22232 );
22233  
22234 } elsif ($timeout < 1) {
22235  
22236 return $self->scriptObj->setError(
22237 'number_NUM_out_of_range',
22238 $self->_objClass . '->implement',
22239 'NUM', $timeout,
22240 );
22241 }
22242 }
22243  
22244 # Inform the parent task that it should start waiting
22245 $self->scriptObj->parentTask->setUpMonitoring(
22246 'status',
22247 'alive',
22248 undef,
22249 $timeout,
22250 );
22251  
22252 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22253 $self->scriptObj->set_scriptStatus('wait_status');
22254  
22255 # Implementation complete
22256 return 1;
22257 }
22258 }
22259  
22260 { package Language::Axbasic::Statement::waitarrive;
22261  
22262 use strict;
22263 use warnings;
22264 use diagnostics;
22265  
22266 use Glib qw(TRUE FALSE);
22267  
22268 @Language::Axbasic::Statement::waitarrive::ISA = qw(
22269 Language::Axbasic
22270 Language::Axbasic::Statement
22271 );
22272  
22273 # WAITARRIVE [ expression ]
22274  
22275 ##################
22276 # Methods
22277  
22278 sub parse {
22279  
22280 # Called by LA::Line->parse directly after a call to LA::Statement->new
22281 #
22282 # Expected arguments
22283 # (none besides $self)
22284 #
22285 # Return values
22286 # 'undef' on improper arguments or if there is an error
22287 # 1 otherwise
22288  
22289 my ($self, $check) = @_;
22290  
22291 # Local variables
22292 my $timeoutExp;
22293  
22294 # Check for improper arguments
22295 if (defined $check) {
22296  
22297 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22298 }
22299  
22300 # Get the timeout, if specified, and convert it into an expression
22301 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22302  
22303 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22304 $self->scriptObj,
22305 $self->tokenGroupObj,
22306 );
22307  
22308 if (! defined $timeoutExp) {
22309  
22310 return $self->scriptObj->setError(
22311 'missing_or_illegal_expression',
22312 $self->_objClass . '->parse',
22313 );
22314 }
22315 }
22316  
22317 # Check that nothing follows the expression(s)
22318 if (! $self->tokenGroupObj->testStatementEnd()) {
22319  
22320 return $self->scriptObj->setError(
22321 'unexpected_keywords,_operators_or_expressions',
22322 $self->_objClass . '->parse',
22323 );
22324 }
22325  
22326 # Store the expression (if specified), so $self->implement can retrieve it
22327 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22328  
22329 # Parsing complete
22330 return 1;
22331 }
22332  
22333 sub implement {
22334  
22335 # Called by LA::Line->implement directly after a call to $self->parse
22336 #
22337 # Expected arguments
22338 # (none besides $self)
22339 #
22340 # Return values
22341 # 'undef' on improper arguments or if there is an error
22342 # 1 otherwise
22343  
22344 my ($self, $check) = @_;
22345  
22346 # Local variables
22347 my ($timeoutExp, $timeout);
22348  
22349 # Check for improper arguments
22350 if (defined $check) {
22351  
22352 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22353 }
22354  
22355 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22356 if (! $self->scriptObj->parentTask) {
22357  
22358 # Implementation complete. Execution resumes from the next statement
22359 return 1;
22360 }
22361  
22362 # Otherwise, retrieve the argument (if any) stored by $self->parse
22363 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22364  
22365 # Evaluate the expression, if specified
22366 if (defined $timeoutExp) {
22367  
22368 $timeout = $timeoutExp->evaluate();
22369  
22370 if (! ($timeout =~ /^\d+$/)) {
22371  
22372 return $self->scriptObj->setError(
22373 'invalid_integer',
22374 $self->_objClass . '->implement',
22375 );
22376  
22377 } elsif ($timeout < 1) {
22378  
22379 return $self->scriptObj->setError(
22380 'number_NUM_out_of_range',
22381 $self->_objClass . '->implement',
22382 'NUM', $timeout,
22383 );
22384 }
22385 }
22386  
22387 # Inform the parent task that it should start waiting
22388 $self->scriptObj->parentTask->setUpMonitoring(
22389 'locator',
22390 'arrive',
22391 undef,
22392 $timeout,
22393 );
22394  
22395 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22396 $self->scriptObj->set_scriptStatus('wait_status');
22397  
22398 # Implementation complete
22399 return 1;
22400 }
22401 }
22402  
22403 { package Language::Axbasic::Statement::waitdead;
22404  
22405 use strict;
22406 use warnings;
22407 use diagnostics;
22408  
22409 use Glib qw(TRUE FALSE);
22410  
22411 @Language::Axbasic::Statement::waitdead::ISA = qw(
22412 Language::Axbasic
22413 Language::Axbasic::Statement
22414 );
22415  
22416 # WAITDEAD [ expression ]
22417  
22418 ##################
22419 # Methods
22420  
22421 sub parse {
22422  
22423 # Called by LA::Line->parse directly after a call to LA::Statement->new
22424 #
22425 # Expected arguments
22426 # (none besides $self)
22427 #
22428 # Return values
22429 # 'undef' on improper arguments or if there is an error
22430 # 1 otherwise
22431  
22432 my ($self, $check) = @_;
22433  
22434 # Local variables
22435 my $timeoutExp;
22436  
22437 # Check for improper arguments
22438 if (defined $check) {
22439  
22440 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22441 }
22442  
22443 # Get the timeout, if specified, and convert it into an expression
22444 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22445  
22446 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22447 $self->scriptObj,
22448 $self->tokenGroupObj,
22449 );
22450  
22451 if (! defined $timeoutExp) {
22452  
22453 return $self->scriptObj->setError(
22454 'missing_or_illegal_expression',
22455 $self->_objClass . '->parse',
22456 );
22457 }
22458 }
22459  
22460 # Check that nothing follows the expression(s)
22461 if (! $self->tokenGroupObj->testStatementEnd()) {
22462  
22463 return $self->scriptObj->setError(
22464 'unexpected_keywords,_operators_or_expressions',
22465 $self->_objClass . '->parse',
22466 );
22467 }
22468  
22469 # Store the expression (if specified), so $self->implement can retrieve it
22470 if (defined $timeoutExp) {
22471  
22472 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22473 }
22474  
22475 # Parsing complete
22476 return 1;
22477 }
22478  
22479 sub implement {
22480  
22481 # Called by LA::Line->implement directly after a call to $self->parse
22482 #
22483 # Expected arguments
22484 # (none besides $self)
22485 #
22486 # Return values
22487 # 'undef' on improper arguments or if there is an error
22488 # 1 otherwise
22489  
22490 my ($self, $check) = @_;
22491  
22492 # Local variables
22493 my ($timeoutExp, $timeout);
22494  
22495 # Check for improper arguments
22496 if (defined $check) {
22497  
22498 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22499 }
22500  
22501 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22502 if (! $self->scriptObj->parentTask) {
22503  
22504 # Implementation complete. Execution resumes from the next statement
22505 return 1;
22506 }
22507  
22508 # Otherwise, retrieve the argument (if any) stored by $self->parse
22509 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22510  
22511 # Evaluate the expression, if specified
22512 if (defined $timeoutExp) {
22513  
22514 $timeout = $timeoutExp->evaluate();
22515  
22516 if (! ($timeout =~ /^\d+$/)) {
22517  
22518 return $self->scriptObj->setError(
22519 'invalid_integer',
22520 $self->_objClass . '->implement',
22521 );
22522  
22523 } elsif ($timeout < 1) {
22524  
22525 return $self->scriptObj->setError(
22526 'number_NUM_out_of_range',
22527 $self->_objClass . '->implement',
22528 'NUM', $timeout,
22529 );
22530 }
22531 }
22532  
22533 # Inform the parent task that it should start waiting
22534 $self->scriptObj->parentTask->setUpMonitoring(
22535 'status',
22536 'dead',
22537 undef,
22538 $timeout,
22539 );
22540  
22541 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22542 $self->scriptObj->set_scriptStatus('wait_status');
22543  
22544 # Implementation complete
22545 return 1;
22546 }
22547 }
22548  
22549 { package Language::Axbasic::Statement::waitep;
22550  
22551 use strict;
22552 use warnings;
22553 use diagnostics;
22554  
22555 use Glib qw(TRUE FALSE);
22556  
22557 @Language::Axbasic::Statement::waitep::ISA = qw(
22558 Language::Axbasic
22559 Language::Axbasic::Statement
22560 );
22561  
22562 # WAITEP expression [ , expression ]
22563  
22564 ##################
22565 # Methods
22566  
22567 sub parse {
22568  
22569 # Called by LA::Line->parse directly after a call to LA::Statement->new
22570 #
22571 # Expected arguments
22572 # (none besides $self)
22573 #
22574 # Return values
22575 # 'undef' on improper arguments or if there is an error
22576 # 1 otherwise
22577  
22578 my ($self, $check) = @_;
22579  
22580 # Local variables
22581 my ($valueExp, $timeoutExp);
22582  
22583 # Check for improper arguments
22584 if (defined $check) {
22585  
22586 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22587 }
22588  
22589 # Convert the value string into an expression
22590 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
22591 $self->scriptObj,
22592 $self->tokenGroupObj,
22593 );
22594  
22595 if (! defined $valueExp) {
22596  
22597 return $self->scriptObj->setError(
22598 'missing_or_illegal_expression',
22599 $self->_objClass . '->parse',
22600 );
22601 }
22602  
22603 # Get the timeout, if specified, and convert it into an expression
22604 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22605  
22606 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22607 $self->scriptObj,
22608 $self->tokenGroupObj,
22609 );
22610  
22611 if (! defined $timeoutExp) {
22612  
22613 return $self->scriptObj->setError(
22614 'missing_or_illegal_expression',
22615 $self->_objClass . '->parse',
22616 );
22617 }
22618 }
22619  
22620 # Check that nothing follows the expression(s)
22621 if (! $self->tokenGroupObj->testStatementEnd()) {
22622  
22623 return $self->scriptObj->setError(
22624 'unexpected_keywords,_operators_or_expressions',
22625 $self->_objClass . '->parse',
22626 );
22627 }
22628  
22629 # Store the expression(s), so $self->implement can retrieve them
22630 $self->ivAdd('parseDataHash', 'value', $valueExp);
22631 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22632  
22633 # Parsing complete
22634 return 1;
22635 }
22636  
22637 sub implement {
22638  
22639 # Called by LA::Line->implement directly after a call to $self->parse
22640 #
22641 # Expected arguments
22642 # (none besides $self)
22643 #
22644 # Return values
22645 # 'undef' on improper arguments or if there is an error
22646 # 1 otherwise
22647  
22648 my ($self, $check) = @_;
22649  
22650 # Local variables
22651 my ($valueExp, $value, $timeoutExp, $timeout);
22652  
22653 # Check for improper arguments
22654 if (defined $check) {
22655  
22656 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22657 }
22658  
22659 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22660 if (! $self->scriptObj->parentTask) {
22661  
22662 # Implementation complete. Execution resumes from the next statement
22663 return 1;
22664 }
22665  
22666 # Otherwise, retrieve the argument(s) stored by $self->parse
22667 $valueExp = $self->ivShow('parseDataHash', 'value');
22668 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22669  
22670 # Evaluate the expression(s)
22671 $value = $valueExp->evaluate();
22672 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
22673  
22674 # An illegitimate percentage, use the default value instead
22675 $value = 100;
22676 }
22677  
22678 if (defined $timeoutExp) {
22679  
22680 $timeout = $timeoutExp->evaluate();
22681  
22682 if (! ($timeout =~ /^\d+$/)) {
22683  
22684 return $self->scriptObj->setError(
22685 'invalid_integer',
22686 $self->_objClass . '->implement',
22687 );
22688  
22689 } elsif ($timeout < 1) {
22690  
22691 return $self->scriptObj->setError(
22692 'number_NUM_out_of_range',
22693 $self->_objClass . '->implement',
22694 'NUM', $timeout,
22695 );
22696 }
22697 }
22698  
22699 # Inform the parent task that it should start waiting
22700 $self->scriptObj->parentTask->setUpMonitoring(
22701 'status',
22702 'ep',
22703 $value,
22704 $timeout,
22705 );
22706  
22707 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22708 $self->scriptObj->set_scriptStatus('wait_status');
22709  
22710 # Implementation complete
22711 return 1;
22712 }
22713 }
22714  
22715 { package Language::Axbasic::Statement::waitgp;
22716  
22717 use strict;
22718 use warnings;
22719 use diagnostics;
22720  
22721 use Glib qw(TRUE FALSE);
22722  
22723 @Language::Axbasic::Statement::waitgp::ISA = qw(
22724 Language::Axbasic
22725 Language::Axbasic::Statement
22726 );
22727  
22728 # WAITGP expression [ , expression ]
22729  
22730 ##################
22731 # Methods
22732  
22733 sub parse {
22734  
22735 # Called by LA::Line->parse directly after a call to LA::Statement->new
22736 #
22737 # Expected arguments
22738 # (none besides $self)
22739 #
22740 # Return values
22741 # 'undef' on improper arguments or if there is an error
22742 # 1 otherwise
22743  
22744 my ($self, $check) = @_;
22745  
22746 # Local variables
22747 my ($valueExp, $timeoutExp);
22748  
22749 # Check for improper arguments
22750 if (defined $check) {
22751  
22752 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22753 }
22754  
22755 # Convert the value string into an expression
22756 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
22757 $self->scriptObj,
22758 $self->tokenGroupObj,
22759 );
22760  
22761 if (! defined $valueExp) {
22762  
22763 return $self->scriptObj->setError(
22764 'missing_or_illegal_expression',
22765 $self->_objClass . '->parse',
22766 );
22767 }
22768  
22769 # Get the timeout, if specified, and convert it into an expression
22770 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22771  
22772 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22773 $self->scriptObj,
22774 $self->tokenGroupObj,
22775 );
22776  
22777 if (! defined $timeoutExp) {
22778  
22779 return $self->scriptObj->setError(
22780 'missing_or_illegal_expression',
22781 $self->_objClass . '->parse',
22782 );
22783 }
22784 }
22785  
22786 # Check that nothing follows the expression(s)
22787 if (! $self->tokenGroupObj->testStatementEnd()) {
22788  
22789 return $self->scriptObj->setError(
22790 'unexpected_keywords,_operators_or_expressions',
22791 $self->_objClass . '->parse',
22792 );
22793 }
22794  
22795 # Store the expression(s), so $self->implement can retrieve them
22796 $self->ivAdd('parseDataHash', 'value', $valueExp);
22797 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22798  
22799 # Parsing complete
22800 return 1;
22801 }
22802  
22803 sub implement {
22804  
22805 # Called by LA::Line->implement directly after a call to $self->parse
22806 #
22807 # Expected arguments
22808 # (none besides $self)
22809 #
22810 # Return values
22811 # 'undef' on improper arguments or if there is an error
22812 # 1 otherwise
22813  
22814 my ($self, $check) = @_;
22815  
22816 # Local variables
22817 my ($valueExp, $value, $timeoutExp, $timeout);
22818  
22819 # Check for improper arguments
22820 if (defined $check) {
22821  
22822 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22823 }
22824  
22825 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22826 if (! $self->scriptObj->parentTask) {
22827  
22828 # Implementation complete. Execution resumes from the next statement
22829 return 1;
22830 }
22831  
22832 # Otherwise, retrieve the argument(s) stored by $self->parse
22833 $valueExp = $self->ivShow('parseDataHash', 'value');
22834 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22835  
22836 # Evaluate the expression(s)
22837 $value = $valueExp->evaluate();
22838 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
22839  
22840 # An illegitimate percentage, use the default value instead
22841 $value = 100;
22842 }
22843  
22844 if (defined $timeoutExp) {
22845  
22846 $timeout = $timeoutExp->evaluate();
22847  
22848 if (! ($timeout =~ /^\d+$/)) {
22849  
22850 return $self->scriptObj->setError(
22851 'invalid_integer',
22852 $self->_objClass . '->implement',
22853 );
22854  
22855 } elsif ($timeout < 1) {
22856  
22857 return $self->scriptObj->setError(
22858 'number_NUM_out_of_range',
22859 $self->_objClass . '->implement',
22860 'NUM', $timeout,
22861 );
22862 }
22863 }
22864  
22865 # Inform the parent task that it should start waiting
22866 $self->scriptObj->parentTask->setUpMonitoring(
22867 'status',
22868 'gp',
22869 $value,
22870 $timeout,
22871 );
22872  
22873 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22874 $self->scriptObj->set_scriptStatus('wait_status');
22875  
22876 # Implementation complete
22877 return 1;
22878 }
22879 }
22880  
22881 { package Language::Axbasic::Statement::waithook;
22882  
22883 use strict;
22884 use warnings;
22885 use diagnostics;
22886  
22887 use Glib qw(TRUE FALSE);
22888  
22889 @Language::Axbasic::Statement::waithook::ISA = qw(
22890 Language::Axbasic
22891 Language::Axbasic::Statement
22892 );
22893  
22894 # WAITHOOK expression [ , expression ]
22895  
22896 ##################
22897 # Methods
22898  
22899 sub parse {
22900  
22901 # Called by LA::Line->parse directly after a call to LA::Statement->new
22902 #
22903 # Expected arguments
22904 # (none besides $self)
22905 #
22906 # Return values
22907 # 'undef' on improper arguments or if there is an error
22908 # 1 otherwise
22909  
22910 my ($self, $check) = @_;
22911  
22912 # Check for improper arguments
22913 if (defined $check) {
22914  
22915 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22916 }
22917  
22918 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
22919 # ready for $self->implement to access
22920 if (! $self->parseWaitInterface()) {
22921  
22922 # ($self->scriptObj->setError has already been called)
22923 return undef;
22924 }
22925  
22926 # Parsing complete
22927 return 1;
22928 }
22929  
22930 sub implement {
22931  
22932 # Called by LA::Line->implement directly after a call to $self->parse
22933 #
22934 # Expected arguments
22935 # (none besides $self)
22936 #
22937 # Return values
22938 # 'undef' on improper arguments or if there is an error
22939 # 1 otherwise
22940  
22941 my ($self, $check) = @_;
22942  
22943 # Check for improper arguments
22944 if (defined $check) {
22945  
22946 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22947 }
22948  
22949 # Implement the statement, haveing parsed it
22950 if (! $self->implementWaitInterface('hook')) {
22951  
22952 # ($self->scriptObj->setError has already been called)
22953 return undef;
22954 }
22955  
22956 # Implementation complete
22957 return 1;
22958 }
22959 }
22960  
22961 { package Language::Axbasic::Statement::waithp;
22962  
22963 use strict;
22964 use warnings;
22965 use diagnostics;
22966  
22967 use Glib qw(TRUE FALSE);
22968  
22969 @Language::Axbasic::Statement::waithp::ISA = qw(
22970 Language::Axbasic
22971 Language::Axbasic::Statement
22972 );
22973  
22974 # WAITHP expression [ , expression ]
22975  
22976 ##################
22977 # Methods
22978  
22979 sub parse {
22980  
22981 # Called by LA::Line->parse directly after a call to LA::Statement->new
22982 #
22983 # Expected arguments
22984 # (none besides $self)
22985 #
22986 # Return values
22987 # 'undef' on improper arguments or if there is an error
22988 # 1 otherwise
22989  
22990 my ($self, $check) = @_;
22991  
22992 # Local variables
22993 my ($valueExp, $timeoutExp);
22994  
22995 # Check for improper arguments
22996 if (defined $check) {
22997  
22998 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22999 }
23000  
23001 # Convert the value string into an expression
23002 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
23003 $self->scriptObj,
23004 $self->tokenGroupObj,
23005 );
23006  
23007 if (! defined $valueExp) {
23008  
23009 return $self->scriptObj->setError(
23010 'missing_or_illegal_expression',
23011 $self->_objClass . '->parse',
23012 );
23013 }
23014  
23015 # Get the timeout, if specified, and convert it into an expression
23016 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23017  
23018 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23019 $self->scriptObj,
23020 $self->tokenGroupObj,
23021 );
23022  
23023 if (! defined $timeoutExp) {
23024  
23025 return $self->scriptObj->setError(
23026 'missing_or_illegal_expression',
23027 $self->_objClass . '->parse',
23028 );
23029 }
23030 }
23031  
23032 # Check that nothing follows the expression(s)
23033 if (! $self->tokenGroupObj->testStatementEnd()) {
23034  
23035 return $self->scriptObj->setError(
23036 'unexpected_keywords,_operators_or_expressions',
23037 $self->_objClass . '->parse',
23038 );
23039 }
23040  
23041 # Store the expression(s), so $self->implement can retrieve them
23042 $self->ivAdd('parseDataHash', 'value', $valueExp);
23043 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23044  
23045 # Parsing complete
23046 return 1;
23047 }
23048  
23049 sub implement {
23050  
23051 # Called by LA::Line->implement directly after a call to $self->parse
23052 #
23053 # Expected arguments
23054 # (none besides $self)
23055 #
23056 # Return values
23057 # 'undef' on improper arguments or if there is an error
23058 # 1 otherwise
23059  
23060 my ($self, $check) = @_;
23061  
23062 # Local variables
23063 my ($valueExp, $value, $timeoutExp, $timeout);
23064  
23065 # Check for improper arguments
23066 if (defined $check) {
23067  
23068 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23069 }
23070  
23071 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23072 if (! $self->scriptObj->parentTask) {
23073  
23074 # Implementation complete. Execution resumes from the next statement
23075 return 1;
23076 }
23077  
23078 # Otherwise, retrieve the argument(s) stored by $self->parse
23079 $valueExp = $self->ivShow('parseDataHash', 'value');
23080 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23081  
23082 # Evaluate the expression(s)
23083 $value = $valueExp->evaluate();
23084 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
23085  
23086 # An illegitimate percentage, use the default value instead
23087 $value = 100;
23088 }
23089  
23090 if (defined $timeoutExp) {
23091  
23092 $timeout = $timeoutExp->evaluate();
23093  
23094 if (! ($timeout =~ /^\d+$/)) {
23095  
23096 return $self->scriptObj->setError(
23097 'invalid_integer',
23098 $self->_objClass . '->implement',
23099 );
23100  
23101 } elsif ($timeout < 1) {
23102  
23103 return $self->scriptObj->setError(
23104 'number_NUM_out_of_range',
23105 $self->_objClass . '->implement',
23106 'NUM', $timeout,
23107 );
23108 }
23109 }
23110  
23111 # Inform the parent task that it should start waiting
23112 $self->scriptObj->parentTask->setUpMonitoring(
23113 'status',
23114 'hp',
23115 $value,
23116 $timeout,
23117 );
23118  
23119 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23120 $self->scriptObj->set_scriptStatus('wait_status');
23121  
23122 # Implementation complete
23123 return 1;
23124 }
23125 }
23126  
23127 { package Language::Axbasic::Statement::waitmacro;
23128  
23129 use strict;
23130 use warnings;
23131 use diagnostics;
23132  
23133 use Glib qw(TRUE FALSE);
23134  
23135 @Language::Axbasic::Statement::waitmacro::ISA = qw(
23136 Language::Axbasic
23137 Language::Axbasic::Statement
23138 );
23139  
23140 # WAITMACRO expression [ , expression ]
23141  
23142 ##################
23143 # Methods
23144  
23145 sub parse {
23146  
23147 # Called by LA::Line->parse directly after a call to LA::Statement->new
23148 #
23149 # Expected arguments
23150 # (none besides $self)
23151 #
23152 # Return values
23153 # 'undef' on improper arguments or if there is an error
23154 # 1 otherwise
23155  
23156 my ($self, $check) = @_;
23157  
23158 # Check for improper arguments
23159 if (defined $check) {
23160  
23161 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23162 }
23163  
23164 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
23165 # ready for $self->implement to access
23166 if (! $self->parseWaitInterface()) {
23167  
23168 # ($self->scriptObj->setError has already been called)
23169 return undef;
23170 }
23171  
23172 # Parsing complete
23173 return 1;
23174 }
23175  
23176 sub implement {
23177  
23178 # Called by LA::Line->implement directly after a call to $self->parse
23179 #
23180 # Expected arguments
23181 # (none besides $self)
23182 #
23183 # Return values
23184 # 'undef' on improper arguments or if there is an error
23185 # 1 otherwise
23186  
23187 my ($self, $check) = @_;
23188  
23189 # Check for improper arguments
23190 if (defined $check) {
23191  
23192 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23193 }
23194  
23195 # Implement the statement, haveing parsed it
23196 if (! $self->implementWaitInterface('macro')) {
23197  
23198 # ($self->scriptObj->setError has already been called)
23199 return undef;
23200 }
23201  
23202 # Implementation complete
23203 return 1;
23204 }
23205 }
23206  
23207 { package Language::Axbasic::Statement::waitmp;
23208  
23209 use strict;
23210 use warnings;
23211 use diagnostics;
23212  
23213 use Glib qw(TRUE FALSE);
23214  
23215 @Language::Axbasic::Statement::waitmp::ISA = qw(
23216 Language::Axbasic
23217 Language::Axbasic::Statement
23218 );
23219  
23220 # WAITMP expression [ , expression ]
23221  
23222 ##################
23223 # Methods
23224  
23225 sub parse {
23226  
23227 # Called by LA::Line->parse directly after a call to LA::Statement->new
23228 #
23229 # Expected arguments
23230 # (none besides $self)
23231 #
23232 # Return values
23233 # 'undef' on improper arguments or if there is an error
23234 # 1 otherwise
23235  
23236 my ($self, $check) = @_;
23237  
23238 # Local variables
23239 my ($valueExp, $timeoutExp);
23240  
23241 # Check for improper arguments
23242 if (defined $check) {
23243  
23244 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23245 }
23246  
23247 # Convert the value string into an expression
23248 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
23249 $self->scriptObj,
23250 $self->tokenGroupObj,
23251 );
23252  
23253 if (! defined $valueExp) {
23254  
23255 return $self->scriptObj->setError(
23256 'missing_or_illegal_expression',
23257 $self->_objClass . '->parse',
23258 );
23259 }
23260  
23261 # Get the timeout, if specified, and convert it into an expression
23262 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23263  
23264 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23265 $self->scriptObj,
23266 $self->tokenGroupObj,
23267 );
23268  
23269 if (! defined $timeoutExp) {
23270  
23271 return $self->scriptObj->setError(
23272 'missing_or_illegal_expression',
23273 $self->_objClass . '->parse',
23274 );
23275 }
23276 }
23277  
23278 # Check that nothing follows the expression(s)
23279 if (! $self->tokenGroupObj->testStatementEnd()) {
23280  
23281 return $self->scriptObj->setError(
23282 'unexpected_keywords,_operators_or_expressions',
23283 $self->_objClass . '->parse',
23284 );
23285 }
23286  
23287 # Store the expression(s), so $self->implement can retrieve them
23288 $self->ivAdd('parseDataHash', 'value', $valueExp);
23289 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23290  
23291 # Parsing complete
23292 return 1;
23293 }
23294  
23295 sub implement {
23296  
23297 # Called by LA::Line->implement directly after a call to $self->parse
23298 #
23299 # Expected arguments
23300 # (none besides $self)
23301 #
23302 # Return values
23303 # 'undef' on improper arguments or if there is an error
23304 # 1 otherwise
23305  
23306 my ($self, $check) = @_;
23307  
23308 # Local variables
23309 my ($valueExp, $value, $timeoutExp, $timeout);
23310  
23311 # Check for improper arguments
23312 if (defined $check) {
23313  
23314 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23315 }
23316  
23317 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23318 if (! $self->scriptObj->parentTask) {
23319  
23320 # Implementation complete. Execution resumes from the next statement
23321 return 1;
23322 }
23323  
23324 # Otherwise, retrieve the argument(s) stored by $self->parse
23325 $valueExp = $self->ivShow('parseDataHash', 'value');
23326 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23327  
23328 # Evaluate the expression(s)
23329 $value = $valueExp->evaluate();
23330 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
23331  
23332 # An illegitimate percentage, use the default value instead
23333 $value = 100;
23334 }
23335  
23336 if (defined $timeoutExp) {
23337  
23338 $timeout = $timeoutExp->evaluate();
23339  
23340 if (! ($timeout =~ /^\d+$/)) {
23341  
23342 return $self->scriptObj->setError(
23343 'invalid_integer',
23344 $self->_objClass . '->implement',
23345 );
23346  
23347 } elsif ($timeout < 1) {
23348  
23349 return $self->scriptObj->setError(
23350 'number_NUM_out_of_range',
23351 $self->_objClass . '->implement',
23352 'NUM', $timeout,
23353 );
23354 }
23355 }
23356  
23357 # Inform the parent task that it should start waiting
23358 $self->scriptObj->parentTask->setUpMonitoring(
23359 'status',
23360 'mp',
23361 $value,
23362 $timeout,
23363 );
23364  
23365 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23366 $self->scriptObj->set_scriptStatus('wait_status');
23367  
23368 # Implementation complete
23369 return 1;
23370 }
23371 }
23372  
23373 { package Language::Axbasic::Statement::waitnextxp;
23374  
23375 use strict;
23376 use warnings;
23377 use diagnostics;
23378  
23379 use Glib qw(TRUE FALSE);
23380  
23381 @Language::Axbasic::Statement::waitnextxp::ISA = qw(
23382 Language::Axbasic
23383 Language::Axbasic::Statement
23384 );
23385  
23386 # WAITNEXTXP expression [ , expression ]
23387  
23388 ##################
23389 # Methods
23390  
23391 sub parse {
23392  
23393 # Called by LA::Line->parse directly after a call to LA::Statement->new
23394 #
23395 # Expected arguments
23396 # (none besides $self)
23397 #
23398 # Return values
23399 # 'undef' on improper arguments or if there is an error
23400 # 1 otherwise
23401  
23402 my ($self, $check) = @_;
23403  
23404 # Local variables
23405 my ($valueExp, $timeoutExp);
23406  
23407 # Check for improper arguments
23408 if (defined $check) {
23409  
23410 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23411 }
23412  
23413 # Convert the value string into an expression
23414 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
23415 $self->scriptObj,
23416 $self->tokenGroupObj,
23417 );
23418  
23419 if (! defined $valueExp) {
23420  
23421 return $self->scriptObj->setError(
23422 'missing_or_illegal_expression',
23423 $self->_objClass . '->parse',
23424 );
23425 }
23426  
23427 # Get the timeout, if specified, and convert it into an expression
23428 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23429  
23430 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23431 $self->scriptObj,
23432 $self->tokenGroupObj,
23433 );
23434  
23435 if (! defined $timeoutExp) {
23436  
23437 return $self->scriptObj->setError(
23438 'missing_or_illegal_expression',
23439 $self->_objClass . '->parse',
23440 );
23441 }
23442 }
23443  
23444 # Check that nothing follows the expression(s)
23445 if (! $self->tokenGroupObj->testStatementEnd()) {
23446  
23447 return $self->scriptObj->setError(
23448 'unexpected_keywords,_operators_or_expressions',
23449 $self->_objClass . '->parse',
23450 );
23451 }
23452  
23453 # Store the expression(s), so $self->implement can retrieve them
23454 $self->ivAdd('parseDataHash', 'value', $valueExp);
23455 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23456  
23457 # Parsing complete
23458 return 1;
23459 }
23460  
23461 sub implement {
23462  
23463 # Called by LA::Line->implement directly after a call to $self->parse
23464 #
23465 # Expected arguments
23466 # (none besides $self)
23467 #
23468 # Return values
23469 # 'undef' on improper arguments or if there is an error
23470 # 1 otherwise
23471  
23472 my ($self, $check) = @_;
23473  
23474 # Local variables
23475 my ($valueExp, $value, $timeoutExp, $timeout);
23476  
23477 # Check for improper arguments
23478 if (defined $check) {
23479  
23480 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23481 }
23482  
23483 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23484 if (! $self->scriptObj->parentTask) {
23485  
23486 # Implementation complete. Execution resumes from the next statement
23487 return 1;
23488 }
23489  
23490 # Otherwise, retrieve the argument(s) stored by $self->parse
23491 $valueExp = $self->ivShow('parseDataHash', 'value');
23492 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23493  
23494 # Evaluate the expression(s)
23495 $value = $valueExp->evaluate();
23496 if (! ($value =~ /^\d+$/)) {
23497  
23498 return $self->scriptObj->setError(
23499 'invalid_integer',
23500 $self->_objClass . '->parse',
23501 );
23502 }
23503  
23504 if (defined $timeoutExp) {
23505  
23506 $timeout = $timeoutExp->evaluate();
23507  
23508 if (! ($timeout =~ /^\d+$/)) {
23509  
23510 return $self->scriptObj->setError(
23511 'invalid_integer',
23512 $self->_objClass . '->implement',
23513 );
23514  
23515 } elsif ($timeout < 1) {
23516  
23517 return $self->scriptObj->setError(
23518 'number_NUM_out_of_range',
23519 $self->_objClass . '->implement',
23520 'NUM', $timeout,
23521 );
23522 }
23523 }
23524  
23525 # Inform the parent task that it should start waiting
23526 $self->scriptObj->parentTask->setUpMonitoring(
23527 'status',
23528 'xp_next_level',
23529 $value,
23530 $timeout,
23531 );
23532  
23533 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23534 $self->scriptObj->set_scriptStatus('wait_status');
23535  
23536 # Implementation complete
23537 return 1;
23538 }
23539 }
23540  
23541 { package Language::Axbasic::Statement::waitnotactive;
23542  
23543 use strict;
23544 use warnings;
23545 use diagnostics;
23546  
23547 use Glib qw(TRUE FALSE);
23548  
23549 @Language::Axbasic::Statement::waitnotactive::ISA = qw(
23550 Language::Axbasic
23551 Language::Axbasic::Statement
23552 );
23553  
23554 # WAITNOTACTIVE expression
23555  
23556 ##################
23557 # Methods
23558  
23559 sub parse {
23560  
23561 # Called by LA::Line->parse directly after a call to LA::Statement->new
23562 #
23563 # Expected arguments
23564 # (none besides $self)
23565 #
23566 # Return values
23567 # 'undef' on improper arguments or if there is an error
23568 # 1 otherwise
23569  
23570 my ($self, $check) = @_;
23571  
23572 # Local variables
23573 my $taskNameExp;
23574  
23575 # Check for improper arguments
23576 if (defined $check) {
23577  
23578 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23579 }
23580  
23581 # Convert the task string into an expression
23582 $taskNameExp = Language::Axbasic::Expression::Arithmetic->new(
23583 $self->scriptObj,
23584 $self->tokenGroupObj,
23585 );
23586  
23587 if (! defined $taskNameExp) {
23588  
23589 return $self->scriptObj->setError(
23590 'missing_or_illegal_expression',
23591 $self->_objClass . '->parse',
23592 );
23593 }
23594  
23595 # Check that nothing follows the expression(s)
23596 if (! $self->tokenGroupObj->testStatementEnd()) {
23597  
23598 return $self->scriptObj->setError(
23599 'unexpected_keywords,_operators_or_expressions',
23600 $self->_objClass . '->parse',
23601 );
23602 }
23603  
23604 # Store the expression, so $self->implement can retrieve it
23605 $self->ivAdd('parseDataHash', 'task_name', $taskNameExp);
23606  
23607 # Parsing complete
23608 return 1;
23609 }
23610  
23611 sub implement {
23612  
23613 # Called by LA::Line->implement directly after a call to $self->parse
23614 #
23615 # Expected arguments
23616 # (none besides $self)
23617 #
23618 # Return values
23619 # 'undef' on improper arguments or if there is an error
23620 # 1 otherwise
23621  
23622 my ($self, $check) = @_;
23623  
23624 # Local variables
23625 my ($taskNameExp, $taskName, $taskObj);
23626  
23627 # Check for improper arguments
23628 if (defined $check) {
23629  
23630 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23631 }
23632  
23633 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23634 if (! $self->scriptObj->parentTask) {
23635  
23636 # Implementation complete. Execution resumes from the next statement
23637 return 1;
23638 }
23639  
23640 # Otherwise, retrieve the argument stored by $self->parse
23641 $taskNameExp = $self->ivShow('parseDataHash', 'task_name');
23642  
23643 # Evaluate the expression(s)
23644 $taskName = $taskNameExp->evaluate();
23645  
23646 # Look for a task matching $taskName. GA::Generic::Cmd->findTask recognises task labels
23647 # (stored in GA::Client->taskLabelHash), tasks' formal names (stored in
23648 # GA::Client->taskPackageHash), or task unique names in the current tasklist (stored in
23649 # GA::Session->currentTaskHash)
23650 ($taskObj) = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $taskName);
23651 if (! $taskObj) {
23652  
23653 # No matching task in the current tasklist
23654 return $self->scriptObj->setError(
23655 'WAITACTIVE_operation_failure',
23656 $self->_objClass . '->parse',
23657 );
23658 }
23659  
23660 # Inform the LA::Script's parent task that it should start waiting
23661 $self->scriptObj->parentTask->setUpMonitoring('task_not_active', $taskObj->uniqueName);
23662  
23663 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23664 $self->scriptObj->set_scriptStatus('wait_not_active');
23665  
23666 # Implementation complete
23667 return 1;
23668 }
23669 }
23670  
23671 { package Language::Axbasic::Statement::waitpassout;
23672  
23673 use strict;
23674 use warnings;
23675 use diagnostics;
23676  
23677 use Glib qw(TRUE FALSE);
23678  
23679 @Language::Axbasic::Statement::waitpassout::ISA = qw(
23680 Language::Axbasic
23681 Language::Axbasic::Statement
23682 );
23683  
23684 # WAITPASSOUT [ expression ]
23685  
23686 ##################
23687 # Methods
23688  
23689 sub parse {
23690  
23691 # Called by LA::Line->parse directly after a call to LA::Statement->new
23692 #
23693 # Expected arguments
23694 # (none besides $self)
23695 #
23696 # Return values
23697 # 'undef' on improper arguments or if there is an error
23698 # 1 otherwise
23699  
23700 my ($self, $check) = @_;
23701  
23702 # Local variables
23703 my $timeoutExp;
23704  
23705 # Check for improper arguments
23706 if (defined $check) {
23707  
23708 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23709 }
23710  
23711 # Get the timeout, if specified, and convert it into an expression
23712 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23713  
23714 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23715 $self->scriptObj,
23716 $self->tokenGroupObj,
23717 );
23718  
23719 if (! defined $timeoutExp) {
23720  
23721 return $self->scriptObj->setError(
23722 'missing_or_illegal_expression',
23723 $self->_objClass . '->parse',
23724 );
23725 }
23726 }
23727  
23728 # Check that nothing follows the expression(s)
23729 if (! $self->tokenGroupObj->testStatementEnd()) {
23730  
23731 return $self->scriptObj->setError(
23732 'unexpected_keywords,_operators_or_expressions',
23733 $self->_objClass . '->parse',
23734 );
23735 }
23736  
23737 # Store the expression (if specified), so $self->implement can retrieve it
23738 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23739  
23740 # Parsing complete
23741 return 1;
23742 }
23743  
23744 sub implement {
23745  
23746 # Called by LA::Line->implement directly after a call to $self->parse
23747 #
23748 # Expected arguments
23749 # (none besides $self)
23750 #
23751 # Return values
23752 # 'undef' on improper arguments or if there is an error
23753 # 1 otherwise
23754  
23755 my ($self, $check) = @_;
23756  
23757 # Local variables
23758 my ($timeoutExp, $timeout);
23759  
23760 # Check for improper arguments
23761 if (defined $check) {
23762  
23763 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23764 }
23765  
23766 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23767 if (! $self->scriptObj->parentTask) {
23768  
23769 # Implementation complete. Execution resumes from the next statement
23770 return 1;
23771 }
23772  
23773 # Otherwise, retrieve the argument (if any) stored by $self->parse
23774 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23775  
23776 # Evaluate the expression, if specified
23777 if (defined $timeoutExp) {
23778  
23779 $timeout = $timeoutExp->evaluate();
23780  
23781 if (! ($timeout =~ /^\d+$/)) {
23782  
23783 return $self->scriptObj->setError(
23784 'invalid_integer',
23785 $self->_objClass . '->implement',
23786 );
23787  
23788 } elsif ($timeout < 1) {
23789  
23790 return $self->scriptObj->setError(
23791 'number_NUM_out_of_range',
23792 $self->_objClass . '->implement',
23793 'NUM', $timeout,
23794 );
23795 }
23796 }
23797  
23798 # Inform the parent task that it should start waiting
23799 $self->scriptObj->parentTask->setUpMonitoring(
23800 'status',
23801 'passout',
23802 undef,
23803 $timeout,
23804 );
23805  
23806 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23807 $self->scriptObj->set_scriptStatus('wait_status');
23808  
23809 # Implementation complete
23810 return 1;
23811 }
23812 }
23813  
23814 { package Language::Axbasic::Statement::waitscript;
23815  
23816 use strict;
23817 use warnings;
23818 use diagnostics;
23819  
23820 use Glib qw(TRUE FALSE);
23821  
23822 @Language::Axbasic::Statement::waitscript::ISA = qw(
23823 Language::Axbasic
23824 Language::Axbasic::Statement
23825 );
23826  
23827 # WAITSCRIPT expression
23828  
23829 ##################
23830 # Methods
23831  
23832 sub parse {
23833  
23834 # Called by LA::Line->parse directly after a call to LA::Statement->new
23835 #
23836 # Expected arguments
23837 # (none besides $self)
23838 #
23839 # Return values
23840 # 'undef' on improper arguments or if there is an error
23841 # 1 otherwise
23842  
23843 my ($self, $check) = @_;
23844  
23845 # Local variables
23846 my $scriptNameExp;
23847  
23848 # Check for improper arguments
23849 if (defined $check) {
23850  
23851 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23852 }
23853  
23854 # Convert the task string into an expression
23855 $scriptNameExp = Language::Axbasic::Expression::Arithmetic->new(
23856 $self->scriptObj,
23857 $self->tokenGroupObj,
23858 );
23859  
23860 if (! defined $scriptNameExp) {
23861  
23862 return $self->scriptObj->setError(
23863 'missing_or_illegal_expression ',
23864 $self->_objClass . '->parse',
23865 );
23866 }
23867  
23868 # Check that nothing follows the expression(s)
23869 if (! $self->tokenGroupObj->testStatementEnd()) {
23870  
23871 return $self->scriptObj->setError(
23872 'unexpected_keywords,_operators_or_expressions',
23873 $self->_objClass . '->parse',
23874 );
23875 }
23876  
23877 # Store the expression, so $self->implement can retrieve it
23878 $self->ivAdd('parseDataHash', 'script_exp', $scriptNameExp);
23879  
23880 # Parsing complete
23881 return 1;
23882 }
23883  
23884 sub implement {
23885  
23886 # Called by LA::Line->implement directly after a call to $self->parse
23887 #
23888 # Expected arguments
23889 # (none besides $self)
23890 #
23891 # Return values
23892 # 'undef' on improper arguments or if there is an error
23893 # 1 otherwise
23894  
23895 my ($self, $check) = @_;
23896  
23897 # Local variables
23898 my ($scriptNameExp, $scriptName, $packageName, $taskObj);
23899  
23900 # Check for improper arguments
23901 if (defined $check) {
23902  
23903 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23904 }
23905  
23906 # If this Axbasic script isn't being run from within an Axmud task, ignore the statement
23907 if (! $self->scriptObj->parentTask) {
23908  
23909 # Implementation complete. Execution resumes from the next statement
23910 return 1;
23911 }
23912  
23913 # Otherwise, retrieve the argument stored by $self->parse
23914 $scriptNameExp = $self->ivShow('parseDataHash', 'script_exp');
23915 # Evaluate the expression(s)
23916 $scriptName = $scriptNameExp->evaluate();
23917  
23918 # Create the new Script task object
23919 $taskObj = Games::Axmud::Task::Script->new($self->scriptObj->session, 'current');
23920 if (! $taskObj) {
23921  
23922 # If the new task can't be created, it's a fatal error
23923 return $self->scriptObj->setError(
23924 'WAITSCRIPT_operation_failure',
23925 $self->_objClass . '->parse',
23926 );
23927 }
23928  
23929 # Tell the new task which Axbasic script to run
23930 $taskObj->ivPoke('scriptName', $scriptName);
23931  
23932 # Inform the LA::Script's parent task that it should start waiting
23933 $self->scriptObj->parentTask->setUpMonitoring('task', $taskObj->uniqueName);
23934  
23935 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23936 $self->scriptObj->set_scriptStatus('wait_status');
23937  
23938 # Implementation complete
23939 return 1;
23940 }
23941 }
23942  
23943 { package Language::Axbasic::Statement::waitsleep;
23944  
23945 use strict;
23946 use warnings;
23947 use diagnostics;
23948  
23949 use Glib qw(TRUE FALSE);
23950  
23951 @Language::Axbasic::Statement::waitsleep::ISA = qw(
23952 Language::Axbasic
23953 Language::Axbasic::Statement
23954 );
23955  
23956 # WAITSLEEP [ expression ]
23957  
23958 ##################
23959 # Methods
23960  
23961 sub parse {
23962  
23963 # Called by LA::Line->parse directly after a call to LA::Statement->new
23964 #
23965 # Expected arguments
23966 # (none besides $self)
23967 #
23968 # Return values
23969 # 'undef' on improper arguments or if there is an error
23970 # 1 otherwise
23971  
23972 my ($self, $check) = @_;
23973  
23974 # Local variables
23975 my $timeoutExp;
23976  
23977 # Check for improper arguments
23978 if (defined $check) {
23979  
23980 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23981 }
23982  
23983 # Get the timeout, if specified, and convert it into an expression
23984 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23985  
23986 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23987 $self->scriptObj,
23988 $self->tokenGroupObj,
23989 );
23990  
23991 if (! defined $timeoutExp) {
23992  
23993 return $self->scriptObj->setError(
23994 'missing_or_illegal_expression',
23995 $self->_objClass . '->parse',
23996 );
23997 }
23998 }
23999  
24000 # Check that nothing follows the expression(s)
24001 if (! $self->tokenGroupObj->testStatementEnd()) {
24002  
24003 return $self->scriptObj->setError(
24004 'unexpected_keywords,_operators_or_expressions',
24005 $self->_objClass . '->parse',
24006 );
24007 }
24008  
24009 # Store the expression (if specified), so $self->implement can retrieve it
24010 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24011  
24012 # Parsing complete
24013 return 1;
24014 }
24015  
24016 sub implement {
24017  
24018 # Called by LA::Line->implement directly after a call to $self->parse
24019 #
24020 # Expected arguments
24021 # (none besides $self)
24022 #
24023 # Return values
24024 # 'undef' on improper arguments or if there is an error
24025 # 1 otherwise
24026  
24027 my ($self, $check) = @_;
24028  
24029 # Local variables
24030 my ($timeoutExp, $timeout);
24031  
24032 # Check for improper arguments
24033 if (defined $check) {
24034  
24035 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24036 }
24037  
24038 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24039 if (! $self->scriptObj->parentTask) {
24040  
24041 # Implementation complete. Execution resumes from the next statement
24042 return 1;
24043 }
24044  
24045 # Otherwise, retrieve the argument (if any) stored by $self->parse
24046 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24047  
24048 # Evaluate the expression, if specified
24049 if (defined $timeoutExp) {
24050  
24051 $timeout = $timeoutExp->evaluate();
24052  
24053 if (! ($timeout =~ /^\d+$/)) {
24054  
24055 return $self->scriptObj->setError(
24056 'invalid_integer',
24057 $self->_objClass . '->implement',
24058 );
24059  
24060 } elsif ($timeout < 1) {
24061  
24062 return $self->scriptObj->setError(
24063 'number_NUM_out_of_range',
24064 $self->_objClass . '->implement',
24065 'NUM', $timeout,
24066 );
24067 }
24068 }
24069  
24070 # Inform the parent task that it should start waiting
24071 $self->scriptObj->parentTask->setUpMonitoring(
24072 'status',
24073 'sleep',
24074 undef,
24075 $timeout,
24076 );
24077  
24078 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24079 $self->scriptObj->set_scriptStatus('wait_status');
24080  
24081 # Implementation complete
24082 return 1;
24083 }
24084 }
24085  
24086 { package Language::Axbasic::Statement::waitsp;
24087  
24088 use strict;
24089 use warnings;
24090 use diagnostics;
24091  
24092 use Glib qw(TRUE FALSE);
24093  
24094 @Language::Axbasic::Statement::waitsp::ISA = qw(
24095 Language::Axbasic
24096 Language::Axbasic::Statement
24097 );
24098  
24099 # WAITSP expression [ , expression ]
24100  
24101 ##################
24102 # Methods
24103  
24104 sub parse {
24105  
24106 # Called by LA::Line->parse directly after a call to LA::Statement->new
24107 #
24108 # Expected arguments
24109 # (none besides $self)
24110 #
24111 # Return values
24112 # 'undef' on improper arguments or if there is an error
24113 # 1 otherwise
24114  
24115 my ($self, $check) = @_;
24116  
24117 # Local variables
24118 my ($valueExp, $timeoutExp);
24119  
24120 # Check for improper arguments
24121 if (defined $check) {
24122  
24123 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24124 }
24125  
24126 # Convert the value string into an expression
24127 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
24128 $self->scriptObj,
24129 $self->tokenGroupObj,
24130 );
24131  
24132 if (! defined $valueExp) {
24133  
24134 return $self->scriptObj->setError(
24135 'missing_or_illegal_expression',
24136 $self->_objClass . '->parse',
24137 );
24138 }
24139  
24140 # Get the timeout, if specified, and convert it into an expression
24141 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24142  
24143 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24144 $self->scriptObj,
24145 $self->tokenGroupObj,
24146 );
24147  
24148 if (! defined $timeoutExp) {
24149  
24150 return $self->scriptObj->setError(
24151 'missing_or_illegal_expression',
24152 $self->_objClass . '->parse',
24153 );
24154 }
24155 }
24156  
24157 # Check that nothing follows the expression(s)
24158 if (! $self->tokenGroupObj->testStatementEnd()) {
24159  
24160 return $self->scriptObj->setError(
24161 'unexpected_keywords,_operators_or_expressions',
24162 $self->_objClass . '->parse',
24163 );
24164 }
24165  
24166 # Store the expression(s), so $self->implement can retrieve them
24167 $self->ivAdd('parseDataHash', 'value', $valueExp);
24168 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24169  
24170 # Parsing complete
24171 return 1;
24172 }
24173  
24174 sub implement {
24175  
24176 # Called by LA::Line->implement directly after a call to $self->parse
24177 #
24178 # Expected arguments
24179 # (none besides $self)
24180 #
24181 # Return values
24182 # 'undef' on improper arguments or if there is an error
24183 # 1 otherwise
24184  
24185 my ($self, $check) = @_;
24186  
24187 # Local variables
24188 my ($valueExp, $value, $timeoutExp, $timeout);
24189  
24190 # Check for improper arguments
24191 if (defined $check) {
24192  
24193 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24194 }
24195  
24196 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24197 if (! $self->scriptObj->parentTask) {
24198  
24199 # Implementation complete. Execution resumes from the next statement
24200 return 1;
24201 }
24202  
24203 # Otherwise, retrieve the argument(s) stored by $self->parse
24204 $valueExp = $self->ivShow('parseDataHash', 'value');
24205 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24206  
24207 # Evaluate the expression(s)
24208 $value = $valueExp->evaluate();
24209 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
24210  
24211 # An illegitimate percentage, use the default value instead
24212 $value = 100;
24213 }
24214  
24215 if (defined $timeoutExp) {
24216  
24217 $timeout = $timeoutExp->evaluate();
24218  
24219 if (! ($timeout =~ /^\d+$/)) {
24220  
24221 return $self->scriptObj->setError(
24222 'invalid_integer',
24223 $self->_objClass . '->implement',
24224 );
24225  
24226 } elsif ($timeout < 1) {
24227  
24228 return $self->scriptObj->setError(
24229 'number_NUM_out_of_range',
24230 $self->_objClass . '->implement',
24231 'NUM', $timeout,
24232 );
24233 }
24234 }
24235  
24236 # Inform the parent task that it should start waiting
24237 $self->scriptObj->parentTask->setUpMonitoring(
24238 'status',
24239 'sp',
24240 $value,
24241 $timeout,
24242 );
24243  
24244 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24245 $self->scriptObj->set_scriptStatus('wait_status');
24246  
24247 # Implementation complete
24248 return 1;
24249 }
24250 }
24251  
24252 { package Language::Axbasic::Statement::waittask;
24253  
24254 use strict;
24255 use warnings;
24256 use diagnostics;
24257  
24258 use Glib qw(TRUE FALSE);
24259  
24260 @Language::Axbasic::Statement::waittask::ISA = qw(
24261 Language::Axbasic
24262 Language::Axbasic::Statement
24263 );
24264  
24265 # WAITTASK expression
24266  
24267 ##################
24268 # Methods
24269  
24270 sub parse {
24271  
24272 # Called by LA::Line->parse directly after a call to LA::Statement->new
24273 #
24274 # Expected arguments
24275 # (none besides $self)
24276 #
24277 # Return values
24278 # 'undef' on improper arguments or if there is an error
24279 # 1 otherwise
24280  
24281 my ($self, $check) = @_;
24282  
24283 # Local variables
24284 my $taskNameExp;
24285  
24286 # Check for improper arguments
24287 if (defined $check) {
24288  
24289 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24290 }
24291  
24292 # Convert the task string into an expression
24293 $taskNameExp = Language::Axbasic::Expression::Arithmetic->new(
24294 $self->scriptObj,
24295 $self->tokenGroupObj,
24296 );
24297  
24298 if (! defined $taskNameExp) {
24299  
24300 return $self->scriptObj->setError(
24301 'missing_or_illegal_expression',
24302 $self->_objClass . '->parse',
24303 );
24304 }
24305  
24306 # Check that nothing follows the expression(s)
24307 if (! $self->tokenGroupObj->testStatementEnd()) {
24308  
24309 return $self->scriptObj->setError(
24310 'unexpected_keywords,_operators_or_expressions',
24311 $self->_objClass . '->parse',
24312 );
24313 }
24314  
24315 # Store the expression, so $self->implement can retrieve it
24316 $self->ivAdd('parseDataHash', 'task_name', $taskNameExp);
24317  
24318 # Parsing complete
24319 return 1;
24320 }
24321  
24322 sub implement {
24323  
24324 # Called by LA::Line->implement directly after a call to $self->parse
24325 #
24326 # Expected arguments
24327 # (none besides $self)
24328 #
24329 # Return values
24330 # 'undef' on improper arguments or if there is an error
24331 # 1 otherwise
24332  
24333 my ($self, $check) = @_;
24334  
24335 # Local variables
24336 my ($taskNameExp, $taskName, $packageName, $taskObj);
24337  
24338 # Check for improper arguments
24339 if (defined $check) {
24340  
24341 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24342 }
24343  
24344 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24345 if (! $self->scriptObj->parentTask) {
24346  
24347 # Implementation complete. Execution resumes from the next statement
24348 return 1;
24349 }
24350  
24351 # Otherwise, retrieve the argument stored by $self->parse
24352 $taskNameExp = $self->ivShow('parseDataHash', 'task_name');
24353  
24354 # Evaluate the expression(s)
24355 $taskName = $taskNameExp->evaluate();
24356  
24357 # The rest of this code is adapted from GA::Cmd::StartTask
24358 # GA::Generic::Cmd->findTaskPackageName recognises unique names of currently running tasks
24359 # (e.g. 'status_task_57'), so before we consult it, check that a task called $taskName
24360 # isn't already running
24361 if ($self->scriptObj->session->ivExists('currentTaskHash', $taskName)) {
24362  
24363 return $self->scriptObj->setError(
24364 'WAITTASK_operation_failure',
24365 $self->_objClass . '->parse',
24366 );
24367 }
24368  
24369 # Get the package name corresponding to $taskName (e.g. 'Games::Axmud::Task::Status',
24370 # 'Games::Axmud::Task::Divert')
24371 $packageName
24372 = Games::Axmud::Generic::Cmd->findTaskPackageName($self->scriptObj->session, $taskName);
24373  
24374 if (! defined $packageName) {
24375  
24376 return $self->scriptObj->setError(
24377 'WAITTASK_operation_failure',
24378 $self->_objClass . '->parse',
24379 );
24380 }
24381  
24382 # Create the new task object
24383 $taskObj = $packageName->new($self->scriptObj->session, 'current');
24384 if (! $taskObj) {
24385  
24386 # If the new task can't be created and set up properly, it's a fatal error
24387 return $self->scriptObj->setError(
24388 'WAITTASK_operation_failure',
24389 $self->_objClass . '->parse',
24390 'STRING', $taskName,
24391 );
24392 }
24393  
24394 # Inform the LA::Script's parent task that it should start waiting
24395 $self->scriptObj->parentTask->setUpMonitoring('task', $taskObj->uniqueName);
24396  
24397 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24398 $self->scriptObj->set_scriptStatus('wait_status');
24399  
24400 # Implementation complete
24401 return 1;
24402 }
24403 }
24404  
24405 { package Language::Axbasic::Statement::waittimer;
24406  
24407 use strict;
24408 use warnings;
24409 use diagnostics;
24410  
24411 use Glib qw(TRUE FALSE);
24412  
24413 @Language::Axbasic::Statement::waittimer::ISA = qw(
24414 Language::Axbasic
24415 Language::Axbasic::Statement
24416 );
24417  
24418 # WAITTIMER expression [ , expression ]
24419  
24420 ##################
24421 # Methods
24422  
24423 sub parse {
24424  
24425 # Called by LA::Line->parse directly after a call to LA::Statement->new
24426 #
24427 # Expected arguments
24428 # (none besides $self)
24429 #
24430 # Return values
24431 # 'undef' on improper arguments or if there is an error
24432 # 1 otherwise
24433  
24434 my ($self, $check) = @_;
24435  
24436 # Check for improper arguments
24437 if (defined $check) {
24438  
24439 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24440 }
24441  
24442 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
24443 # ready for $self->implement to access
24444 if (! $self->parseWaitInterface()) {
24445  
24446 # ($self->scriptObj->setError has already been called)
24447 return undef;
24448 }
24449  
24450 # Parsing complete
24451 return 1;
24452 }
24453  
24454 sub implement {
24455  
24456 # Called by LA::Line->implement directly after a call to $self->parse
24457 #
24458 # Expected arguments
24459 # (none besides $self)
24460 #
24461 # Return values
24462 # 'undef' on improper arguments or if there is an error
24463 # 1 otherwise
24464  
24465 my ($self, $check) = @_;
24466  
24467 # Check for improper arguments
24468 if (defined $check) {
24469  
24470 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24471 }
24472  
24473 # Implement the statement, haveing parsed it
24474 if (! $self->implementWaitInterface('timer')) {
24475  
24476 # ($self->scriptObj->setError has already been called)
24477 return undef;
24478 }
24479  
24480 # Implementation complete
24481 return 1;
24482 }
24483 }
24484  
24485 { package Language::Axbasic::Statement::waittotalxp;
24486  
24487 use strict;
24488 use warnings;
24489 use diagnostics;
24490  
24491 use Glib qw(TRUE FALSE);
24492  
24493 @Language::Axbasic::Statement::waittotalxp::ISA = qw(
24494 Language::Axbasic
24495 Language::Axbasic::Statement
24496 );
24497  
24498 # WAITTOTALXP expression [ , expression ]
24499  
24500 ##################
24501 # Methods
24502  
24503 sub parse {
24504  
24505 # Called by LA::Line->parse directly after a call to LA::Statement->new
24506 #
24507 # Expected arguments
24508 # (none besides $self)
24509 #
24510 # Return values
24511 # 'undef' on improper arguments or if there is an error
24512 # 1 otherwise
24513  
24514 my ($self, $check) = @_;
24515  
24516 # Local variables
24517 my ($valueExp, $timeoutExp);
24518  
24519 # Check for improper arguments
24520 if (defined $check) {
24521  
24522 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24523 }
24524  
24525 # Convert the value string into an expression
24526 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
24527 $self->scriptObj,
24528 $self->tokenGroupObj,
24529 );
24530  
24531 if (! defined $valueExp) {
24532  
24533 return $self->scriptObj->setError(
24534 'missing_or_illegal_expression',
24535 $self->_objClass . '->parse',
24536 );
24537 }
24538  
24539 # Get the timeout, if specified, and convert it into an expression
24540 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24541  
24542 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24543 $self->scriptObj,
24544 $self->tokenGroupObj,
24545 );
24546  
24547 if (! defined $timeoutExp) {
24548  
24549 return $self->scriptObj->setError(
24550 'missing_or_illegal_expression',
24551 $self->_objClass . '->parse',
24552 );
24553 }
24554 }
24555  
24556 # Check that nothing follows the expression(s)
24557 if (! $self->tokenGroupObj->testStatementEnd()) {
24558  
24559 return $self->scriptObj->setError(
24560 'unexpected_keywords,_operators_or_expressions',
24561 $self->_objClass . '->parse',
24562 );
24563 }
24564  
24565 # Store the expression(s), so $self->implement can retrieve them
24566 $self->ivAdd('parseDataHash', 'value', $valueExp);
24567 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24568  
24569 # Parsing complete
24570 return 1;
24571 }
24572  
24573 sub implement {
24574  
24575 # Called by LA::Line->implement directly after a call to $self->parse
24576 #
24577 # Expected arguments
24578 # (none besides $self)
24579 #
24580 # Return values
24581 # 'undef' on improper arguments or if there is an error
24582 # 1 otherwise
24583  
24584 my ($self, $check) = @_;
24585  
24586 # Local variables
24587 my ($valueExp, $value, $timeoutExp, $timeout);
24588  
24589 # Check for improper arguments
24590 if (defined $check) {
24591  
24592 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24593 }
24594  
24595 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24596 if (! $self->scriptObj->parentTask) {
24597  
24598 # Implementation complete. Execution resumes from the next statement
24599 return 1;
24600 }
24601  
24602 # Otherwise, retrieve the argument(s) stored by $self->parse
24603 $valueExp = $self->ivShow('parseDataHash', 'value');
24604 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24605  
24606 # Evaluate the expression(s)
24607 $value = $valueExp->evaluate();
24608 if (! ($value =~ /^\d+$/)) {
24609  
24610 return $self->scriptObj->setError(
24611 'invalid_integer',
24612 $self->_objClass . '->parse',
24613 );
24614 }
24615  
24616 if (defined $timeoutExp) {
24617  
24618 $timeout = $timeoutExp->evaluate();
24619  
24620 if (! ($timeout =~ /^\d+$/)) {
24621  
24622 return $self->scriptObj->setError(
24623 'invalid_integer',
24624 $self->_objClass . '->implement',
24625 );
24626  
24627 } elsif ($timeout < 1) {
24628  
24629 return $self->scriptObj->setError(
24630 'number_NUM_out_of_range',
24631 $self->_objClass . '->implement',
24632 'NUM', $timeout,
24633 );
24634 }
24635 }
24636  
24637 # Inform the parent task that it should start waiting
24638 $self->scriptObj->parentTask->setUpMonitoring(
24639 'status',
24640 'xp_total',
24641 $value,
24642 $timeout,
24643 );
24644  
24645 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24646 $self->scriptObj->set_scriptStatus('wait_status');
24647  
24648 # Implementation complete
24649 return 1;
24650 }
24651 }
24652  
24653 { package Language::Axbasic::Statement::waittrig;
24654  
24655 use strict;
24656 use warnings;
24657 use diagnostics;
24658  
24659 use Glib qw(TRUE FALSE);
24660  
24661 @Language::Axbasic::Statement::waittrig::ISA = qw(
24662 Language::Axbasic
24663 Language::Axbasic::Statement
24664 );
24665  
24666 # WAITTRIG expression [ , expression ]
24667  
24668 ##################
24669 # Methods
24670  
24671 sub parse {
24672  
24673 # Called by LA::Line->parse directly after a call to LA::Statement->new
24674 #
24675 # Expected arguments
24676 # (none besides $self)
24677 #
24678 # Return values
24679 # 'undef' on improper arguments or if there is an error
24680 # 1 otherwise
24681  
24682 my ($self, $check) = @_;
24683  
24684 # Check for improper arguments
24685 if (defined $check) {
24686  
24687 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24688 }
24689  
24690 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
24691 # ready for $self->implement to access
24692 if (! $self->parseWaitInterface()) {
24693  
24694 # ($self->scriptObj->setError has already been called)
24695 return undef;
24696 }
24697  
24698 # Parsing complete
24699 return 1;
24700 }
24701  
24702 sub implement {
24703  
24704 # Called by LA::Line->implement directly after a call to $self->parse
24705 #
24706 # Expected arguments
24707 # (none besides $self)
24708 #
24709 # Return values
24710 # 'undef' on improper arguments or if there is an error
24711 # 1 otherwise
24712  
24713 my ($self, $check) = @_;
24714  
24715 # Check for improper arguments
24716 if (defined $check) {
24717  
24718 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24719 }
24720  
24721 # Implement the statement, haveing parsed it
24722 if (! $self->implementWaitInterface('trigger')) {
24723  
24724 # ($self->scriptObj->setError has already been called)
24725 return undef;
24726 }
24727  
24728 # Implementation complete
24729 return 1;
24730 }
24731 }
24732  
24733 { package Language::Axbasic::Statement::waitxp;
24734  
24735 use strict;
24736 use warnings;
24737 use diagnostics;
24738  
24739 use Glib qw(TRUE FALSE);
24740  
24741 @Language::Axbasic::Statement::waitxp::ISA = qw(
24742 Language::Axbasic
24743 Language::Axbasic::Statement
24744 );
24745  
24746 # WAITXP expression [ , expression ]
24747  
24748 ##################
24749 # Methods
24750  
24751 sub parse {
24752  
24753 # Called by LA::Line->parse directly after a call to LA::Statement->new
24754 #
24755 # Expected arguments
24756 # (none besides $self)
24757 #
24758 # Return values
24759 # 'undef' on improper arguments or if there is an error
24760 # 1 otherwise
24761  
24762 my ($self, $check) = @_;
24763  
24764 # Local variables
24765 my ($valueExp, $timeoutExp);
24766  
24767 # Check for improper arguments
24768 if (defined $check) {
24769  
24770 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24771 }
24772  
24773 # Convert the value string into an expression
24774 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
24775 $self->scriptObj,
24776 $self->tokenGroupObj,
24777 );
24778  
24779 if (! defined $valueExp) {
24780  
24781 return $self->scriptObj->setError(
24782 'missing_or_illegal_expression',
24783 $self->_objClass . '->parse',
24784 );
24785 }
24786  
24787 # Get the timeout, if specified, and convert it into an expression
24788 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24789  
24790 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24791 $self->scriptObj,
24792 $self->tokenGroupObj,
24793 );
24794  
24795 if (! defined $timeoutExp) {
24796  
24797 return $self->scriptObj->setError(
24798 'missing_or_illegal_expression',
24799 $self->_objClass . '->parse',
24800 );
24801 }
24802 }
24803  
24804 # Check that nothing follows the expression(s)
24805 if (! $self->tokenGroupObj->testStatementEnd()) {
24806  
24807 return $self->scriptObj->setError(
24808 'unexpected_keywords,_operators_or_expressions',
24809 $self->_objClass . '->parse',
24810 );
24811 }
24812  
24813 # Store the expression(s), so $self->implement can retrieve them
24814 $self->ivAdd('parseDataHash', 'value', $valueExp);
24815 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24816  
24817 # Parsing complete
24818 return 1;
24819 }
24820  
24821 sub implement {
24822  
24823 # Called by LA::Line->implement directly after a call to $self->parse
24824 #
24825 # Expected arguments
24826 # (none besides $self)
24827 #
24828 # Return values
24829 # 'undef' on improper arguments or if there is an error
24830 # 1 otherwise
24831  
24832 my ($self, $check) = @_;
24833  
24834 # Local variables
24835 my ($valueExp, $value, $timeoutExp, $timeout);
24836  
24837 # Check for improper arguments
24838 if (defined $check) {
24839  
24840 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24841 }
24842  
24843 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24844 if (! $self->scriptObj->parentTask) {
24845  
24846 # Implementation complete. Execution resumes from the next statement
24847 return 1;
24848 }
24849  
24850 # Otherwise, retrieve the argument(s) stored by $self->parse
24851 $valueExp = $self->ivShow('parseDataHash', 'value');
24852 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24853  
24854 # Evaluate the expression(s)
24855 $value = $valueExp->evaluate();
24856 if (! ($value =~ /^\d+$/)) {
24857  
24858 return $self->scriptObj->setError(
24859 'invalid_integer',
24860 $self->_objClass . '->parse',
24861 );
24862 }
24863  
24864 if (defined $timeoutExp) {
24865  
24866 $timeout = $timeoutExp->evaluate();
24867  
24868 if (! ($timeout =~ /^\d+$/)) {
24869  
24870 return $self->scriptObj->setError(
24871 'invalid_integer',
24872 $self->_objClass . '->implement',
24873 );
24874  
24875 } elsif ($timeout < 1) {
24876  
24877 return $self->scriptObj->setError(
24878 'number_NUM_out_of_range',
24879 $self->_objClass . '->implement',
24880 'NUM', $timeout,
24881 );
24882 }
24883 }
24884  
24885 # Inform the parent task that it should start waiting
24886 $self->scriptObj->parentTask->setUpMonitoring(
24887 'status',
24888 'xp_current',
24889 $value,
24890 $timeout,
24891 );
24892  
24893 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24894 $self->scriptObj->set_scriptStatus('wait_status');
24895  
24896 # Implementation complete
24897 return 1;
24898 }
24899 }
24900  
24901 { package Language::Axbasic::Statement::warning;
24902  
24903 use strict;
24904 use warnings;
24905 use diagnostics;
24906  
24907 use Glib qw(TRUE FALSE);
24908  
24909 @Language::Axbasic::Statement::warning::ISA = qw(
24910 Language::Axbasic
24911 Language::Axbasic::Statement
24912 );
24913  
24914 # WARNING expression
24915  
24916 ##################
24917 # Methods
24918  
24919 sub parse {
24920  
24921 # Called by LA::Line->parse directly after a call to LA::Statement->new
24922 #
24923 # Expected arguments
24924 # (none besides $self)
24925 #
24926 # Return values
24927 # 'undef' on improper arguments or if there is an error
24928 # 1 otherwise
24929  
24930 my ($self, $check) = @_;
24931  
24932 # Local variables
24933 my $expression;
24934  
24935 # Check for improper arguments
24936 if (defined $check) {
24937  
24938 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24939 }
24940  
24941 # Get the expression and store it for ->implement to use
24942 $expression = Language::Axbasic::Expression::Arithmetic->new(
24943 $self->scriptObj,
24944 $self->tokenGroupObj,
24945 );
24946  
24947 if (! defined $expression) {
24948  
24949 return $self->scriptObj->setError(
24950 'missing_or_illegal_expression',
24951 $self->_objClass . '->parse',
24952 );
24953  
24954 } else {
24955  
24956 $self->ivAdd('parseDataHash', 'expression', $expression);
24957 }
24958  
24959 # There should be nothing after the expression
24960 if (! $self->tokenGroupObj->testStatementEnd()) {
24961  
24962 return $self->scriptObj->setError(
24963 'unexpected_keywords,_operators_or_expressions',
24964 $self->_objClass . '->parse',
24965 );
24966 }
24967  
24968 # Parsing complete
24969 return 1;
24970 }
24971  
24972 sub implement {
24973  
24974 # Called by LA::Line->implement directly after a call to $self->parse
24975 #
24976 # Expected arguments
24977 # (none besides $self)
24978 #
24979 # Return values
24980 # 'undef' on improper arguments or if there is an error
24981 # 1 otherwise
24982  
24983 my ($self, $check) = @_;
24984  
24985 # Local variables
24986 my ($expression, $string);
24987  
24988 # Check for improper arguments
24989 if (defined $check) {
24990  
24991 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24992 }
24993  
24994 # Retrieve the expression to be written
24995 $expression = $self->ivShow('parseDataHash', 'expression');
24996 # Evaluate the expression to get a scalar value
24997 $string = $expression->evaluate();
24998  
24999 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
25000 # the error message appears on a new line
25001 if ($self->scriptObj->column != 0) {
25002  
25003 $self->scriptObj->session->writeText('', 'after');
25004 $self->scriptObj->set_column(0);
25005 }
25006  
25007 # Write the error message to the 'main' window
25008 $self->scriptObj->session->writeWarning($string);
25009  
25010 # Implementation complete
25011 return 1;
25012 }
25013 }
25014  
25015 { package Language::Axbasic::Statement::while;
25016  
25017 use strict;
25018 use warnings;
25019 use diagnostics;
25020  
25021 use Glib qw(TRUE FALSE);
25022  
25023 @Language::Axbasic::Statement::while::ISA = qw(
25024 Language::Axbasic
25025 Language::Axbasic::Statement
25026 );
25027  
25028 # WHILE condition
25029 # WHILE expression
25030  
25031 ##################
25032 # Methods
25033  
25034 sub parse {
25035  
25036 # Called by LA::Line->parse directly after a call to LA::Statement->new
25037 #
25038 # Expected arguments
25039 # (none besides $self)
25040 #
25041 # Return values
25042 # 'undef' on improper arguments or if there is an error
25043 # 1 otherwise
25044  
25045 my ($self, $check) = @_;
25046  
25047 # Local variables
25048 my ($condition, $subObj);
25049  
25050 # Check for improper arguments
25051 if (defined $check) {
25052  
25053 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
25054 }
25055  
25056 # The 'while' keyword is not available in primitive numbering mode
25057 if ($self->scriptObj->executionMode ne 'no_line_num') {
25058  
25059 return $self->scriptObj->setError(
25060 'statement_not_available_with_line_numbers',
25061 $self->_objClass . '->parse',
25062 );
25063 }
25064  
25065 # Read a conditional expression
25066 $condition = Language::Axbasic::Expression::LogicalOr->new(
25067 $self->scriptObj,
25068 $self->tokenGroupObj,
25069 'maybe_arithmetic',
25070 );
25071  
25072 if (! defined $condition) {
25073  
25074 return $self->scriptObj->setError(
25075 'missing_or_illegal_conditional_expression',
25076 $self->_objClass . '->parse',
25077 );
25078  
25079 } else {
25080  
25081 # Store the condition expression, so $self->implement can retrieve it
25082 $self->ivAdd('parseDataHash', 'condition', $condition);
25083 }
25084  
25085 # Check there's nothing else in the statement after the condition expression
25086 if (! $self->tokenGroupObj->testStatementEnd()) {
25087  
25088 return $self->scriptObj->setError(
25089 'unexpected_keywords,_operators_or_expressions',
25090 $self->_objClass . '->parse',
25091 );
25092 }
25093  
25094 # Add this WHILE statement to the WHILE code block stack for the current subroutine
25095 $subObj = $self->scriptObj->returnCurrentSub();
25096 $subObj->push_whileStackList($self);
25097  
25098 # We don't know what the corresponding LOOP statement is, yet
25099 $self->ivAdd('parseDataHash', 'loop_statement', undef);
25100  
25101 # Parsing complete
25102 return 1;
25103 }
25104  
25105 sub implement {
25106  
25107 # Called by LA::Line->implement directly after a call to $self->parse when the
25108 # first token in the statement is the keyword 'while'
25109 #
25110 # Expected arguments
25111 # (none besides $self)
25112 #
25113 # Return values
25114 # 'undef' on improper arguments or if there is an error
25115 # 1 otherwise
25116  
25117 my ($self, $check) = @_;
25118  
25119 # Local variables
25120 my ($condition, $loopStatement, $subObj);
25121  
25122 # Check for improper arguments
25123 if (defined $check) {
25124  
25125 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25126 }
25127  
25128 # Retrieve the condition expression stored by $self->parse
25129 $condition = $self->ivShow('parseDataHash', 'condition');
25130  
25131 # Check the corresponding 'loop' statement from the current subroutine's WHILE code block
25132 # stack.
25133 if (! $self->ivShow('parseDataHash', 'loop_statement')) {
25134  
25135 return $self->scriptObj->setError(
25136 'WHILE_statement_without_matching_LOOP',
25137 $self->_objClass . '->implement',
25138 );
25139 }
25140  
25141 # Evaluate the condition expression
25142 if (! $condition->evaluate()) {
25143  
25144 # The condition expression is false, so we need to skip to the end of the WHILE..LOOP
25145 # code block
25146 $loopStatement = $self->ivShow('parseDataHash', 'loop_statement');
25147  
25148 if (defined $loopStatement->nextStatement) {
25149  
25150 # LA::Script->nextStatement is currently set to this statement; continue execution
25151 # as if this were the LOOP statement
25152 $self->scriptObj->set_nextStatement($loopStatement);
25153  
25154 } else {
25155  
25156 $self->scriptObj->set_nextStatement(undef);
25157 $self->scriptObj->set_nextLine($loopStatement->lineObj->procLineNum + 1),
25158 }
25159  
25160 } else {
25161  
25162 # Add this WHILE code block to the main code block stack, since we're going to execute
25163 # it now. The corresponding UNTIL statement will remove it.
25164 # NB The main ->blockStackList is used during ->implement for all kinds of code blocks;
25165 # ->whileStackList is used during ->parse for WHILE..LOOP blocks only
25166 $subObj = $self->scriptObj->returnCurrentSub();
25167 $subObj->push_blockStackList($self);
25168 }
25169  
25170 # Implementation complete
25171 return 1;
25172 }
25173 }
25174  
25175 { package Language::Axbasic::Statement::write;
25176  
25177 use strict;
25178 use warnings;
25179 use diagnostics;
25180  
25181 use Glib qw(TRUE FALSE);
25182  
25183 @Language::Axbasic::Statement::write::ISA = qw(
25184 Language::Axbasic
25185 Language::Axbasic::Statement
25186 );
25187  
25188 # WRITE expression
25189  
25190 ##################
25191 # Methods
25192  
25193 sub parse {
25194  
25195 # Called by LA::Line->parse directly after a call to LA::Statement->new
25196 #
25197 # Expected arguments
25198 # (none besides $self)
25199 #
25200 # Return values
25201 # 'undef' on improper arguments or if there is an error
25202 # 1 otherwise
25203  
25204 my ($self, $check) = @_;
25205  
25206 # Local variables
25207 my $expression;
25208  
25209 # Check for improper arguments
25210 if (defined $check) {
25211  
25212 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
25213 }
25214  
25215 # Get the expression and store it for ->implement to use
25216 $expression = Language::Axbasic::Expression::Arithmetic->new(
25217 $self->scriptObj,
25218 $self->tokenGroupObj,
25219 );
25220  
25221 if (! defined $expression) {
25222  
25223 return $self->scriptObj->setError(
25224 'missing_or_illegal_expression',
25225 $self->_objClass . '->parse',
25226 );
25227  
25228 } else {
25229  
25230 $self->ivAdd('parseDataHash', 'expression', $expression);
25231 }
25232  
25233 # There should be nothing after the expression
25234 if (! $self->tokenGroupObj->testStatementEnd()) {
25235  
25236 return $self->scriptObj->setError(
25237 'unexpected_keywords,_operators_or_expressions',
25238 $self->_objClass . '->parse',
25239 );
25240 }
25241  
25242 # Parsing complete
25243 return 1;
25244 }
25245  
25246 sub implement {
25247  
25248 # Called by LA::Line->implement directly after a call to $self->parse
25249 #
25250 # Expected arguments
25251 # (none besides $self)
25252 #
25253 # Return values
25254 # 'undef' on improper arguments or if there is an error
25255 # 1 otherwise
25256  
25257 my ($self, $check) = @_;
25258  
25259 # Local variables
25260 my ($expression, $string);
25261  
25262 # Check for improper arguments
25263 if (defined $check) {
25264  
25265 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25266 }
25267  
25268 # Retrieve the expression to be written
25269 $expression = $self->ivShow('parseDataHash', 'expression');
25270 # Evaluate the expression to get a scalar value
25271 $string = $expression->evaluate();
25272  
25273 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
25274 # the message appears on a new line
25275 if ($self->scriptObj->column != 0) {
25276  
25277 $self->scriptObj->session->writeText('', 'after');
25278 $self->scriptObj->set_column(0);
25279 }
25280  
25281 # Write the message to the 'main' window
25282 $self->scriptObj->session->writeText('AXBASIC: ' . $string);
25283  
25284 # Implementation complete
25285 return 1;
25286 }
25287 }
25288  
25289 { package Language::Axbasic::Statement::writewin;
25290  
25291 use strict;
25292 use warnings;
25293 use diagnostics;
25294  
25295 use Glib qw(TRUE FALSE);
25296  
25297 @Language::Axbasic::Statement::writewin::ISA = qw(
25298 Language::Axbasic
25299 Language::Axbasic::Statement
25300 );
25301  
25302 # WRITEWIN expression [ , expression [ , expression ... ] ]
25303  
25304 ##################
25305 # Methods
25306  
25307 sub parse {
25308  
25309 # Called by LA::Line->parse directly after a call to LA::Statement->new
25310 #
25311 # Expected arguments
25312 # (none besides $self)
25313 #
25314 # Return values
25315 # 'undef' on improper arguments or if there is an error
25316 # 1 otherwise
25317  
25318 my ($self, $check) = @_;
25319  
25320 # Local variables
25321 my (
25322 $textExp, $exitFlag,
25323 @otherExpList,
25324 );
25325  
25326 # Check for improper arguments
25327 if (defined $check) {
25328  
25329 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
25330 }
25331  
25332 # Get the text expression
25333 $textExp = Language::Axbasic::Expression::Arithmetic->new(
25334 $self->scriptObj,
25335 $self->tokenGroupObj,
25336 );
25337  
25338 if (! defined $textExp) {
25339  
25340 return $self->scriptObj->setError(
25341 'missing_or_illegal_expression',
25342 $self->_objClass . '->parse',
25343 );
25344 }
25345  
25346 # Get the optional expressions
25347 do {
25348 my ($token, $otherExp);
25349  
25350 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
25351  
25352 $token = $self->tokenGroupObj->lookAhead();
25353 if (defined $token) {
25354  
25355 $otherExp = Language::Axbasic::Expression::Arithmetic->new(
25356 $self->scriptObj,
25357 $self->tokenGroupObj,
25358 );
25359  
25360 if (! defined $otherExp) {
25361  
25362 return $self->scriptObj->setError(
25363 'missing_or_illegal_expression',
25364 $self->_objClass . '->parse',
25365 );
25366  
25367 } else {
25368  
25369 push (@otherExpList, $otherExp);
25370 }
25371 }
25372  
25373 } else {
25374  
25375 $exitFlag = TRUE;
25376 }
25377  
25378 } until ($exitFlag);
25379  
25380 # Check that nothing follows the expressions
25381 if (! $self->tokenGroupObj->testStatementEnd()) {
25382  
25383 return $self->scriptObj->setError(
25384 'unexpected_keywords,_operators_or_expressions',
25385 $self->_objClass . '->parse',
25386 );
25387 }
25388  
25389 # Store the expressions, so $self->implement can retrieve them
25390 $self->ivAdd('parseDataHash', 'text_exp', $textExp);
25391 $self->ivPoke('parseDataList', @otherExpList);
25392  
25393 # Parsing complete
25394 return 1;
25395 }
25396  
25397 sub implement {
25398  
25399 # Called by LA::Line->implement directly after a call to $self->parse
25400 #
25401 # Expected arguments
25402 # (none besides $self)
25403 #
25404 # Return values
25405 # 'undef' on improper arguments or if there is an error
25406 # 1 otherwise
25407  
25408 my ($self, $check) = @_;
25409  
25410 # Local variables
25411 my (
25412 $textExp, $text,
25413 @otherExpList, @otherList,
25414 );
25415  
25416 # Check for improper arguments
25417 if (defined $check) {
25418  
25419 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25420 }
25421  
25422 # Retrieve the arguments stored by $self->parse
25423 $textExp = $self->ivShow('parseDataHash', 'text_exp');
25424 @otherExpList = $self->parseDataList;
25425  
25426 # Evaluate each expression
25427 $text = $textExp->evaluate();
25428 foreach my $exp (@otherExpList) {
25429  
25430 push (@otherList, $exp->evaluate());
25431 }
25432  
25433 # If the Axbasic script is being run from within an Axmud task and the task window is open,
25434 # write to it. If run from within the task, the task window is closed but we're allowed to
25435 # write to the 'main' window, write to the 'main' window. Otherwise, do nothing
25436 if ($self->scriptObj->parentTask) {
25437  
25438 if ($self->scriptObj->parentTask->taskWinFlag) {
25439  
25440 # Write to the task window
25441 $self->scriptObj->parentTask->insertPrint($text, @otherList);
25442  
25443 } elsif ($self->scriptObj->ivShow('optionStatementHash', 'redirect')) {
25444  
25445 # Write to the 'main' window; ignore the contents of @otherList
25446 $self->scriptObj->session->writeText($text);
25447 }
25448 }
25449  
25450 # Implementation complete
25451 return 1;
25452 }
25453 }
25454  
25455 # Package must return a true value
25456 1