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

filter: Statementstmt 0.0% 0 / 7054 Branchbran 0.0% 0 / 2990 Conditioncond 0.0% 0 / 834 MC/DCmcdc 0.0% 0 / 484 Subroutinesub 0.0% 0 / 812 Podpod 0.0% 0 / 334 totaltotal 0.0% 0 / 12508 CC 1496 SCAR 44.2
CC
1496
Cov
0%
parse
930.0
implement
812.0
implement
650.0
CRAP 83.2
1 # Copyright (C) 2011-2024 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::winaddgauge;
186 package Language::Axbasic::Statement::winaddcongauge;
187 package Language::Axbasic::Statement::windelgauge;
188 package Language::Axbasic::Statement::winsetgauge;
189 package Language::Axbasic::Statement::write;
190 package Language::Axbasic::Statement::writewin;
191 }
192  
193 ##################
194 # Constructors
195  
196 sub new {
197  
198 # Called by LA::Line->parse (or by the ->parse function of another LA::Statement::xxx
199 # object)
200 # The class that handles the parsing of a single Axbasic statement
201 # This function blesses itself, then calls $self->refine to decide what kind of statement it
202 # is (PRINT, LET, DATA, etc)
203 # $self->refine creates a LA::Statement::<keyword> object, where <keyword> is the first
204 # keyword in the statement (matches an element in LA::Token->keywordList). <keyword> is
205 # set to the implied LET for a statement beginning with a variable.
206 # This function then returns the blessed reference of the LA::Statement::<keyword> object (a
207 # subclass which inherits from this one)
208 #
209 # Expected arguments
210 # $scriptObj - Blessed reference of the parent LA::Script
211 # $lineObj - Blessed reference of the calling LA::Line
212 # $tokenGroupObj - Blessed reference of the line's LA::TokenGroup
213 #
214 # Optional arguments
215 # $lineNumOk - Set to 'line_num_ok' when called by LA::Statement::if, in situations
216 # like 'IF ... THEN 20' in which case, this statement knows that the
217 # 'THEN 20' part should be parsed as 'THEN GOTO 20'. Otherwise, set to
218 # 'undef'
219 #
220 # Return values
221 # 'undef' on improper arguments, or if the statement can't be parsed at all (i.e. doesn't
222 # begin with a keyword, including an implied LET), or begins with a 'weak' keyword
223 # like STEP (matching a key in LA::Script->weakKeywordHash)
224 # Blessed reference to the newly-created object on success
225  
226 my ($class, $scriptObj, $lineObj, $tokenGroupObj, $lineNumOk, $check) = @_;
227  
228 # Check for improper arguments
229 if (
230 ! defined $class || ! defined $scriptObj || ! defined $lineObj
231 || ! defined $tokenGroupObj || (defined $lineNumOk && $lineNumOk ne 'line_num_ok')
232 || defined $check
233 ) {
234 return $axmud::CLIENT->writeImproper($class . '->new', @_);
235 }
236  
237 # Setup
238 my $self = {
239 _objName => $class, # Name Axbasic objects after their class
240 _objClass => $class,
241 _parentFile => undef, # No parent file object
242 _parentWorld => undef, # No parent file object
243 _privFlag => TRUE, # All IVs are private
244  
245 # Perl object components
246 # ----------------------
247  
248 # The parent LA::Script
249 scriptObj => $scriptObj,
250 # Blessed reference of the calling LA::Line
251 lineObj => $lineObj,
252 # Blessed reference of the line's token group
253 tokenGroupObj => $tokenGroupObj,
254  
255 # IVs
256 # ----
257  
258 # What kind of statement this is (set to <keyword> by the subclass)
259 keyword => undef,
260 # For keywords that are a synonym of another (e.g., SLEEP is a synonym of PAUSE) and for
261 # keywords that share an LA::Statement with another (e.g. ADDCONGAUGE shares code
262 # with ADDGAUGE), the keyword that was actually used when deciding which class of
263 # LA::Statement:: object to use
264 # For all other keywords, $self->keyword is the same as $self->modKeyword
265 modKeyword => undef,
266 # The statement's status: 0 being parsed/implemented, 1 parsed/implemented, 2 parsed but
267 # caused an error
268 status => 0,
269  
270 # Set by LA::Line->parse - blessed reference of the next statement in a single line, to
271 # be executed after this one (e.g. the 'print "hello" : print 'there" ' contains two
272 # statements)
273 nextStatement => undef,
274  
275 # The call to ->parse can sometimes create data which must be stored until the call to
276 # ->implement (if there is one). This data is stored in either of these two variables
277 parseDataList => [],
278 parseDataHash => {},
279  
280 # Defined if this statement is a 'then' statement, so that 'then 20' can be parsed as
281 # 'then goto 20'
282 lineNumOk => $lineNumOk,
283 };
284  
285 bless $self, $class;
286  
287 # Create the subclass object
288 if (! $self->refine()) {
289  
290 return undef;
291 }
292  
293 # Return the subclass object, if it was created
294 return $self;
295 }
296  
297 sub refine {
298  
299 # Called by $self->new to bless a sub-class (see the comments for $self-new)
300 # Reads the keyword the statement starts with - which might be an implied LET - and uses it
301 # to bless the sub-class
302 #
303 # Expected arguments
304 # (none besides $self)
305 #
306 # Return values
307 # 'undef' on improper arguments, or if there is an error
308 # Otherwise returns the blessed reference of the subclass
309  
310 my ($self, $check) = @_;
311  
312 # Local variables
313 my ($token, $subClass, $keyword, $modKeyword);
314  
315 # Check for improper arguments
316 if (defined $check) {
317  
318 return $axmud::CLIENT->writeImproper($self->_objClass . '->refine', @_);
319 }
320  
321 # Get the first token from the statement
322 $token = $self->tokenGroupObj->lookAhead();
323 if (! defined $token) {
324  
325 if (! $self->tokenGroupObj->shortCommentFlag) {
326  
327 return $self->scriptObj->setDebug(
328 'Empty statement error',
329 $self->_objClass . '->refine',
330 );
331  
332 } else {
333  
334 # First token on the line was ! (short comment token). Treat it like a REM
335 # statement
336 $keyword = 'rem';
337 }
338  
339 # If the first token is a recognised Axbasic keyword...
340 } elsif ($token->category eq 'keyword') {
341  
342 # Check that it's not a weak keyword like STEP which isn't allowed to begin a statement
343 if ($self->scriptObj->ivExists('weakKeywordHash', $token->tokenText)) {
344  
345 return $self->scriptObj->setError(
346 'statements_cannot_start_with_keyword_STRING',
347 $self->_objClass . '->refine',
348 'STRING', $token->tokenText,
349 );
350  
351 } else {
352  
353 # Remove the token containing the keyword from the token group's token list
354 # (->lookAhead has already returned a defined value, so there's no need to check
355 # the return value of ->shiftToken)
356 $self->tokenGroupObj->shiftToken();
357 # Set $keyword to the keyword itself
358 $keyword = $token->tokenText;
359  
360 # Check if this keyword is a synonym of another (e.g., SLEEP is a synonym of PAUSE)
361 # or if the keyword shares an LA::Statement with another (e.g. ADDCONGAUGE
362 # shares code with ADDGAUGE)
363 if ($self->scriptObj->ivExists('equivKeywordHash', $keyword)) {
364  
365 $modKeyword = $self->scriptObj->ivShow('equivKeywordHash', $keyword);
366 }
367 }
368  
369 # If the first token is a comment...
370 } elsif ($token->category eq 'comment') {
371  
372 $keyword = 'rem';
373  
374 # If the first token is an implied 'let' keyword...
375 } elsif ($token->category eq 'identifier') {
376  
377 # Are we allowed to use implied LETs?
378 if (
379 $self->scriptObj->ivShow('optionStatementHash', 'nolet')
380 || $self->scriptObj->executionMode eq 'line_num'
381 ) {
382 $keyword = 'let';
383  
384 } else {
385  
386 return $self->scriptObj->setError(
387 'syntax_error',
388 $self->_objClass . '->refine',
389 );
390 }
391  
392 # If we're in a NEXT clause of an IF statement...
393 } elsif (
394 $self->lineNumOk
395 && $token->category eq 'numeric_constant'
396 && $token->tokenText =~ /^\d+$/
397 ) {
398 $keyword = 'goto';
399  
400 } else {
401  
402 # Statement doesn't start with a keyword, comment or variable
403 return $self->scriptObj->setError(
404 'syntax_error',
405 $self->_objClass . '->refine',
406 );
407 }
408  
409 # Decide which sub-class to use
410 if (! $modKeyword) {
411  
412 $modKeyword = $keyword;
413 }
414  
415 $subClass = 'Language::Axbasic::Statement::' . $modKeyword;
416  
417 # Bless the subclass object into existence, replacing the blessed reference of the calling
418 # LA::Statement object (as explained in the comments for $self->new)
419 bless $self, $subClass;
420  
421 # Store the statement type
422 $self->ivPoke('keyword', $keyword);
423 $self->ivPoke('modKeyword', $modKeyword);
424  
425 return $self;
426 }
427  
428 ##################
429 # Methods
430  
431 sub parse {
432  
433 # This generic ->parse function does nothing (it is inherited by LA::Statement::rem which
434 # doesn't have its own ->parse method)
435  
436 my ($self, $check) = @_;
437  
438 # Check for improper arguments
439 if (defined $check) {
440  
441 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
442 }
443  
444 # Do nothing
445 return 1;
446 }
447  
448 sub implement {
449  
450 # This generic ->implement function does nothing (it is inherited by LA::Statement::rem
451 # which doesn't have its own ->parse method)
452  
453 my ($self, $check) = @_;
454  
455 # Check for improper arguments
456 if (defined $check) {
457  
458 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
459 }
460  
461 # Do nothing
462 return 1;
463 }
464  
465 # Functions used by POKE... and PEEK... statements
466  
467 sub parsePeek {
468  
469 # Called by $self->parse for all PEEK... statements (including PEEK itself)
470 #
471 # Expected arguments
472 # (none besides $self)
473 #
474 # Optional arguments
475 # $forceFlag - Set to TRUE for statements like PEEKKEYS, which use an Axbasic array
476 # variable regardless of whether the statement is in the form
477 # 'PEEKKEYS var = string' or 'PEEKKEYS ARRAY var = string'. Set to FALSE
478 # (or 'undef') for all other PEEK... statements
479 # $extraFlag - Set to TRUE for statements like PEEKINDEX, which use an extra argument
480 # at the end of the statement, which must be extracted and stored
481 #
482 # Return values
483 # 'undef' on improper arguments or if there is an error
484 # 1 otherwise
485  
486 my ($self, $forceFlag, $extraFlag, $check) = @_;
487  
488 # Local variables
489 my ($token, $arrayFlag, $varName, $varObj, $expression, $extraExp);
490  
491 # Check for improper arguments
492 if (defined $check) {
493  
494 return $axmud::CLIENT->writeImproper($self->_objClass . '->parsePeek', @_);
495 }
496  
497 # Extract the optional ARRAY keyword
498 $token = $self->tokenGroupObj->shiftMatchingToken('array');
499 if ($token || $forceFlag) {
500 $arrayFlag = TRUE;
501 } else {
502 $arrayFlag = FALSE;
503 }
504  
505 # Extract a token comprising a whole variable identifier (e.g. A, a$, array)
506 $token = $self->tokenGroupObj->shiftTokenIfCategory('identifier');
507 if (! defined $token) {
508  
509 return $self->scriptObj->setError(
510 'missing_or_illegal_variable',
511 $self->_objClass . '->parse',
512 );
513  
514 } else {
515  
516 $varName = $token->tokenText;
517  
518 # Look up the LA::Variable. Use the local variable, if it exists. Otherwise use the
519 # global variable, if it exists. Otherwise, create a global variable
520 # (If the user wants to PEEK a Perl list/hash into an Axbasic array that's a local
521 # variable, they can use a DIM LOCAL statement before this one)
522 if (! $arrayFlag) {
523  
524 $self->scriptObj->set_declareMode('peek_scalar');
525 $varObj = Language::Axbasic::Variable->lookup($self->scriptObj, $varName);
526  
527 } else {
528  
529 # If it's an array, ->lookup expects a LA::Expression::Arglist; but we only need to
530 # supply it with a defined value
531 $self->scriptObj->set_declareMode('peek_array');
532 $varObj = Language::Axbasic::Variable->lookup(
533 $self->scriptObj,
534 $varName,
535 'fake_arg_list'
536 );
537 }
538  
539 $self->scriptObj->set_declareMode('default');
540  
541 if (! $varObj) {
542  
543 # This shouldn't happen...
544 return $self->scriptObj->setError(
545 'syntax_error',
546 $self->_objClass . '->parse',
547 );
548 }
549 }
550  
551 # Extract the assignment operator
552 if (! defined $self->tokenGroupObj->shiftTokenIfCategory('assignment_operator')) {
553  
554 return $self->scriptObj->setError(
555 'missing_assignment_operator',
556 $self->_objClass . '->parse',
557 );
558 }
559  
560 # The next token is either an expression representing an Axmud internal variable (a scalar,
561 # e.g. "current.world.name"; an array, e.g. "current.world.statusFormatList"; or a hash,
562 # e.g. "current.world.currencyHash")
563 $token = $self->tokenGroupObj->lookAhead();
564 if (! defined $token) {
565  
566 return $self->scriptObj->setError(
567 'syntax_error',
568 $self->_objClass . '->parse',
569 );
570  
571 } else {
572  
573 $expression = Language::Axbasic::Expression::Arithmetic->new(
574 $self->scriptObj,
575 $self->tokenGroupObj,
576 );
577  
578 if (! defined $expression) {
579  
580 return $self->scriptObj->setError(
581 'missing_or_illegal_expression',
582 $self->_objClass . '->parse',
583 );
584 }
585 }
586  
587 # Save the array flag, variable object and expression object so $self->implement can use
588 # them, if it is called
589 $self->ivAdd('parseDataHash', 'array_flag', $arrayFlag);
590 $self->ivAdd('parseDataHash', 'var_name', $varName);
591 $self->ivAdd('parseDataHash', 'expression', $expression);
592  
593 if ($extraFlag) {
594  
595 # This statement uses further, which must be extracted
596 # Extract the comma
597 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
598  
599 return $self->scriptObj->setError(
600 'syntax_error',
601 $self->_objClass . '->parse',
602 );
603 }
604  
605 # Extract the extra expression
606 $token = $self->tokenGroupObj->lookAhead();
607 if (! defined $token) {
608  
609 return $self->scriptObj->setError(
610 'syntax_error',
611 $self->_objClass . '->parse',
612 );
613  
614 } else {
615  
616 $extraExp = Language::Axbasic::Expression::Arithmetic->new(
617 $self->scriptObj,
618 $self->tokenGroupObj,
619 );
620  
621 if (! defined $extraExp) {
622  
623 return $self->scriptObj->setError(
624 'missing_or_illegal_expression',
625 $self->_objClass . '->parse',
626 );
627 }
628 }
629  
630 # Save the extra expression object so $self->implement can use it, if it is called
631 $self->ivAdd('parseDataHash', 'extra_exp', $extraExp);
632 }
633  
634 # There should be nothing after the expression
635 if (defined $self->tokenGroupObj->lookAhead()) {
636  
637 return $self->scriptObj->setError(
638 'unexpected_keywords,_operators_or_expressions',
639 $self->_objClass . '->parse',
640 );
641 }
642  
643 # Initial parsing complete
644 return 1;
645 }
646  
647 sub parsePoke {
648  
649 # Called by $self->parse for many POKE... statements (but not POKE itself)
650 #
651 # Expected arguments
652 # (none besides $self)
653 #
654 # Optional arguments
655 # $number - The number of expressions to extract, after the first (compulsory) one. An
656 # integer, 0 or above (or 'undef' to extract no optional expressions)
657 # $max - The maximum number or expressions to extract, after the first (compulsory)
658 # one. If defined, $number must be defined too, and $number represents
659 # the minimum. Set to 'undef' if the maximum number is the same as the
660 # minimum (or if no optional expressions are to be extracted)
661 #
662 # Return values
663 # 'undef' on improper arguments or if there is an error
664 # 1 otherwise
665  
666 my ($self, $number, $max, $check) = @_;
667  
668 # Local variables
669 my (
670 $token, $varExp,
671 @expList,
672 );
673  
674 # Check for improper arguments
675 if (defined $check) {
676  
677 return $axmud::CLIENT->writeImproper($self->_objClass . '->parsePoke', @_);
678 }
679  
680 # The first token is either an expression representing an Axmud internal variable (a scalar,
681 # e.g. "current.world.name"; an array, e.g. "current.world.statusFormatList"; or a hash,
682 # e.g. "current.world.currencyHash")
683 $token = $self->tokenGroupObj->lookAhead();
684 if (! defined $token) {
685  
686 return $self->scriptObj->setError(
687 'syntax_error',
688 $self->_objClass . '->parse',
689 );
690  
691 } else {
692  
693 $varExp = Language::Axbasic::Expression::Arithmetic->new(
694 $self->scriptObj,
695 $self->tokenGroupObj,
696 );
697  
698 if (! defined $varExp) {
699  
700 return $self->scriptObj->setError(
701 'missing_or_illegal_expression',
702 $self->_objClass . '->parse',
703 );
704 }
705 }
706  
707 # (Extract expressions, even if the minimum is 0 and the maximum is 1)
708 if ($number || $max) {
709  
710 if (! defined $max) {
711  
712 # Minimum and maximum number of expressions is the same
713 $max = $number;
714  
715 } elsif ($number > $max) {
716  
717 # Emergency failsafe to prevent infinite loops
718 $number = $max;
719 }
720  
721 # Extract expressions until there are none left
722 OUTER: for (my $count = 1; $count <= $max; $count++) {
723  
724 my $expression;
725  
726 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
727  
728 if ($count > $number) {
729  
730 # We have at least the minimum number of expressions we need
731 last OUTER;
732  
733 } else {
734  
735 return $self->scriptObj->setError(
736 'syntax error',
737 $self->_objClass . '->parse',
738 );
739 }
740 }
741  
742 $expression = Language::Axbasic::Expression::Arithmetic->new(
743 $self->scriptObj,
744 $self->tokenGroupObj,
745 );
746  
747 if (! defined $expression) {
748  
749 return $self->scriptObj->setError(
750 'missing_or_illegal_expression',
751 $self->_objClass . '->parse',
752 );
753  
754 } else {
755  
756 push (@expList, $expression);
757 }
758 }
759 }
760  
761 # There are no further expressions to extract
762 if (! $self->tokenGroupObj->testStatementEnd()) {
763  
764 return $self->scriptObj->setError(
765 'unexpected_keywords,_operators_or_expressions',
766 $self->_objClass . '->parse',
767 );
768 }
769  
770 # Save the expressions so $self->implement can use them, if it is called
771 $self->ivAdd('parseDataHash', 'var_exp', $varExp);
772 $self->ivPoke('parseDataList', @expList);
773  
774 # Initial parsing complete
775 return 1;
776 }
777  
778 sub fetchVar {
779  
780 # Called by $self->parse for most PEEK... statements (including PEEK itself)
781 # Looks up an Axbasic scalar variable or array, calling $self->scriptObj->setError if the
782 # variable can't be found
783 #
784 # Expected arguments
785 # $statement - The statement keyword, e.g. 'PEEK'
786 # $varName - The name of the variable, e.g. 'var$'
787 #
788 # Optional arguments
789 # $arrayFlag - Flag set to TRUE if the ARRAY keyword was also used (e.g. PEEK ARRAY); set
790 # to FALSE (or 'undef') if not
791 #
792 # Return values
793 # 'undef' on improper arguments or the variable can't be found
794 # Otherwise, returns the LA::Variable object
795  
796 my ($self, $statement, $varName, $arrayFlag, $check) = @_;
797  
798 # Local variables
799 my $varObj;
800  
801 # Check for improper arguments
802 if (! defined $statement || ! defined $varName || defined $check) {
803  
804 return $axmud::CLIENT->writeImproper($self->_objClass . '->fetchVar', @_);
805 }
806  
807 # Look up the LA::Variable
808 if (! $arrayFlag) {
809  
810 $varObj = Language::Axbasic::Variable->lookup($self->scriptObj, $varName);
811  
812 } else {
813  
814 # If it's an array, ->lookup expects a LA::Expression::Arglist; but we only need to
815 # supply it with a defined value
816 $varObj = Language::Axbasic::Variable->lookup(
817 $self->scriptObj,
818 $varName,
819 'fake_arg_list'
820 );
821 }
822  
823 if (! $varObj) {
824  
825 # This shouldn't happen...
826 return $self->scriptObj->setError(
827 $statement . '_operation_failure',
828 $self->_objClass . '->implement',
829 );
830  
831 } else {
832  
833 return $varObj;
834 }
835 }
836  
837 sub importAsScalar {
838  
839 # Called by $self->parse for all PEEK... statements (including PEEK itself)
840 # Sets the value of an Axbasic scalar variable, converting Perl 'undef' to an Axbasic string
841 # or numeric value, as required
842 #
843 # Expected arguments
844 # $varObj - A LA::Variable::Array object
845 #
846 # Optional arguments
847 # $scalar - A value to store in the Axbasic scalar variable (may be 'undef')
848  
849 my ($self, $varObj, $scalar) = @_;
850  
851 # Check for improper arguments
852 if (! defined $varObj) {
853  
854 return $axmud::CLIENT->writeImproper($self->_objClass . '->importAsScalar', @_);
855 }
856  
857 # Perl 'undef' values are converted to Axbasic strings "<<undef>>" or the number 0
858 if (defined $scalar) {
859 $varObj->set($scalar);
860 } elsif (ref($varObj) =~ m/Numeric/) {
861 $varObj->set(0);
862 } else {
863 $varObj->set('<<undef>>');
864 }
865  
866 # Do nothing
867 return 1;
868 }
869  
870 sub importAsArray {
871  
872 # Called by $self->parse for all PEEK... statements (including PEEK itself)
873 # Replaces the contents of an Axbasic array variable with a Perl list, redimensioning the
874 # array as required
875 #
876 # Expected arguments
877 # $varObj - A LA::Variable::Array object
878 #
879 # Optional arguments
880 # @array - A list of values to put into the Axbasic array (can be an empty list)
881  
882 my ($self, $varObj, @array) = @_;
883  
884 # Local variables
885 my (
886 $count,
887 @cellList,
888 );
889  
890 # Check for improper arguments
891 if (! defined $varObj) {
892  
893 return $axmud::CLIENT->writeImproper($self->_objClass . '->importAsArray', @_);
894 }
895  
896 # Re-dimension the array to match the size of @array (and to make sure it has only one
897 # dimension)
898 $varObj->dimension(0, (scalar @array) - 1);
899  
900 # Set each variable in the Axbasic array to match the values of the elements in the Axmud
901 # list/hash
902 @cellList = $varObj->cellList;
903 # The first item in LA::Variable::Array->cellList is the lower bound, which we already
904 # know is 0 (so we can dispense with it)
905 shift @cellList;
906 # (But the first element of @array that we want is, of course, element 0)
907 $count = -1;
908  
909 foreach my $arrayVar (@cellList) {
910  
911 $count++;
912  
913 # Perl 'undef' values are converted to Axbasic strings "<<undef>>" or the number 0
914 if (defined $array[$count]) {
915 $arrayVar->set($array[$count]);
916 } elsif (ref($varObj) =~ m/Numeric/) {
917 $arrayVar->set(0);
918 } else {
919 $arrayVar->set("<<undef>>");
920 }
921 }
922  
923 # Do nothing
924 return 1;
925 }
926  
927 # Functions used by SETTRIG, etc statements
928  
929 sub parseSetInterface {
930  
931 # Called by $self->parse for the SETTRIG, SETALIAS, SETMACRO, SETTIMER and SETHOOK
932 # statements
933 #
934 # Expected arguments
935 # (none besides $self)
936 #
937 # Return values
938 # 'undef' on improper arguments or if there is an error
939 # 1 otherwise
940  
941 my ($self, $check) = @_;
942  
943 # Local variables
944 my ($stimulusExp, $newScriptExp, $token);
945  
946 # Check for improper arguments
947 if (defined $check) {
948  
949 return $axmud::CLIENT->writeImproper($self->_objClass . '->parseSetInterface', @_);
950 }
951  
952 # Convert the stimulus string into an expression
953 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
954 $self->scriptObj,
955 $self->tokenGroupObj,
956 );
957  
958 if (! defined $stimulusExp) {
959  
960 return $self->scriptObj->setError(
961 'missing_or_illegal_expression',
962 $self->_objClass . '->parse',
963 );
964 }
965  
966 # Get the new script name, if specified
967 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
968  
969 $token = $self->tokenGroupObj->lookAhead();
970 if (defined $token) {
971  
972 $newScriptExp = Language::Axbasic::Expression::Arithmetic->new(
973 $self->scriptObj,
974 $self->tokenGroupObj,
975 );
976  
977 if (! defined $newScriptExp) {
978  
979 return $self->scriptObj->setError(
980 'missing_or_illegal_expression',
981 $self->_objClass . '->parse',
982 );
983 }
984 }
985 }
986  
987 # Check that nothing follows the expression(s)
988 if (! $self->tokenGroupObj->testStatementEnd()) {
989  
990 return $self->scriptObj->setError(
991 'unexpected_keywords,_operators_or_expressions',
992 $self->_objClass . '->parse',
993 );
994 }
995  
996 # Store the expression(s), so $self->implement can retrieve them
997 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
998 $self->ivAdd('parseDataHash', 'new_script', $newScriptExp);
999  
1000 # Parsing complete
1001 return 1;
1002 }
1003  
1004 # Functions used by WAITTRIG, etc statements
1005  
1006 sub parseWaitInterface {
1007  
1008 # Called by LA::Statement::waittrig->parse (and also by WAITALIAS, WAITMACRO, WAITTIMER and
1009 # WAITHOOK ->parse functions)
1010 #
1011 # Expected arguments
1012 # (none besides $self)
1013 #
1014 # Return values
1015 # 'undef' on improper arguments or if there is an error
1016 # 1 otherwise
1017  
1018 my ($self, $check) = @_;
1019  
1020 # Local variables
1021 my ($stimulusExp, $timeoutExp);
1022  
1023 # Check for improper arguments
1024 if (defined $check) {
1025  
1026 return $axmud::CLIENT->writeImproper($self->_objClass . '->parseWaitInterface', @_);
1027 }
1028  
1029 # Convert the pattern string into an expression
1030 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1031 $self->scriptObj,
1032 $self->tokenGroupObj,
1033 );
1034  
1035 if (! defined $stimulusExp) {
1036  
1037 return $self->scriptObj->setError(
1038 'missing_or_illegal_expression',
1039 $self->_objClass . '->parse',
1040 );
1041 }
1042  
1043 # Get the timeout, if specified, and convert it into an expression
1044 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1045  
1046 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
1047 $self->scriptObj,
1048 $self->tokenGroupObj,
1049 );
1050  
1051 if (! defined $timeoutExp) {
1052  
1053 return $self->scriptObj->setError(
1054 'missing_or_illegal_expression',
1055 $self->_objClass . '->parse',
1056 );
1057 }
1058 }
1059  
1060 # Check that nothing follows the expression(s)
1061 if (! $self->tokenGroupObj->testStatementEnd()) {
1062  
1063 return $self->scriptObj->setError(
1064 'unexpected_keywords,_operators_or_expressions',
1065 $self->_objClass . '->parse',
1066 );
1067 }
1068  
1069 # Store the expression(s), so $self->implement can retrieve them
1070 $self->ivAdd('parseDataHash', 'pattern', $stimulusExp);
1071 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
1072  
1073 # Parsing complete
1074 return 1;
1075 }
1076  
1077 sub implementWaitInterface {
1078  
1079 # Called by LA::Statement::waittrig->implement (and also by WAITALIAS, WAITMACRO, WAITTIMER
1080 # and WAITHOOK ->implement functions)
1081 #
1082 # Expected arguments
1083 # $interfaceType - 'trigger', 'alias', 'macro', 'timer or 'hook'
1084 #
1085 # Return values
1086 # 'undef' on improper arguments or if there is an error
1087 # 1 otherwise
1088  
1089 my ($self, $interfaceType, $check) = @_;
1090  
1091 # Local variables
1092 my ($stimulusExp, $stimulus, $timeoutExp, $timeout, $interfaceObj);
1093  
1094 # Check for improper arguments
1095 if (! defined $interfaceType || defined $check) {
1096  
1097 return $axmud::CLIENT->writeImproper($self->_objClass . '->implementWaitInterface', @_);
1098 }
1099  
1100 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
1101 if (! $self->scriptObj->parentTask) {
1102  
1103 # Implementation complete. Execution resumes from the next statement
1104 return 1;
1105 }
1106  
1107 # Otherwise, retrieve the argument(s) stored by $self->parse
1108 $stimulusExp = $self->ivShow('parseDataHash', 'pattern');
1109 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
1110  
1111 # Evaluate the expression(s)
1112 $stimulus = $stimulusExp->evaluate();
1113  
1114 if (defined $timeoutExp) {
1115  
1116 $timeout = $timeoutExp->evaluate();
1117  
1118 if (! ($timeout =~ /^\d+$/)) {
1119  
1120 return $self->scriptObj->setError(
1121 'invalid_integer',
1122 $self->_objClass . '->implement',
1123 );
1124  
1125 } elsif ($timeout < 1) {
1126  
1127 return $self->scriptObj->setError(
1128 'number_NUM_out_of_range',
1129 $self->_objClass . '->implement',
1130 'NUM', $timeout,
1131 );
1132 }
1133 }
1134  
1135 # Create the interface, which will call a function in this script's parent task when it
1136 # fires
1137 $interfaceObj = $self->scriptObj->session->createDependentInterface(
1138 $interfaceType,
1139 $stimulus,
1140 $self->scriptObj->parentTask,
1141 'interfaceWaitSeen',
1142 'temporary',
1143 1,
1144 );
1145  
1146 if (defined $interfaceObj) {
1147  
1148 # Add this interface to the list of interfaces created during the execution of the
1149 # Axbasic script
1150 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
1151 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
1152  
1153 # Mark this script as paused
1154 $self->scriptObj->set_scriptStatus('paused');
1155 # Tell the task that it's waiting for an interface, so that the interface can be
1156 # deleted, the first time it fires...
1157 $self->scriptObj->parentTask->ivPoke('waitForInterface', $interfaceObj->name);
1158 # ...and then begin the pause
1159 if (defined $timeoutExp) {
1160  
1161 $self->scriptObj->parentTask->pauseUntil(
1162 ($self->scriptObj->session->sessionTime + $timeout),
1163 );
1164  
1165 } else {
1166  
1167 $self->scriptObj->parentTask->pauseUntil();
1168 }
1169  
1170 } else {
1171  
1172 # Store the fact that creation of the interface failed
1173 $self->scriptObj->set_depInterfaceName(undef);
1174 }
1175  
1176 # Implementation complete
1177 return 1;
1178 }
1179  
1180 ##################
1181 # Accessors - set
1182  
1183 sub set_nextStatement {
1184  
1185 # Returns 'undef' on improper arguments
1186 # Returns 1 on success
1187  
1188 my ($self, $obj, $check) = @_;
1189  
1190 # Check for improper arguments
1191 if (defined $check) {
1192  
1193 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_nextStatement', @_);
1194 }
1195  
1196 # Update IVs
1197 $self->ivPoke('nextStatement', $obj);
1198  
1199 return 1;
1200 }
1201  
1202 sub add_parseDataHash {
1203  
1204 # Returns 'undef' on improper arguments
1205 # Returns 1 on success
1206  
1207 my ($self, $string, $obj, $check) = @_;
1208  
1209 # Check for improper arguments
1210 if (! defined $string || ! defined $obj || defined $check) {
1211  
1212 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_parseDataHash', @_);
1213 }
1214  
1215 # Update IVs
1216 $self->ivAdd('parseDataHash', $string, $obj);
1217  
1218 return 1;
1219 }
1220  
1221 sub push_parseDataList {
1222  
1223 # Returns 'undef' on improper arguments
1224 # Returns 1 on success
1225  
1226 my ($self, $obj, $check) = @_;
1227  
1228 # Check for improper arguments
1229 if (! defined $obj || defined $check) {
1230  
1231 return $axmud::CLIENT->writeImproper($self->_objClass . '->push_parseDataList', @_);
1232 }
1233  
1234 # Update IVs
1235 $self->ivPush('parseDataList', $obj);
1236  
1237 return 1;
1238 }
1239  
1240 ##################
1241 # Accessors - get
1242  
1243 sub scriptObj
1244 { $_[0]->{scriptObj} }
1245 sub lineObj
1246 { $_[0]->{lineObj} }
1247 sub tokenGroupObj
1248 { $_[0]->{tokenGroupObj} }
1249  
1250 sub keyword
1251 { $_[0]->{keyword} }
1252 sub modKeyword
1253 { $_[0]->{modKeyword} }
1254 sub status
1255 { $_[0]->{status} }
1256  
1257 sub nextStatement
1258 { $_[0]->{nextStatement} }
1259  
1260 sub parseDataList
1261 { my $self = shift; return @{$self->{parseDataList}}; }
1262 sub parseDataHash
1263 { my $self = shift; return %{$self->{parseDataHash}}; }
1264  
1265 sub lineNumOk
1266 { $_[0]->{lineNumOk} }
1267 }
1268  
1269 { package Language::Axbasic::Statement::addalias;
1270  
1271 use strict;
1272 use warnings;
1273 # use diagnostics;
1274  
1275 use Glib qw(TRUE FALSE);
1276  
1277 @Language::Axbasic::Statement::addalias::ISA = qw(
1278 Language::Axbasic
1279 Language::Axbasic::Statement
1280 );
1281  
1282 # ADDALIAS expression , expression [ , expression ]
1283  
1284 ##################
1285 # Methods
1286  
1287 sub parse {
1288  
1289 # Called by LA::Line->parse directly after a call to LA::Statement->new
1290 #
1291 # Expected arguments
1292 # (none besides $self)
1293 #
1294 # Return values
1295 # 'undef' on improper arguments or if there is an error
1296 # 1 otherwise
1297  
1298 my ($self, $check) = @_;
1299  
1300 # Local variables
1301 my ($stimulusExp, $responseExp, $nameExp, $token);
1302  
1303 # Check for improper arguments
1304 if (defined $check) {
1305  
1306 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1307 }
1308  
1309 # Convert the stimulus and response strings into expressions
1310 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1311 $self->scriptObj,
1312 $self->tokenGroupObj,
1313 );
1314  
1315 if (! defined $stimulusExp) {
1316  
1317 return $self->scriptObj->setError(
1318 'missing_or_illegal_expression',
1319 $self->_objClass . '->parse',
1320 );
1321 }
1322  
1323 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1324  
1325 return $self->scriptObj->setError(
1326 'syntax_error',
1327 $self->_objClass . '->parse',
1328 );
1329 }
1330  
1331 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
1332 $self->scriptObj,
1333 $self->tokenGroupObj,
1334 );
1335  
1336 if (! defined $responseExp) {
1337  
1338 return $self->scriptObj->setError(
1339 'missing_or_illegal_expression',
1340 $self->_objClass . '->parse',
1341 );
1342 }
1343  
1344 # Get the alias name, if specified
1345 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1346  
1347 $token = $self->tokenGroupObj->lookAhead();
1348 if (defined $token) {
1349  
1350 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
1351 $self->scriptObj,
1352 $self->tokenGroupObj,
1353 );
1354  
1355 if (! defined $nameExp) {
1356  
1357 return $self->scriptObj->setError(
1358 'missing_or_illegal_expression',
1359 $self->_objClass . '->parse',
1360 );
1361 }
1362 }
1363 }
1364  
1365 # Check that nothing follows the expressions
1366 if (! $self->tokenGroupObj->testStatementEnd()) {
1367  
1368 return $self->scriptObj->setError(
1369 'unexpected_keywords,_operators_or_expressions',
1370 $self->_objClass . '->parse',
1371 );
1372 }
1373  
1374 # Store the expressions, so $self->implement can retrieve them
1375 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
1376 $self->ivAdd('parseDataHash', 'response', $responseExp);
1377 # (If the third expession wasn't specified, $name will be 'undef'
1378 $self->ivAdd('parseDataHash', 'name', $nameExp);
1379  
1380 # Parsing complete
1381 return 1;
1382 }
1383  
1384 sub implement {
1385  
1386 # Called by LA::Line->implement directly after a call to $self->parse
1387 #
1388 # Expected arguments
1389 # (none besides $self)
1390 #
1391 # Return values
1392 # 'undef' on improper arguments or if there is an error
1393 # 1 otherwise
1394  
1395 my ($self, $check) = @_;
1396  
1397 # Local variables
1398 my (
1399 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
1400 );
1401  
1402 # Check for improper arguments
1403 if (defined $check) {
1404  
1405 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1406 }
1407  
1408 # Retrieve the arguments stored by $self->parse
1409 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
1410 $responseExp = $self->ivShow('parseDataHash', 'response');
1411 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
1412  
1413 # Evaluate each expression
1414 $stimulus = $stimulusExp->evaluate();
1415 $response = $responseExp->evaluate();
1416 if (defined $nameExp) {
1417  
1418 $name = $nameExp->evaluate();
1419 }
1420  
1421 # Specify which profile to use
1422 if (defined $self->scriptObj->useProfile) {
1423 $profile = $self->scriptObj->useProfile;
1424 } else {
1425 $profile = $self->scriptObj->session->currentWorld->name;
1426 }
1427  
1428 # Prepare the client command
1429 $string = 'addalias -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
1430 if ($name) {
1431  
1432 $string .= ' -n <' . $name . '>';
1433 }
1434  
1435 # Send the command
1436 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
1437  
1438 # Alias created successfully. Update the LA::Script IVs
1439 if (! $name) {
1440  
1441 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
1442 # specified
1443 $name = $stimulus;
1444 }
1445  
1446 $self->scriptObj->push_indepInterfaceList($name, $profile, 'alias');
1447 $self->scriptObj->set_indepInterfaceName($name);
1448  
1449 } else {
1450  
1451 # Store the fact that creation of the alias failed
1452 $self->scriptObj->set_indepInterfaceName(undef);
1453 }
1454  
1455 # Implementation complete
1456 return 1;
1457 }
1458 }
1459  
1460 { package Language::Axbasic::Statement::addgauge;
1461  
1462 use strict;
1463 use warnings;
1464 # use diagnostics;
1465  
1466 use Glib qw(TRUE FALSE);
1467  
1468 @Language::Axbasic::Statement::addgauge::ISA = qw(
1469 Language::Axbasic
1470 Language::Axbasic::Statement
1471 );
1472  
1473 # ADDGAUGE expression , expression [ , expression ] [ , expression ] [ , expression ]
1474 # ADDCONGAUGE expression , expression [ , expression ] [ , expression ] [ , expression ]
1475 # WINADDGAUGE expression , expression [ , expression ] [ , expression ] [ , expression ]
1476 # WINADDCONGAUGE expression , expression [ , expression ] [ , expression ] [ , expression ]
1477  
1478 ##################
1479 # Methods
1480  
1481 sub parse {
1482  
1483 # Called by LA::Line->parse directly after a call to LA::Statement->new
1484 #
1485 # Expected arguments
1486 # (none besides $self)
1487 #
1488 # Return values
1489 # 'undef' on improper arguments or if there is an error
1490 # 1 otherwise
1491  
1492 my ($self, $check) = @_;
1493  
1494 # Local variables
1495 my ($numberExp, $labelExp, $fullColExp, $emptyColExp, $labelColExp, $token);
1496  
1497 # Check for improper arguments
1498 if (defined $check) {
1499  
1500 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1501 }
1502  
1503 # Convert the compulsory arguments into expressions
1504 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
1505 $self->scriptObj,
1506 $self->tokenGroupObj,
1507 );
1508  
1509 if (! defined $numberExp) {
1510  
1511 return $self->scriptObj->setError(
1512 'missing_or_illegal_expression',
1513 $self->_objClass . '->parse',
1514 );
1515 }
1516  
1517 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1518  
1519 return $self->scriptObj->setError(
1520 'syntax_error',
1521 $self->_objClass . '->parse',
1522 );
1523 }
1524  
1525 $labelExp = Language::Axbasic::Expression::Arithmetic->new(
1526 $self->scriptObj,
1527 $self->tokenGroupObj,
1528 );
1529  
1530 if (! defined $labelExp) {
1531  
1532 return $self->scriptObj->setError(
1533 'missing_or_illegal_expression',
1534 $self->_objClass . '->parse',
1535 );
1536 }
1537  
1538 # Get the optional arguments, if specified
1539 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1540  
1541 $token = $self->tokenGroupObj->lookAhead();
1542 if (defined $token) {
1543  
1544 $fullColExp = Language::Axbasic::Expression::Arithmetic->new(
1545 $self->scriptObj,
1546 $self->tokenGroupObj,
1547 );
1548  
1549 if (! defined $fullColExp) {
1550  
1551 return $self->scriptObj->setError(
1552 'missing_or_illegal_expression',
1553 $self->_objClass . '->parse',
1554 );
1555 }
1556 }
1557 }
1558  
1559 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1560  
1561 $token = $self->tokenGroupObj->lookAhead();
1562 if (defined $token) {
1563  
1564 $emptyColExp = Language::Axbasic::Expression::Arithmetic->new(
1565 $self->scriptObj,
1566 $self->tokenGroupObj,
1567 );
1568  
1569 if (! defined $emptyColExp) {
1570  
1571 return $self->scriptObj->setError(
1572 'missing_or_illegal_expression',
1573 $self->_objClass . '->parse',
1574 );
1575 }
1576 }
1577 }
1578  
1579 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1580  
1581 $token = $self->tokenGroupObj->lookAhead();
1582 if (defined $token) {
1583  
1584 $labelColExp = Language::Axbasic::Expression::Arithmetic->new(
1585 $self->scriptObj,
1586 $self->tokenGroupObj,
1587 );
1588  
1589 if (! defined $labelColExp) {
1590  
1591 return $self->scriptObj->setError(
1592 'missing_or_illegal_expression',
1593 $self->_objClass . '->parse',
1594 );
1595 }
1596 }
1597 }
1598  
1599 # Check that nothing follows the expressions
1600 if (! $self->tokenGroupObj->testStatementEnd()) {
1601  
1602 return $self->scriptObj->setError(
1603 'unexpected_keywords,_operators_or_expressions',
1604 $self->_objClass . '->parse',
1605 );
1606 }
1607  
1608 # Store the expressions, so $self->implement can retrieve them
1609 $self->ivAdd('parseDataHash', 'number', $numberExp);
1610 $self->ivAdd('parseDataHash', 'label', $labelExp);
1611 $self->ivAdd('parseDataHash', 'full_col', $fullColExp); # 'undef' if not specified
1612 $self->ivAdd('parseDataHash', 'empty_col', $emptyColExp); # 'undef' if not specified
1613 $self->ivAdd('parseDataHash', 'label_col', $labelColExp); # 'undef' if not specified
1614  
1615 # Parsing complete
1616 return 1;
1617 }
1618  
1619 sub implement {
1620  
1621 # Called by LA::Line->implement directly after a call to $self->parse
1622 #
1623 # Expected arguments
1624 # (none besides $self)
1625 #
1626 # Return values
1627 # 'undef' on improper arguments or if there is an error
1628 # 1 otherwise
1629  
1630 my ($self, $check) = @_;
1631  
1632 # Local variables
1633 my (
1634 $numberExp, $labelExp, $fullColExp, $emptyColExp, $labelColExp, $number, $label,
1635 $fullCol, $emptyCol, $labelCol, $addFlag,
1636 );
1637  
1638 # Check for improper arguments
1639 if (defined $check) {
1640  
1641 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1642 }
1643  
1644 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
1645 if (! $self->scriptObj->parentTask) {
1646  
1647 # Implementation complete. Execution resumes from the next statement
1648 return 1;
1649 }
1650  
1651 # Retrieve the arguments stored by $self->parse
1652 $numberExp = $self->ivShow('parseDataHash', 'number');
1653 $labelExp = $self->ivShow('parseDataHash', 'label');
1654 $fullColExp = $self->ivShow('parseDataHash', 'full_col'); # May be 'undef'
1655 $emptyColExp = $self->ivShow('parseDataHash', 'empty_col'); # May be 'undef'
1656 $labelColExp = $self->ivShow('parseDataHash', 'label_col'); # May be 'undef'
1657  
1658 # Evaluate each expression
1659 $number = $numberExp->evaluate();
1660 $label = $labelExp->evaluate();
1661 if (defined $fullColExp) {
1662  
1663 $fullCol = $fullColExp->evaluate();
1664 }
1665  
1666 if (defined $emptyColExp) {
1667  
1668 $emptyCol = $emptyColExp->evaluate();
1669 }
1670  
1671 if (defined $labelColExp) {
1672  
1673 $labelCol = $labelColExp->evaluate();
1674 }
1675  
1676 # Check that the gauge number and label are valid. $number must be an integer, >= 0
1677 if ($number =~ m/\D/ || $number < 0) {
1678  
1679 return $self->scriptObj->setError(
1680 'invalid_gauge_number',
1681 $self->_objClass . '->implement',
1682 );
1683 }
1684  
1685 # Tell the Script task to add the gauge
1686 if ($self->keyword eq 'addgauge') {
1687  
1688 $self->scriptObj->parentTask->addMainWinGauge(
1689 $number,
1690 $label,
1691 FALSE,
1692 $fullCol,
1693 $emptyCol,
1694 $labelCol,
1695 );
1696  
1697 } elsif ($self->keyword eq 'addcongauge') {
1698  
1699 $self->scriptObj->parentTask->addMainWinGauge(
1700 $number,
1701 $label,
1702 TRUE,
1703 $fullCol,
1704 $emptyCol,
1705 $labelCol,
1706 );
1707  
1708 } elsif ($self->keyword eq 'winaddgauge' && $self->scriptObj->parentTask->winObj) {
1709  
1710 $self->scriptObj->parentTask->addTaskWinGauge(
1711 $number,
1712 $label,
1713 FALSE,
1714 $fullCol,
1715 $emptyCol,
1716 $labelCol,
1717 );
1718  
1719 } elsif ($self->keyword eq 'winaddcongauge' && $self->scriptObj->parentTask->winObj) {
1720  
1721 $self->scriptObj->parentTask->addTaskWinGauge(
1722 $number,
1723 $label,
1724 TRUE,
1725 $fullCol,
1726 $emptyCol,
1727 $labelCol,
1728 );
1729 }
1730  
1731 # Implementation complete
1732 return 1;
1733 }
1734 }
1735  
1736 { package Language::Axbasic::Statement::addhook;
1737  
1738 use strict;
1739 use warnings;
1740 # use diagnostics;
1741  
1742 use Glib qw(TRUE FALSE);
1743  
1744 @Language::Axbasic::Statement::addhook::ISA = qw(
1745 Language::Axbasic
1746 Language::Axbasic::Statement
1747 );
1748  
1749 # ADDHOOK expression , expression [ , expression ]
1750  
1751 ##################
1752 # Methods
1753  
1754 sub parse {
1755  
1756 # Called by LA::Line->parse directly after a call to LA::Statement->new
1757 #
1758 # Expected arguments
1759 # (none besides $self)
1760 #
1761 # Return values
1762 # 'undef' on improper arguments or if there is an error
1763 # 1 otherwise
1764  
1765 my ($self, $check) = @_;
1766  
1767 # Local variables
1768 my ($stimulusExp, $responseExp, $nameExp, $token);
1769  
1770 # Check for improper arguments
1771 if (defined $check) {
1772  
1773 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1774 }
1775  
1776 # Convert the stimulus and response strings into expressions
1777 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1778 $self->scriptObj,
1779 $self->tokenGroupObj,
1780 );
1781  
1782 if (! defined $stimulusExp) {
1783  
1784 return $self->scriptObj->setError(
1785 'missing_or_illegal_expression',
1786 $self->_objClass . '->parse',
1787 );
1788 }
1789  
1790 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1791  
1792 return $self->scriptObj->setError(
1793 'syntax_error',
1794 $self->_objClass . '->parse',
1795 );
1796 }
1797  
1798 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
1799 $self->scriptObj,
1800 $self->tokenGroupObj,
1801 );
1802  
1803 if (! defined $responseExp) {
1804  
1805 return $self->scriptObj->setError(
1806 'missing_or_illegal_expression',
1807 $self->_objClass . '->parse',
1808 );
1809 }
1810  
1811 # Get the hook name, if specified
1812 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1813  
1814 $token = $self->tokenGroupObj->lookAhead();
1815 if (defined $token) {
1816  
1817 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
1818 $self->scriptObj,
1819 $self->tokenGroupObj,
1820 );
1821  
1822 if (! defined $nameExp) {
1823  
1824 return $self->scriptObj->setError(
1825 'missing_or_illegal_expression',
1826 $self->_objClass . '->parse',
1827 );
1828 }
1829 }
1830 }
1831  
1832 # Check that nothing follows the expressions
1833 if (! $self->tokenGroupObj->testStatementEnd()) {
1834  
1835 return $self->scriptObj->setError(
1836 'unexpected_keywords,_operators_or_expressions',
1837 $self->_objClass . '->parse',
1838 );
1839 }
1840  
1841 # Store the expressions, so $self->implement can retrieve them
1842 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
1843 $self->ivAdd('parseDataHash', 'response', $responseExp);
1844 # (If the third expession wasn't specified, $name will be 'undef'
1845 $self->ivAdd('parseDataHash', 'name', $nameExp);
1846  
1847 # Parsing complete
1848 return 1;
1849 }
1850  
1851 sub implement {
1852  
1853 # Called by LA::Line->implement directly after a call to $self->parse
1854 #
1855 # Expected arguments
1856 # (none besides $self)
1857 #
1858 # Return values
1859 # 'undef' on improper arguments or if there is an error
1860 # 1 otherwise
1861  
1862 my ($self, $check) = @_;
1863  
1864 # Local variables
1865 my (
1866 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
1867 );
1868  
1869 # Check for improper arguments
1870 if (defined $check) {
1871  
1872 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
1873 }
1874  
1875 # Retrieve the arguments stored by $self->parse
1876 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
1877 $responseExp = $self->ivShow('parseDataHash', 'response');
1878 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
1879  
1880 # Evaluate each expression
1881 $stimulus = $stimulusExp->evaluate();
1882 $response = $responseExp->evaluate();
1883 if (defined $nameExp) {
1884  
1885 $name = $nameExp->evaluate();
1886 }
1887  
1888 # Specify which profile to use
1889 if (defined $self->scriptObj->useProfile) {
1890 $profile = $self->scriptObj->useProfile;
1891 } else {
1892 $profile = $self->scriptObj->session->currentWorld->name;
1893 }
1894  
1895 # Prepare the client command
1896 $string = 'addhook -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
1897 if ($name) {
1898  
1899 $string .= ' -n <' . $name . '>';
1900 }
1901  
1902 # Send the command
1903 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
1904  
1905 # Hook created successfully. Update the LA::Script IVs
1906 if (! $name) {
1907  
1908 # GenericCommand->addHookEtc uses the stimulus as a name, if no name is specified
1909 $name = $stimulus;
1910 }
1911  
1912 $self->scriptObj->push_indepInterfaceList($name, $profile, 'hook');
1913 $self->scriptObj->set_indepInterfaceName($name);
1914  
1915  
1916 } else {
1917  
1918 # Store the fact that creation of the hook failed
1919 $self->scriptObj->set_indepInterfaceName(undef);
1920 }
1921  
1922 # Implementation complete
1923 return 1;
1924 }
1925 }
1926  
1927 { package Language::Axbasic::Statement::addmacro;
1928  
1929 use strict;
1930 use warnings;
1931 # use diagnostics;
1932  
1933 use Glib qw(TRUE FALSE);
1934  
1935 @Language::Axbasic::Statement::addmacro::ISA = qw(
1936 Language::Axbasic
1937 Language::Axbasic::Statement
1938 );
1939  
1940 # ADDMACRO expression , expression [ , expression ]
1941  
1942 ##################
1943 # Methods
1944  
1945 sub parse {
1946  
1947 # Called by LA::Line->parse directly after a call to LA::Statement->new
1948 #
1949 # Expected arguments
1950 # (none besides $self)
1951 #
1952 # Return values
1953 # 'undef' on improper arguments or if there is an error
1954 # 1 otherwise
1955  
1956 my ($self, $check) = @_;
1957  
1958 # Local variables
1959 my ($stimulusExp, $responseExp, $nameExp, $token);
1960  
1961 # Check for improper arguments
1962 if (defined $check) {
1963  
1964 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
1965 }
1966  
1967 # Convert the stimulus and response strings into expressions
1968 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
1969 $self->scriptObj,
1970 $self->tokenGroupObj,
1971 );
1972  
1973 if (! defined $stimulusExp) {
1974  
1975 return $self->scriptObj->setError(
1976 'missing_or_illegal_expression',
1977 $self->_objClass . '->parse',
1978 );
1979 }
1980  
1981 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
1982  
1983 return $self->scriptObj->setError(
1984 'syntax_error',
1985 $self->_objClass . '->parse',
1986 );
1987 }
1988  
1989 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
1990 $self->scriptObj,
1991 $self->tokenGroupObj,
1992 );
1993  
1994 if (! defined $responseExp) {
1995  
1996 return $self->scriptObj->setError(
1997 'missing_or_illegal_expression',
1998 $self->_objClass . '->parse',
1999 );
2000 }
2001  
2002 # Get the macro name, if specified
2003 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2004  
2005 $token = $self->tokenGroupObj->lookAhead();
2006 if (defined $token) {
2007  
2008 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
2009 $self->scriptObj,
2010 $self->tokenGroupObj,
2011 );
2012  
2013 if (! defined $nameExp) {
2014  
2015 return $self->scriptObj->setError(
2016 'missing_or_illegal_expression',
2017 $self->_objClass . '->parse',
2018 );
2019 }
2020 }
2021 }
2022  
2023 # Check that nothing follows the expressions
2024 if (! $self->tokenGroupObj->testStatementEnd()) {
2025  
2026 return $self->scriptObj->setError(
2027 'unexpected_keywords,_operators_or_expressions',
2028 $self->_objClass . '->parse',
2029 );
2030 }
2031  
2032 # Store the expressions, so $self->implement can retrieve them
2033 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
2034 $self->ivAdd('parseDataHash', 'response', $responseExp);
2035 # (If the third expession wasn't specified, $name will be 'undef'
2036 $self->ivAdd('parseDataHash', 'name', $nameExp);
2037  
2038 # Parsing complete
2039 return 1;
2040 }
2041  
2042 sub implement {
2043  
2044 # Called by LA::Line->implement directly after a call to $self->parse
2045 #
2046 # Expected arguments
2047 # (none besides $self)
2048 #
2049 # Return values
2050 # 'undef' on improper arguments or if there is an error
2051 # 1 otherwise
2052  
2053 my ($self, $check) = @_;
2054  
2055 # Local variables
2056 my (
2057 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
2058 );
2059  
2060 # Check for improper arguments
2061 if (defined $check) {
2062  
2063 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2064 }
2065  
2066 # Retrieve the arguments stored by $self->parse
2067 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
2068 $responseExp = $self->ivShow('parseDataHash', 'response');
2069 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2070  
2071 # Evaluate each expression
2072 $stimulus = $stimulusExp->evaluate();
2073 $response = $responseExp->evaluate();
2074 if (defined $nameExp) {
2075  
2076 $name = $nameExp->evaluate();
2077 }
2078  
2079 # Specify which profile to use
2080 if (defined $self->scriptObj->useProfile) {
2081 $profile = $self->scriptObj->useProfile;
2082 } else {
2083 $profile = $self->scriptObj->session->currentWorld->name;
2084 }
2085  
2086 # Prepare the client command
2087 $string = 'addmacro -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2088 if ($name) {
2089  
2090 $string .= ' -n <' . $name . '>';
2091 }
2092  
2093 # Send the command
2094 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2095  
2096 # Macro created successfully. Update the LA::Script IVs
2097 if (! $name) {
2098  
2099 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
2100 # specified
2101 $name = $stimulus;
2102 }
2103  
2104 $self->scriptObj->push_indepInterfaceList($name, $profile, 'macro');
2105 $self->scriptObj->set_indepInterfaceName($name);
2106  
2107 } else {
2108  
2109 # Store the fact that creation of the macro failed
2110 $self->scriptObj->set_indepInterfaceName(undef);
2111 }
2112  
2113 # Implementation complete
2114 return 1;
2115 }
2116 }
2117  
2118 { package Language::Axbasic::Statement::addstatus;
2119  
2120 use strict;
2121 use warnings;
2122 # use diagnostics;
2123  
2124 use Glib qw(TRUE FALSE);
2125  
2126 @Language::Axbasic::Statement::addstatus::ISA = qw(
2127 Language::Axbasic
2128 Language::Axbasic::Statement
2129 );
2130  
2131 # ADDSTATUS expression , expression
2132 # ADDCONSTATUS expression , expression
2133 # WINADDSTATUS expression , expression
2134 # WINADDCONSTATUS expression , expression
2135  
2136 ##################
2137 # Methods
2138  
2139 sub parse {
2140  
2141 # Called by LA::Line->parse directly after a call to LA::Statement->new
2142 #
2143 # Expected arguments
2144 # (none besides $self)
2145 #
2146 # Return values
2147 # 'undef' on improper arguments or if there is an error
2148 # 1 otherwise
2149  
2150 my ($self, $check) = @_;
2151  
2152 # Local variables
2153 my ($numberExp, $labelExp, $token);
2154  
2155 # Check for improper arguments
2156 if (defined $check) {
2157  
2158 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2159 }
2160  
2161 # Convert the compulsory arguments into expressions
2162 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
2163 $self->scriptObj,
2164 $self->tokenGroupObj,
2165 );
2166  
2167 if (! defined $numberExp) {
2168  
2169 return $self->scriptObj->setError(
2170 'missing_or_illegal_expression',
2171 $self->_objClass . '->parse',
2172 );
2173 }
2174  
2175 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2176  
2177 return $self->scriptObj->setError(
2178 'syntax_error',
2179 $self->_objClass . '->parse',
2180 );
2181 }
2182  
2183 $labelExp = Language::Axbasic::Expression::Arithmetic->new(
2184 $self->scriptObj,
2185 $self->tokenGroupObj,
2186 );
2187  
2188 if (! defined $labelExp) {
2189  
2190 return $self->scriptObj->setError(
2191 'missing_or_illegal_expression',
2192 $self->_objClass . '->parse',
2193 );
2194 }
2195  
2196 # Check that nothing follows the expressions
2197 if (! $self->tokenGroupObj->testStatementEnd()) {
2198  
2199 return $self->scriptObj->setError(
2200 'unexpected_keywords,_operators_or_expressions',
2201 $self->_objClass . '->parse',
2202 );
2203 }
2204  
2205 # Store the expressions, so $self->implement can retrieve them
2206 $self->ivAdd('parseDataHash', 'number', $numberExp);
2207 $self->ivAdd('parseDataHash', 'label', $labelExp);
2208  
2209 # Parsing complete
2210 return 1;
2211 }
2212  
2213 sub implement {
2214  
2215 # Called by LA::Line->implement directly after a call to $self->parse
2216 #
2217 # Expected arguments
2218 # (none besides $self)
2219 #
2220 # Return values
2221 # 'undef' on improper arguments or if there is an error
2222 # 1 otherwise
2223  
2224 my ($self, $check) = @_;
2225  
2226 # Local variables
2227 my ($numberExp, $labelExp, $number, $label, $addFlag);
2228  
2229 # Check for improper arguments
2230 if (defined $check) {
2231  
2232 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2233 }
2234  
2235 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
2236 if (! $self->scriptObj->parentTask) {
2237  
2238 # Implementation complete. Execution resumes from the next statement
2239 return 1;
2240 }
2241  
2242 # Retrieve the arguments stored by $self->parse
2243 $numberExp = $self->ivShow('parseDataHash', 'number');
2244 $labelExp = $self->ivShow('parseDataHash', 'label');
2245  
2246 # Evaluate each expression
2247 $number = $numberExp->evaluate();
2248 $label = $labelExp->evaluate();
2249  
2250 # Check that the status bar number and label are valid. $number must be an integer, >= 0
2251 if ($number =~ m/\D/ || $number < 0) {
2252  
2253 return $self->scriptObj->setError(
2254 'invalid_status_bar_number',
2255 $self->_objClass . '->implement',
2256 );
2257 }
2258  
2259 # Tell the Script task to add the status bar
2260 if ($self->keyword eq 'addstatus') {
2261 $self->scriptObj->parentTask->addMainWinStatusBar($number, $label, FALSE);
2262 } elsif ($self->keyword eq 'addconstatus') {
2263 $self->scriptObj->parentTask->addMainWinStatusBar($number, $label, TRUE);
2264 } elsif ($self->keyword eq 'winaddstatus') {
2265 $self->scriptObj->parentTask->addTaskWinStatusBar($number, $label, FALSE);
2266 } elsif ($self->keyword eq 'winaddconstatus') {
2267 $self->scriptObj->parentTask->addTaskWinStatusBar($number, $label, TRUE);
2268 }
2269  
2270 # Implementation complete
2271 return 1;
2272 }
2273 }
2274  
2275 { package Language::Axbasic::Statement::addtimer;
2276  
2277 use strict;
2278 use warnings;
2279 # use diagnostics;
2280  
2281 use Glib qw(TRUE FALSE);
2282  
2283 @Language::Axbasic::Statement::addtimer::ISA = qw(
2284 Language::Axbasic
2285 Language::Axbasic::Statement
2286 );
2287  
2288 # ADDTIMER expression , expression [ , expression ]
2289  
2290 ##################
2291 # Methods
2292  
2293 sub parse {
2294  
2295 # Called by LA::Line->parse directly after a call to LA::Statement->new
2296 #
2297 # Expected arguments
2298 # (none besides $self)
2299 #
2300 # Return values
2301 # 'undef' on improper arguments or if there is an error
2302 # 1 otherwise
2303  
2304 my ($self, $check) = @_;
2305  
2306 # Local variables
2307 my ($stimulusExp, $responseExp, $nameExp, $token);
2308  
2309 # Check for improper arguments
2310 if (defined $check) {
2311  
2312 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2313 }
2314  
2315 # Convert the interval and action strings into expressions
2316 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
2317 $self->scriptObj,
2318 $self->tokenGroupObj,
2319 );
2320  
2321 if (! defined $stimulusExp) {
2322  
2323 return $self->scriptObj->setError(
2324 'missing_or_illegal_expression',
2325 $self->_objClass . '->parse',
2326 );
2327 }
2328  
2329 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2330  
2331 return $self->scriptObj->setError(
2332 'syntax_error',
2333 $self->_objClass . '->parse',
2334 );
2335 }
2336  
2337 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
2338 $self->scriptObj,
2339 $self->tokenGroupObj,
2340 );
2341  
2342 if (! defined $responseExp) {
2343  
2344 return $self->scriptObj->setError(
2345 'missing_or_illegal_expression',
2346 $self->_objClass . '->parse',
2347 );
2348 }
2349  
2350 # Get the timer name, if specified
2351 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2352  
2353 $token = $self->tokenGroupObj->lookAhead();
2354 if (defined $token) {
2355  
2356 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
2357 $self->scriptObj,
2358 $self->tokenGroupObj,
2359 );
2360  
2361 if (! defined $nameExp) {
2362  
2363 return $self->scriptObj->setError(
2364 'missing_or_illegal_expression',
2365 $self->_objClass . '->parse',
2366 );
2367 }
2368 }
2369 }
2370  
2371 # Check that nothing follows the expressions
2372 if (! $self->tokenGroupObj->testStatementEnd()) {
2373  
2374 return $self->scriptObj->setError(
2375 'unexpected_keywords,_operators_or_expressions',
2376 $self->_objClass . '->parse',
2377 );
2378 }
2379  
2380 # Store the expressions, so $self->implement can retrieve them
2381 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
2382 $self->ivAdd('parseDataHash', 'response', $responseExp);
2383 # (If the third expession wasn't specified, $name will be 'undef'
2384 $self->ivAdd('parseDataHash', 'name', $nameExp);
2385  
2386 # Parsing complete
2387 return 1;
2388 }
2389  
2390 sub implement {
2391  
2392 # Called by LA::Line->implement directly after a call to $self->parse
2393 #
2394 # Expected arguments
2395 # (none besides $self)
2396 #
2397 # Return values
2398 # 'undef' on improper arguments or if there is an error
2399 # 1 otherwise
2400  
2401 my ($self, $check) = @_;
2402  
2403 # Local variables
2404 my (
2405 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
2406 );
2407  
2408 # Check for improper arguments
2409 if (defined $check) {
2410  
2411 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2412 }
2413  
2414 # Retrieve the arguments stored by $self->parse
2415 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
2416 $responseExp = $self->ivShow('parseDataHash', 'response');
2417 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2418  
2419 # Evaluate each expression
2420 $stimulus = $stimulusExp->evaluate();
2421 $response = $responseExp->evaluate();
2422 if (defined $nameExp) {
2423  
2424 $name = $nameExp->evaluate();
2425 }
2426  
2427 # Specify which profile to use
2428 if (defined $self->scriptObj->useProfile) {
2429 $profile = $self->scriptObj->useProfile;
2430 } else {
2431 $profile = $self->scriptObj->session->currentWorld->name;
2432 }
2433  
2434 # Prepare the client command
2435 $string = 'addtimer -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2436 if ($name) {
2437  
2438 $string .= ' -n <' . $name . '>';
2439 }
2440  
2441 # Send the command
2442 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2443  
2444 # Timer created successfully. Update the LA::Script IVs
2445 if (! $name) {
2446  
2447 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
2448 # specified
2449 $name = $stimulus;
2450 }
2451  
2452 $self->scriptObj->push_indepInterfaceList($name, $profile, 'timer');
2453 $self->scriptObj->set_indepInterfaceName($name);
2454  
2455 } else {
2456  
2457 # Store the fact that creation of the timer failed
2458 $self->scriptObj->set_indepInterfaceName(undef);
2459 }
2460  
2461 # Implementation complete
2462 return 1;
2463 }
2464 }
2465  
2466 { package Language::Axbasic::Statement::addtrig;
2467  
2468 use strict;
2469 use warnings;
2470 # use diagnostics;
2471  
2472 use Glib qw(TRUE FALSE);
2473  
2474 @Language::Axbasic::Statement::addtrig::ISA = qw(
2475 Language::Axbasic
2476 Language::Axbasic::Statement
2477 );
2478  
2479 # ADDTRIG expression , expression [ , expression ]
2480  
2481 ##################
2482 # Methods
2483  
2484 sub parse {
2485  
2486 # Called by LA::Line->parse directly after a call to LA::Statement->new
2487 #
2488 # Expected arguments
2489 # (none besides $self)
2490 #
2491 # Return values
2492 # 'undef' on improper arguments or if there is an error
2493 # 1 otherwise
2494  
2495 my ($self, $check) = @_;
2496  
2497 # Local variables
2498 my ($stimulusExp, $responseExp, $nameExp, $token);
2499  
2500 # Check for improper arguments
2501 if (defined $check) {
2502  
2503 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2504 }
2505  
2506 # Convert the pattern and action strings into expressions
2507 $stimulusExp = Language::Axbasic::Expression::Arithmetic->new(
2508 $self->scriptObj,
2509 $self->tokenGroupObj,
2510 );
2511  
2512 if (! defined $stimulusExp) {
2513  
2514 return $self->scriptObj->setError(
2515 'missing_or_illegal_expression',
2516 $self->_objClass . '->parse',
2517 );
2518 }
2519  
2520 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2521  
2522 return $self->scriptObj->setError(
2523 'syntax_error',
2524 $self->_objClass . '->parse',
2525 );
2526 }
2527  
2528 $responseExp = Language::Axbasic::Expression::Arithmetic->new(
2529 $self->scriptObj,
2530 $self->tokenGroupObj,
2531 );
2532  
2533 if (! defined $responseExp) {
2534  
2535 return $self->scriptObj->setError(
2536 'missing_or_illegal_expression',
2537 $self->_objClass . '->parse',
2538 );
2539 }
2540  
2541 # Get the trigger name, if specified
2542 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
2543  
2544 $token = $self->tokenGroupObj->lookAhead();
2545 if (defined $token) {
2546  
2547 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
2548 $self->scriptObj,
2549 $self->tokenGroupObj,
2550 );
2551  
2552 if (! defined $nameExp) {
2553  
2554 return $self->scriptObj->setError(
2555 'missing_or_illegal_expression',
2556 $self->_objClass . '->parse',
2557 );
2558 }
2559 }
2560 }
2561  
2562 # Check that nothing follows the expressions
2563 if (! $self->tokenGroupObj->testStatementEnd()) {
2564  
2565 return $self->scriptObj->setError(
2566 'unexpected_keywords,_operators_or_expressions',
2567 $self->_objClass . '->parse',
2568 );
2569 }
2570  
2571 # Store the expressions, so $self->implement can retrieve them
2572 $self->ivAdd('parseDataHash', 'stimulus', $stimulusExp);
2573 $self->ivAdd('parseDataHash', 'response', $responseExp);
2574 # (If the third expession wasn't specified, $name will be 'undef'
2575 $self->ivAdd('parseDataHash', 'name', $nameExp);
2576  
2577 # Parsing complete
2578 return 1;
2579 }
2580  
2581 sub implement {
2582  
2583 # Called by LA::Line->implement directly after a call to $self->parse
2584 #
2585 # Expected arguments
2586 # (none besides $self)
2587 #
2588 # Return values
2589 # 'undef' on improper arguments or if there is an error
2590 # 1 otherwise
2591  
2592 my ($self, $check) = @_;
2593  
2594 # Local variables
2595 my (
2596 $stimulusExp, $stimulus, $responseExp, $response, $nameExp, $name, $string, $profile,
2597 );
2598  
2599 # Check for improper arguments
2600 if (defined $check) {
2601  
2602 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2603 }
2604  
2605 # Retrieve the arguments stored by $self->parse
2606 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
2607 $responseExp = $self->ivShow('parseDataHash', 'response');
2608 $nameExp = $self->ivShow('parseDataHash', 'name'); # May be 'undef'
2609  
2610 # Evaluate each expression
2611 $stimulus = $stimulusExp->evaluate();
2612 $response = $responseExp->evaluate();
2613 if (defined $nameExp) {
2614  
2615 $name = $nameExp->evaluate();
2616 }
2617  
2618 # Specify which profile to use
2619 if (defined $self->scriptObj->useProfile) {
2620 $profile = $self->scriptObj->useProfile;
2621 } else {
2622 $profile = $self->scriptObj->session->currentWorld->name;
2623 }
2624  
2625 # Prepare the client command
2626 $string = 'addtrigger -s <' . $stimulus . '> -p <' . $response . '> -d ' . $profile;
2627 if ($name) {
2628  
2629 $string .= ' -n <' . $name . '>';
2630 }
2631  
2632 # Send the command
2633 if ($self->scriptObj->session->pseudoCmd($string, $self->scriptObj->pseudoCmdMode)) {
2634  
2635 # Trigger created successfully. Update the LA::Script IVs
2636 if (! $name) {
2637  
2638 # GA::Generic::Cmd->addInterface uses the stimulus as a name, if no name is
2639 # specified
2640 $name = $stimulus;
2641 }
2642  
2643 $self->scriptObj->push_indepInterfaceList($name, $profile, 'trigger');
2644 $self->scriptObj->set_indepInterfaceName($name);
2645  
2646 } else {
2647  
2648 # Store the fact that creation of the trigger failed
2649 $self->scriptObj->set_indepInterfaceName(undef);
2650 }
2651  
2652 # Implementation complete
2653 return 1;
2654 }
2655 }
2656  
2657 { package Language::Axbasic::Statement::beep;
2658  
2659 use strict;
2660 use warnings;
2661 # use diagnostics;
2662  
2663 use Glib qw(TRUE FALSE);
2664  
2665 @Language::Axbasic::Statement::beep::ISA = qw(
2666 Language::Axbasic
2667 Language::Axbasic::Statement
2668 );
2669  
2670 # BEEP
2671  
2672 ##################
2673 # Methods
2674  
2675 sub parse {
2676  
2677 # Called by LA::Line->parse directly after a call to LA::Statement->new
2678 #
2679 # Expected arguments
2680 # (none besides $self)
2681 #
2682 # Return values
2683 # 'undef' on improper arguments or if there is an error
2684 # 1 otherwise
2685  
2686 my ($self, $check) = @_;
2687  
2688 # Check for improper arguments
2689 if (defined $check) {
2690  
2691 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2692 }
2693  
2694 # BEEP statements always appear on their own
2695 if (! $self->tokenGroupObj->testStatementEnd()) {
2696  
2697 return $self->scriptObj->setError(
2698 'unexpected_keywords,_operators_or_expressions',
2699 $self->_objClass . '->parse',
2700 );
2701 }
2702  
2703 # Parsing complete
2704 return 1;
2705 }
2706  
2707 sub implement {
2708  
2709 # Called by LA::Line->implement directly after a call to $self->parse
2710 #
2711 # Expected arguments
2712 # (none besides $self)
2713 #
2714 # Return values
2715 # 'undef' on improper arguments or if there is an error
2716 # 1 otherwise
2717  
2718 my ($self, $check) = @_;
2719  
2720 # Check for improper arguments
2721 if (defined $check) {
2722  
2723 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2724 }
2725  
2726 # Check that the sound effect exists
2727 if (
2728 ! $axmud::CLIENT->ivExists('customSoundHash', 'beep')
2729 || ! $axmud::CLIENT->ivShow('customSoundHash', 'beep')
2730 ) {
2731 return $self->scriptObj->setError(
2732 'beep_not_available',
2733 $self->_objClass . '->implement',
2734 );
2735  
2736 } else {
2737  
2738 # Play the sound effect (if allowed)
2739 $axmud::CLIENT->playSound('beep');
2740 }
2741  
2742 # Implementation complete
2743 return 1;
2744 }
2745 }
2746  
2747 { package Language::Axbasic::Statement::break;
2748  
2749 use strict;
2750 use warnings;
2751 # use diagnostics;
2752  
2753 use Glib qw(TRUE FALSE);
2754  
2755 @Language::Axbasic::Statement::break::ISA = qw(
2756 Language::Axbasic
2757 Language::Axbasic::Statement
2758 );
2759  
2760 # BREAK
2761  
2762 ##################
2763 # Methods
2764  
2765 sub parse {
2766  
2767 # Called by LA::Line->parse directly after a call to LA::Statement->new
2768 #
2769 # Expected arguments
2770 # (none besides $self)
2771 #
2772 # Return values
2773 # 'undef' on improper arguments or if there is an error
2774 # 1 otherwise
2775  
2776 my ($self, $check) = @_;
2777  
2778 # Check for improper arguments
2779 if (defined $check) {
2780  
2781 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2782 }
2783  
2784 # BREAK statements always appear on their own
2785 if (! $self->tokenGroupObj->testStatementEnd()) {
2786  
2787 return $self->scriptObj->setError(
2788 'unexpected_keywords,_operators_or_expressions',
2789 $self->_objClass . '->parse',
2790 );
2791 }
2792  
2793 # Parsing complete
2794 return 1;
2795 }
2796  
2797 sub implement {
2798  
2799 # Called by LA::Line->implement directly after a call to $self->parse
2800 #
2801 # Expected arguments
2802 # (none besides $self)
2803 #
2804 # Return values
2805 # 'undef' on improper arguments or if there is an error
2806 # 1 otherwise
2807  
2808 my ($self, $check) = @_;
2809  
2810 # Check for improper arguments
2811 if (defined $check) {
2812  
2813 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2814 }
2815  
2816 # If the Axbasic script is being run from within an Axmud task, pause execution until the
2817 # next task loop. Otherwise, do nothing
2818 if ($self->scriptObj->parentTask) {
2819  
2820 $self->scriptObj->set_scriptStatus('paused');
2821  
2822 # Reset the number of steps to take, before taking an automatic pause
2823 $self->scriptObj->set_stepCount(0);
2824 }
2825  
2826 # Implementation complete
2827 return 1;
2828 }
2829 }
2830  
2831 { package Language::Axbasic::Statement::bypass;
2832  
2833 use strict;
2834 use warnings;
2835 # use diagnostics;
2836  
2837 use Glib qw(TRUE FALSE);
2838  
2839 @Language::Axbasic::Statement::bypass::ISA = qw(
2840 Language::Axbasic
2841 Language::Axbasic::Statement
2842 );
2843  
2844 # BYPASS expression
2845  
2846 ##################
2847 # Methods
2848  
2849 sub parse {
2850  
2851 # Called by LA::Line->parse directly after a call to LA::Statement->new
2852 #
2853 # Expected arguments
2854 # (none besides $self)
2855 #
2856 # Return values
2857 # 'undef' on improper arguments or if there is an error
2858 # 1 otherwise
2859  
2860 my ($self, $check) = @_;
2861  
2862 # Local variables
2863 my $expression;
2864  
2865 # Check for improper arguments
2866 if (defined $check) {
2867  
2868 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2869 }
2870  
2871 # Get the expression and store it for ->implement to use
2872 $expression = Language::Axbasic::Expression::Arithmetic->new(
2873 $self->scriptObj,
2874 $self->tokenGroupObj,
2875 );
2876  
2877 if (! defined $expression) {
2878  
2879 return $self->scriptObj->setError(
2880 'missing_or_illegal_expression',
2881 $self->_objClass . '->parse',
2882 );
2883  
2884 } else {
2885  
2886 $self->ivAdd('parseDataHash', 'expression', $expression);
2887 }
2888  
2889 # There should be nothing after the expression
2890 if (! $self->tokenGroupObj->testStatementEnd()) {
2891  
2892 return $self->scriptObj->setError(
2893 'unexpected_keywords,_operators_or_expressions',
2894 $self->_objClass . '->parse',
2895 );
2896 }
2897  
2898 # Parsing complete
2899 return 1;
2900 }
2901  
2902 sub implement {
2903  
2904 # Called by LA::Line->implement directly after a call to $self->parse
2905 #
2906 # Expected arguments
2907 # (none besides $self)
2908 #
2909 # Return values
2910 # 'undef' on improper arguments or if there is an error
2911 # 1 otherwise
2912  
2913 my ($self, $check) = @_;
2914  
2915 # Local variables
2916 my ($expression, $string);
2917  
2918 # Check for improper arguments
2919 if (defined $check) {
2920  
2921 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
2922 }
2923  
2924 # Retrieve the expression to be written
2925 $expression = $self->ivShow('parseDataHash', 'expression');
2926 # Evaluate the expression to get a scalar value
2927 $string = $expression->evaluate();
2928  
2929 # Execute the expression as a bypass command
2930 $self->scriptObj->session->worldCmd($string, undef, undef, TRUE);
2931  
2932 # Implementation complete
2933 return 1;
2934 }
2935 }
2936  
2937 { package Language::Axbasic::Statement::call;
2938  
2939 use strict;
2940 use warnings;
2941 # use diagnostics;
2942  
2943 use Glib qw(TRUE FALSE);
2944  
2945 @Language::Axbasic::Statement::call::ISA = qw(
2946 Language::Axbasic
2947 Language::Axbasic::Statement
2948 );
2949  
2950 # CALL subroutine-name
2951 # CALL subroutine-name ( [ expression [ , expression ... ] ] )
2952  
2953 ##################
2954 # Methods
2955  
2956 sub parse {
2957  
2958 # Called by LA::Line->parse directly after a call to LA::Statement->new
2959 #
2960 # Expected arguments
2961 # (none besides $self)
2962 #
2963 # Optional arguments
2964 # $letStatement - When this function is called from within a LET statement,
2965 # i.e. 'LET a$ = CALL func_name (arg$)', which LET statement called
2966 # this one
2967 #
2968 # Return values
2969 # 'undef' on improper arguments or if there is an error
2970 # 1 otherwise
2971  
2972 my ($self, $letStatement, $check) = @_;
2973  
2974 # Local variables
2975 my ($subNameToken, $subName, $argListObj);
2976  
2977 # Check for improper arguments
2978 if (defined $check) {
2979  
2980 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
2981 }
2982  
2983 # If $letStatement was specified, use it
2984 if ($letStatement) {
2985  
2986 $self = $letStatement;
2987 }
2988  
2989 # The 'call' keyword is not available in primitive numbering mode
2990 if ($self->scriptObj->executionMode ne 'no_line_num') {
2991  
2992 return $self->scriptObj->setError(
2993 'statement_not_available_with_line_numbers',
2994 $self->_objClass . '->parse',
2995 );
2996 }
2997  
2998 # Check there's a subroutine name to be got...
2999 if (defined $self->tokenGroupObj->testStatementEnd()) {
3000  
3001 return $self->scriptObj->setError(
3002 'unspecified_subroutine',
3003 $self->_objClass . '->parse',
3004 );
3005 }
3006  
3007 # Get the subroutine name
3008 $subNameToken = $self->tokenGroupObj->shiftToken();
3009 if (! defined $subNameToken) {
3010  
3011 return $self->scriptObj->setError(
3012 'unspecified_subroutine',
3013 $self->_objClass . '->parse',
3014 );
3015 }
3016  
3017 # Get an argument list. The TRUE argument means that an empty token group is treated
3018 # the same an empty arglist, in this case (e.g. 'CALL hello ()' and 'CALL hello' are both
3019 # acceptable)
3020 $argListObj = Language::Axbasic::Expression::ArgList->new(
3021 $self->scriptObj,
3022 $self->tokenGroupObj,
3023 TRUE,
3024 );
3025  
3026 if (! defined $argListObj) {
3027  
3028 return $self->scriptObj->setError(
3029 'missing_or_invalid_argument_list',
3030 $self->_objClass . '->parse',
3031 );
3032 }
3033  
3034 # Check that there is nothing after the list of arguments (except for the statement
3035 # separator, : )
3036 if (! $self->tokenGroupObj->testStatementEnd()) {
3037  
3038 return $self->scriptObj->setError(
3039 'unexpected_keywords,_operators_or_expressions',
3040 $self->_objClass . '->parse',
3041 );
3042 }
3043  
3044 # Store the subroutine name and its argument list for ->implement to use
3045 $self->ivAdd('parseDataHash', 'sub_name', $subNameToken->tokenText);
3046 $self->ivAdd('parseDataHash', 'arg_list_obj', $argListObj);
3047  
3048 # Parsing complete
3049 return 1;
3050 }
3051  
3052 sub implement {
3053  
3054 # Called by LA::Line->implement directly after a call to $self->parse
3055 #
3056 # Expected arguments
3057 # (none besides $self)
3058 #
3059 # Optional arguments
3060 # $letStatement - When this function is called from within a LET statement,
3061 # i.e. 'LET a$ = CALL func_name (arg$)', which LET statement called
3062 # this one
3063 #
3064 # Return values
3065 # 'undef' on improper arguments
3066 # 1 otherwise
3067  
3068 my ($self, $letStatement, $check) = @_;
3069  
3070 # Local variables
3071 my (
3072 $returnVar, $subName, $argListObj, $subObj, $declareStatement,
3073 @callArgList, @subArgList,
3074 );
3075  
3076 # Check for improper arguments
3077 if (defined $check) {
3078  
3079 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3080 }
3081  
3082 # If $letStatement was specified, use it
3083 if ($letStatement) {
3084  
3085 $self = $letStatement;
3086 # The subroutine's return value must be assigned to this variable
3087 $returnVar = $self->ivShow('parseDataHash', 'call_var');
3088 }
3089  
3090 # Retrieve the variables stored by ->parse
3091 $subName = $self->ivShow('parseDataHash', 'sub_name');
3092 $argListObj = $self->ivShow('parseDataHash', 'arg_list_obj');
3093  
3094 # Check that a subroutine with the same name has been declared
3095 if (! $self->scriptObj->ivExists('subNameHash', $subName)) {
3096  
3097 return $self->scriptObj->setError(
3098 'no_such_function_or_subroutine',
3099 $self->_objClass . '->implement',
3100 );
3101  
3102 } else {
3103  
3104 $subObj = $self->scriptObj->ivShow('subNameHash', $subName);
3105 }
3106  
3107 # We need to check that the arguments specified in the CALL statement are of the same
3108 # number, and of the same type, as the arguments specified in the subroutine declaration
3109 @callArgList = $argListObj->argList;
3110 @subArgList = $subObj->argListObj->argList;
3111  
3112 # Check that there are the right number of arguments
3113 if ((scalar @callArgList) != (scalar @subArgList)) {
3114  
3115 return $self->scriptObj->setError(
3116 'wrong_number_of_arguments',
3117 $self->_objClass . '->implement',
3118 );
3119 }
3120  
3121 # Check that each argument is of the right type
3122 if (@callArgList) {
3123  
3124 for (my $count = 0; $count < scalar @callArgList; $count++) {
3125  
3126 my $value = $callArgList[$count]->evaluate();
3127  
3128 if (
3129 ref($subArgList[$count]) =~ m/Numeric/
3130 && ! Scalar::Util::looks_like_number($value)
3131 ) {
3132 return $self->scriptObj->setError(
3133 'type_mismatch_error',
3134 $self->_objClass . '->implement',
3135 );
3136 }
3137 }
3138 }
3139  
3140 # Make sure the subroutine's local variable and code block stores are empty
3141 $subObj->set_localScalarHash();
3142 $subObj->set_localArrayHash();
3143 $subObj->set_blockStackList();
3144 # Set the variable that will be assigned the subroutine's return value
3145 if ($returnVar) {
3146  
3147 $subObj->set_returnVar($returnVar);
3148  
3149 } else {
3150  
3151 # Empty a variable from any previous call
3152 $subObj->set_returnVar(undef);
3153 }
3154  
3155 # Evaluate each argument in the CALL statement's argument list, then create local variables
3156 # in the subroutine initialised with those values
3157 if (@callArgList) {
3158  
3159 for (my $count = 0; $count < scalar @callArgList; $count++) {
3160  
3161 my ($callArg, $value, $subArg);
3162  
3163 $callArg = $callArgList[$count];
3164 $value = $callArg->evaluate();
3165  
3166 $subArg = $subArgList[$count];
3167 $subArg->variable->set($value);
3168  
3169 # Initialise local variable $subArg->varName (e.g. name$) with $value
3170 $subObj->add_localScalar($subArg->varName, $subArg);
3171 }
3172 }
3173  
3174 # Execution will shortly at the first statement after the SUB declaration statement
3175 $declareStatement = $subObj->declareStatement;
3176  
3177 # The next statement to execute is the statement after that
3178 if (defined $declareStatement->nextStatement) {
3179  
3180 # LA::Script->nextStatement is currently set to this statement; continue execution
3181 # as if this were the SUB statement
3182 $self->scriptObj->set_nextStatement($declareStatement);
3183  
3184 } else {
3185  
3186 $self->scriptObj->set_nextStatement(undef);
3187 $self->scriptObj->set_nextLine($declareStatement->lineObj->procLineNum + 1);
3188 }
3189  
3190 # At the end of the subroutine, execution will continue at the first statement after this
3191 # one
3192 $subObj->set_callStatement($self);
3193  
3194 # Add this subroutine to the script's subroutine stack
3195 $self->scriptObj->pushSubStack($subObj);
3196  
3197 # Implementation complete
3198 return 1;
3199 }
3200 }
3201  
3202 { package Language::Axbasic::Statement::case;
3203  
3204 use strict;
3205 use warnings;
3206 # use diagnostics;
3207  
3208 use Glib qw(TRUE FALSE);
3209  
3210 @Language::Axbasic::Statement::case::ISA = qw(
3211 Language::Axbasic
3212 Language::Axbasic::Statement
3213 );
3214  
3215 # CASE constant [ , constant ...]
3216 # CASE ELSE
3217  
3218 ##################
3219 # Methods
3220  
3221 sub parse {
3222  
3223 # Called by LA::Line->parse directly after a call to LA::Statement->new
3224 #
3225 # Expected arguments
3226 # (none besides $self)
3227 #
3228 # Return values
3229 # 'undef' on improper arguments or if there is an error
3230 # 1 otherwise
3231  
3232 my ($self, $check) = @_;
3233  
3234 # Local variables
3235 my ($subObj, $selectStatement);
3236  
3237 # Check for improper arguments
3238 if (defined $check) {
3239  
3240 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3241 }
3242  
3243 # The 'case' keyword is not available in primitive numbering mode
3244 if ($self->scriptObj->executionMode ne 'no_line_num') {
3245  
3246 return $self->scriptObj->setError(
3247 'statement_not_available_with_line_numbers',
3248 $self->_objClass . '->parse',
3249 );
3250 }
3251  
3252 # Get the SELECT CASE statement which starts this code block
3253 $subObj = $self->scriptObj->returnCurrentSub();
3254 if (! $subObj->selectStackList) {
3255  
3256 return $self->scriptObj->setError(
3257 'CASE_statement_without_matching_SELECT_CASE',
3258 $self->_objClass . '->parse',
3259 );
3260  
3261 } else {
3262  
3263 # The matching SELECT CASE statement is the last one in the stack
3264 $selectStatement = $subObj->pop_selectStackList();
3265 }
3266  
3267 if ($self->tokenGroupObj->shiftMatchingToken('else')) {
3268  
3269 # CASE ELSE statement
3270  
3271 # If the SELECT CASE statement has already seen a CASE ELSE, it's an error
3272 if (defined $selectStatement->ivShow('parseDataHash', 'case_else_statement')) {
3273  
3274 return $self->scriptObj->setError(
3275 'multiple_CASE_ELSE_statements_in_SELECT_block',
3276 $self->_objClass . '->parse',
3277 );
3278  
3279 } else {
3280  
3281 # Inform the SELECT CASE statement where its CASE ELSE statement is
3282 $selectStatement->add_parseDataHash('case_else_statement', $self);
3283 }
3284  
3285 } else {
3286  
3287 # CASE constant [ , constant ...] statement
3288  
3289 # Read the constants, one by one, and store them
3290 do {
3291  
3292 my $expression = Language::Axbasic::Expression::Constant->new(
3293 $self->scriptObj,
3294 $self->tokenGroupObj,
3295 );
3296  
3297 if (! defined $expression) {
3298  
3299 return $self->scriptObj->setError(
3300 'missing_or_illegal_constant',
3301 $self->_objClass . '->parse',
3302 );
3303  
3304 } else {
3305  
3306 $self->ivPush('parseDataList', $expression->evaluate);
3307 }
3308  
3309 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
3310  
3311 # Add this statement to the SELECT CASE statement's list of CASE statements
3312 $selectStatement->push_parseDataList($self);
3313 }
3314  
3315 # Store the SELECT CASE statement so this statement's ->implement can use it
3316 $self->ivAdd('parseDataHash', 'select_statement', $selectStatement);
3317 # Re-insert the SELECT CASE statement back into its stack
3318 $subObj->push_selectStackList($selectStatement);
3319  
3320 # Parsing complete
3321 return 1;
3322 }
3323  
3324 sub implement {
3325  
3326 # Called by LA::Line->implement directly after a call to $self->parse
3327 #
3328 # Expected arguments
3329 # (none besides $self)
3330 #
3331 # Return values
3332 # 'undef' on improper arguments or if there is an error
3333 # 1 otherwise
3334  
3335 my ($self, $check) = @_;
3336  
3337 # Local variables
3338 my ($selectStatement, $endSelectStatement, $subObj, $topStatement);
3339  
3340 # Check for improper arguments
3341 if (defined $check) {
3342  
3343 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3344 }
3345  
3346 # Retrieve the SELECT CASE statement which starts this code block
3347 $selectStatement = $self->ivShow('parseDataHash', 'select_statement');
3348 # Get the matching END SELECT statement
3349 $endSelectStatement = $selectStatement->ivShow('parseDataHash', 'end_select_statement');
3350  
3351 # This SELECT CASE..CASE..END SELECT code block has now finished
3352 $subObj = $self->scriptObj->returnCurrentSub();
3353 $subObj->pop_selectStackList();
3354  
3355 # Execution continues at the next statement after END SELECT
3356 if (defined $endSelectStatement->nextStatement) {
3357  
3358 $self->scriptObj->set_nextStatement($endSelectStatement->nextStatement);
3359  
3360 } else {
3361  
3362 # The case statement was the last (or only) statement on the line: use the next line
3363 $self->scriptObj->set_nextLine($endSelectStatement->lineObj->procLineNum + 1);
3364 }
3365  
3366 # Remove this code block from the standard code block stack.
3367 if (! $subObj->blockStackList) {
3368  
3369 return $self->scriptObj->setError(
3370 'CASE_statement_without_matching_SELECT_CASE',
3371 $self->_objClass . '->implement',
3372 );
3373  
3374 } else {
3375  
3376 $topStatement = $subObj->pop_blockStackList();
3377  
3378 # The statement at the top of the stack must be a WHILE statement, not another kind of
3379 # code block
3380 if ($topStatement->keyword ne 'select') {
3381  
3382 return $self->scriptObj->setError(
3383 'CASE_statement_without_matching_SELECT_CASE',
3384 $self->_objClass . '->implement',
3385 );
3386 }
3387 }
3388  
3389 # Implementation complete
3390 return 1;
3391 }
3392 }
3393  
3394 { package Language::Axbasic::Statement::client;
3395  
3396 use strict;
3397 use warnings;
3398 # use diagnostics;
3399  
3400 use Glib qw(TRUE FALSE);
3401  
3402 @Language::Axbasic::Statement::client::ISA = qw(
3403 Language::Axbasic
3404 Language::Axbasic::Statement
3405 );
3406  
3407 # CLIENT expression
3408  
3409 ##################
3410 # Methods
3411  
3412 sub parse {
3413  
3414 # Called by LA::Line->parse directly after a call to LA::Statement->new
3415 #
3416 # Expected arguments
3417 # (none besides $self)
3418 #
3419 # Return values
3420 # 'undef' on improper arguments or if there is an error
3421 # 1 otherwise
3422  
3423 my ($self, $check) = @_;
3424  
3425 # Local variables
3426 my $expression;
3427  
3428 # Check for improper arguments
3429 if (defined $check) {
3430  
3431 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3432 }
3433  
3434 # Get the expression and store it for ->implement to use
3435 $expression = Language::Axbasic::Expression::Arithmetic->new(
3436 $self->scriptObj,
3437 $self->tokenGroupObj,
3438 );
3439  
3440 if (! defined $expression) {
3441  
3442 return $self->scriptObj->setError(
3443 'missing_or_illegal_expression',
3444 $self->_objClass . '->parse',
3445 );
3446  
3447 } else {
3448  
3449 $self->ivAdd('parseDataHash', 'expression', $expression);
3450 }
3451  
3452 # There should be nothing after the expression
3453 if (! $self->tokenGroupObj->testStatementEnd()) {
3454  
3455 return $self->scriptObj->setError(
3456 'unexpected_keywords,_operators_or_expressions',
3457 $self->_objClass . '->parse',
3458 );
3459 }
3460  
3461 # Parsing complete
3462 return 1;
3463 }
3464  
3465 sub implement {
3466  
3467 # Called by LA::Line->implement directly after a call to $self->parse
3468 #
3469 # Expected arguments
3470 # (none besides $self)
3471 #
3472 # Return values
3473 # 'undef' on improper arguments or if there is an error
3474 # 1 otherwise
3475  
3476 my ($self, $check) = @_;
3477  
3478 # Local variables
3479 my ($expression, $cmd);
3480  
3481 # Check for improper arguments
3482 if (defined $check) {
3483  
3484 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3485 }
3486  
3487 # Retrieve the expression to be played
3488 $expression = $self->ivShow('parseDataHash', 'expression');
3489 # Evaluate the expression to get a client command
3490 $cmd = $expression->evaluate();
3491  
3492 # Execute the client command
3493 $self->scriptObj->session->pseudoCmd($cmd, $self->scriptObj->pseudoCmdMode);
3494  
3495 # Implementation complete
3496 return 1;
3497 }
3498 }
3499  
3500 { package Language::Axbasic::Statement::cls;
3501  
3502 use strict;
3503 use warnings;
3504 # use diagnostics;
3505  
3506 use Glib qw(TRUE FALSE);
3507  
3508 @Language::Axbasic::Statement::cls::ISA = qw(
3509 Language::Axbasic
3510 Language::Axbasic::Statement
3511 );
3512  
3513 # CLS
3514  
3515 ##################
3516 # Methods
3517  
3518 sub parse {
3519  
3520 # Called by LA::Line->parse directly after a call to LA::Statement->new
3521 #
3522 # Expected arguments
3523 # (none besides $self)
3524 #
3525 # Return values
3526 # 'undef' on improper arguments or if there is an error
3527 # 1 otherwise
3528  
3529 my ($self, $check) = @_;
3530  
3531 # Local variables
3532 my ($expression);
3533  
3534 # Check for improper arguments
3535 if (defined $check) {
3536  
3537 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3538 }
3539  
3540 # EMPTYWIN statements always appear on their own
3541 if (! $self->tokenGroupObj->testStatementEnd()) {
3542  
3543 return $self->scriptObj->setError(
3544 'unexpected_keywords,_operators_or_expressions',
3545 $self->_objClass . '->parse',
3546 );
3547 }
3548  
3549 # Parsing complete
3550 return 1;
3551 }
3552  
3553 sub implement {
3554  
3555 # Called by LA::Line->implement directly after a call to $self->parse
3556 #
3557 # Expected arguments
3558 # (none besides $self)
3559 #
3560 # Return values
3561 # 'undef' on improper arguments or if there is an error
3562 # 1 otherwise
3563  
3564 my ($self, $check) = @_;
3565  
3566 # Local variables
3567  
3568 # Check for improper arguments
3569 if (defined $check) {
3570  
3571 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3572 }
3573  
3574 # If the Axbasic script is being run from within an Axmud task and the task window is open,
3575 # empty it. Otherwise, do nothing
3576 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
3577  
3578 # Clears a task window's default tab
3579 $self->scriptObj->parentTask->clearBuffer();
3580 }
3581  
3582 # Implementation complete
3583 return 1;
3584 }
3585 }
3586  
3587 { package Language::Axbasic::Statement::close;
3588  
3589 use strict;
3590 use warnings;
3591 # use diagnostics;
3592  
3593 use Glib qw(TRUE FALSE);
3594  
3595 @Language::Axbasic::Statement::close::ISA = qw(
3596 Language::Axbasic
3597 Language::Axbasic::Statement
3598 );
3599  
3600 # CLOSE #channel
3601  
3602 ##################
3603 # Methods
3604  
3605 sub parse {
3606  
3607 # Called by LA::Line->parse directly after a call to LA::Statement->new
3608 #
3609 # Expected arguments
3610 # (none besides $self)
3611 #
3612 # Return values
3613 # 'undef' on improper arguments or if there is an error
3614 # 1 otherwise
3615  
3616 my ($self, $check) = @_;
3617  
3618 # Local variables
3619 my ($channelToken, $channel, $nameFlag);
3620  
3621 # Check for improper arguments
3622 if (defined $check) {
3623  
3624 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3625 }
3626  
3627 # Get the channel token. For CLOSE statements, it must not include a colon at the end
3628 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
3629 if (! defined $channelToken || $channelToken->tokenText =~ m/\:$/) {
3630  
3631 return $self->scriptObj->setError(
3632 'syntax_error',
3633 $self->_objClass . '->parse',
3634 );
3635  
3636 } else {
3637  
3638 # Store the channel number
3639 $channelToken->tokenText =~ m/([0-9]+)/;
3640 $channel = $1;
3641  
3642 # True BASIC specifies that the channel must be in the range 1-999; same range used by
3643 # Axbasic
3644 if ($channel < 1 || $channel > 999) {
3645  
3646 return $self->scriptObj->setError(
3647 'file_channel_NUM_out_of_range',
3648 $self->_objClass . '->parse',
3649 'NUM', $channel,
3650 );
3651  
3652 } else {
3653  
3654 $self->ivAdd('parseDataHash', 'channel', $channel);
3655 }
3656 }
3657  
3658 # Check that nothing follows the file channel
3659 if (! $self->tokenGroupObj->testStatementEnd()) {
3660  
3661 return $self->scriptObj->setError(
3662 'unexpected_keywords,_operators_or_expressions',
3663 $self->_objClass . '->parse',
3664 );
3665 }
3666  
3667 # Parsing complete
3668 return 1;
3669 }
3670  
3671 sub implement {
3672  
3673 # Called by LA::Line->implement directly after a call to $self->parse
3674 #
3675 # Expected arguments
3676 # (none besides $self)
3677 #
3678 # Return values
3679 # 'undef' on improper arguments or if there is an error
3680 # 1 otherwise
3681  
3682 my ($self, $check) = @_;
3683  
3684 # Local variables
3685 my ($channel, $channelObj);
3686  
3687 # Check for improper arguments
3688 if (defined $check) {
3689  
3690 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3691 }
3692  
3693 # Retrieve the variables stored by ->parse
3694 $channel = $self->ivShow('parseDataHash', 'channel');
3695  
3696 # Check that the file channel exists
3697 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
3698  
3699 return $self->scriptObj->setError(
3700 'file_channel_NUM_not_open',
3701 $self->_objClass . '->implement',
3702 'NUM', $channel,
3703 );
3704  
3705 } else {
3706  
3707 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
3708 }
3709  
3710 # Update the LA::Script IVs
3711 $self->scriptObj->del_fileChannel($channelObj);
3712  
3713 # Close the filehandle
3714 if (! close ($channelObj->fileHandle)) {
3715  
3716 return $self->scriptObj->setError(
3717 'failed_to_close_file',
3718 $self->_objClass . '->implement',
3719 );
3720 }
3721  
3722 # Implementation complete
3723 return 1;
3724 }
3725 }
3726  
3727 { package Language::Axbasic::Statement::closewin;
3728  
3729 use strict;
3730 use warnings;
3731 # use diagnostics;
3732  
3733 use Glib qw(TRUE FALSE);
3734  
3735 @Language::Axbasic::Statement::closewin::ISA = qw(
3736 Language::Axbasic
3737 Language::Axbasic::Statement
3738 );
3739  
3740 # CLOSEWIN
3741  
3742 ##################
3743 # Methods
3744  
3745 sub parse {
3746  
3747 # Called by LA::Line->parse directly after a call to LA::Statement->new
3748 #
3749 # Expected arguments
3750 # (none besides $self)
3751 #
3752 # Return values
3753 # 'undef' on improper arguments or if there is an error
3754 # 1 otherwise
3755  
3756 my ($self, $check) = @_;
3757  
3758 # Local variables
3759 my ($expression);
3760  
3761 # Check for improper arguments
3762 if (defined $check) {
3763  
3764 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3765 }
3766  
3767 # CLOSEWIN statements always appear on their own
3768 if (! $self->tokenGroupObj->testStatementEnd()) {
3769  
3770 return $self->scriptObj->setError(
3771 'unexpected_keywords,_operators_or_expressions',
3772 $self->_objClass . '->parse',
3773 );
3774 }
3775  
3776 # Parsing complete
3777 return 1;
3778 }
3779  
3780 sub implement {
3781  
3782 # Called by LA::Line->implement directly after a call to $self->parse
3783 #
3784 # Expected arguments
3785 # (none besides $self)
3786 #
3787 # Return values
3788 # 'undef' on improper arguments or if there is an error
3789 # 1 otherwise
3790  
3791 my ($self, $check) = @_;
3792  
3793 # Local variables
3794  
3795 # Check for improper arguments
3796 if (defined $check) {
3797  
3798 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3799 }
3800  
3801 # If the Axbasic script is being run from within an Axmud task and the task window is open,
3802 # close it. Otherwise, do nothing
3803 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
3804  
3805 # Close the task window
3806 $self->scriptObj->parentTask->closeWin();
3807 }
3808  
3809 # Implementation complete
3810 return 1;
3811 }
3812 }
3813  
3814 { package Language::Axbasic::Statement::data;
3815  
3816 use strict;
3817 use warnings;
3818 # use diagnostics;
3819  
3820 use Glib qw(TRUE FALSE);
3821  
3822 @Language::Axbasic::Statement::data::ISA = qw(
3823 Language::Axbasic
3824 Language::Axbasic::Statement
3825 );
3826  
3827 # DATA constant [ , constant ... ]
3828  
3829 ##################
3830 # Methods
3831  
3832 sub parse {
3833  
3834 # Called by LA::Line->parse directly after a call to LA::Statement->new
3835 #
3836 # Expected arguments
3837 # (none besides $self)
3838 #
3839 # Return values
3840 # 'undef' on improper arguments or if there is an error
3841 # 1 otherwise
3842  
3843 my ($self, $check) = @_;
3844  
3845 # Local variables
3846 my $expression;
3847  
3848 # Check for improper arguments
3849 if (defined $check) {
3850  
3851 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3852 }
3853  
3854 # The rest of the statement is a list of things to add to the script's global data list
3855 # - the things can be retrieved later on by the 'read' statement
3856 do {
3857  
3858 $expression = Language::Axbasic::Expression::Constant->new(
3859 $self->scriptObj,
3860 $self->tokenGroupObj,
3861 );
3862  
3863 if (! defined $expression) {
3864  
3865 return $self->scriptObj->setError(
3866 'missing_or_illegal_constant',
3867 $self->_objClass . '->parse',
3868 );
3869  
3870 } else {
3871  
3872 # One copy of the constant goes in a permanent list...
3873 $self->scriptObj->push_globalDataList($expression);
3874 # ...and another copy goes into a list from which items are removed by each
3875 # successive 'read' statement
3876 $self->scriptObj->push_readDataList($expression);
3877 }
3878  
3879 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
3880  
3881 # Parsing complete
3882 return 1;
3883 }
3884  
3885 # sub implement {} # No ->implement method necessary
3886 }
3887  
3888 { package Language::Axbasic::Statement::debug;
3889  
3890 use strict;
3891 use warnings;
3892 # use diagnostics;
3893  
3894 use Glib qw(TRUE FALSE);
3895  
3896 @Language::Axbasic::Statement::debug::ISA = qw(
3897 Language::Axbasic
3898 Language::Axbasic::Statement
3899 );
3900  
3901 # DEBUG expression
3902  
3903 ##################
3904 # Methods
3905  
3906 sub parse {
3907  
3908 # Called by LA::Line->parse directly after a call to LA::Statement->new
3909 #
3910 # Expected arguments
3911 # (none besides $self)
3912  
3913 # Return values
3914 # 'undef' on improper arguments or if there is an error
3915 # 1 otherwise
3916  
3917 my ($self, $check) = @_;
3918  
3919 # Local variables
3920 my $expression;
3921  
3922 # Check for improper arguments
3923 if (defined $check) {
3924  
3925 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
3926 }
3927  
3928 # Get the expression and store it for ->implement to use
3929 $expression = Language::Axbasic::Expression::Arithmetic->new(
3930 $self->scriptObj,
3931 $self->tokenGroupObj,
3932 );
3933  
3934 if (! defined $expression) {
3935  
3936 return $self->scriptObj->setError(
3937 'missing_or_illegal_expression',
3938 $self->_objClass . '->parse',
3939 );
3940  
3941 } else {
3942  
3943 $self->ivAdd('parseDataHash', 'expression', $expression);
3944 }
3945  
3946 # There should be nothing after the expression
3947 if (! $self->tokenGroupObj->testStatementEnd()) {
3948  
3949 return $self->scriptObj->setError(
3950 'unexpected_keywords,_operators_or_expressions',
3951 $self->_objClass . '->parse',
3952 );
3953 }
3954  
3955 # Parsing complete
3956 return 1;
3957 }
3958  
3959 sub implement {
3960  
3961 # Called by LA::Line->implement directly after a call to $self->parse
3962 #
3963 # Expected arguments
3964 # (none besides $self)
3965 #
3966 # Return values
3967 # 'undef' on improper arguments or if there is an error
3968 # 1 otherwise
3969  
3970 my ($self, $check) = @_;
3971  
3972 # Local variables
3973 my ($expression, $string);
3974  
3975 # Check for improper arguments
3976 if (defined $check) {
3977  
3978 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
3979 }
3980  
3981 # Retrieve the expression to be written
3982 $expression = $self->ivShow('parseDataHash', 'expression');
3983 # Evaluate the expression to get a scalar value
3984 $string = $expression->evaluate();
3985  
3986 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
3987 # the error message appears on a new line
3988 if ($self->scriptObj->column != 0) {
3989  
3990 $self->scriptObj->session->writeText('', 'after');
3991 $self->scriptObj->set_column(0);
3992 }
3993  
3994 # Write the error message to the 'main' window
3995 $self->scriptObj->session->writeDebug($string);
3996  
3997 # Implementation complete
3998 return 1;
3999 }
4000 }
4001  
4002 { package Language::Axbasic::Statement::def;
4003  
4004 use strict;
4005 use warnings;
4006 # use diagnostics;
4007  
4008 use Glib qw(TRUE FALSE);
4009  
4010 @Language::Axbasic::Statement::def::ISA = qw(
4011 Language::Axbasic
4012 Language::Axbasic::Statement
4013 );
4014  
4015 # DEF function-name ( variable-name [ , variable-name ... ] ) = expression
4016  
4017 ##################
4018 # Methods
4019  
4020 sub parse {
4021  
4022 # Called by LA::Line->parse directly after a call to LA::Statement->new
4023 #
4024 # Expected arguments
4025 # (none besides $self)
4026 #
4027 # Return values
4028 # 'undef' on improper arguments or if there is an error
4029 # 1 otherwise
4030  
4031 my ($self, $check) = @_;
4032  
4033 # Local variables
4034 my ($funcExpression, $funcObj, $expression);
4035  
4036 # Check for improper arguments
4037 if (defined $check) {
4038  
4039 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4040 }
4041  
4042 # The function name, and its arguments, consist of all the tokens up until the equals
4043 # Call LA::Expression::Function->new with an extra argument so it knows not to complain
4044 # about an unknown function
4045 $funcExpression = Language::Axbasic::Expression::Function->new(
4046 $self->scriptObj,
4047 $self->tokenGroupObj,
4048 'defining_flag',
4049 );
4050  
4051 if (! defined $funcExpression) {
4052  
4053 return $self->scriptObj->setError(
4054 'bad_function_definition',
4055 $self->_objClass . '->parse',
4056 );
4057 }
4058  
4059 if (! $self->tokenGroupObj->shiftTokenIfCategory('assignment_operator')) {
4060  
4061 return $self->scriptObj->setError(
4062 'missing_assignment_operator',
4063 $self->_objClass . '->parse',
4064 );
4065 }
4066  
4067 # We don't actually want the LA::Expression, just the LA::Function object we've declared
4068 $funcObj = $funcExpression->funcObj;
4069  
4070 # Read the function definition
4071 $expression = Language::Axbasic::Expression::Arithmetic->new(
4072 $self->scriptObj,
4073 $self->tokenGroupObj,
4074 );
4075  
4076 if (! defined $expression) {
4077  
4078 return $self->scriptObj->setError(
4079 'bad_function_definition',
4080 $self->_objClass . '->parse',
4081 );
4082 }
4083  
4084 # Now actually define the function (tell it how many arguments, and of which type, it has)
4085 $funcObj->set_defFuncExp($expression);
4086 # Save the function object (it doesn't appear to be retrieved by any other part of the
4087 # Axbasic code)
4088 $self->ivAdd('parseDataHash', 'func_obj', $funcObj);
4089  
4090 # Parsing complete
4091 return 1;
4092 }
4093  
4094 # sub implement {} # No ->implement method - function definition happens at parse time
4095 }
4096  
4097 { package Language::Axbasic::Statement::delalias;
4098  
4099 use strict;
4100 use warnings;
4101 # use diagnostics;
4102  
4103 use Glib qw(TRUE FALSE);
4104  
4105 @Language::Axbasic::Statement::delalias::ISA = qw(
4106 Language::Axbasic
4107 Language::Axbasic::Statement
4108 );
4109  
4110 # DELALIAS expression
4111  
4112 ##################
4113 # Methods
4114  
4115 sub parse {
4116  
4117 # Called by LA::Line->parse directly after a call to LA::Statement->new
4118 # when the first token in the statement is the keyword 'delalias'
4119 #
4120 # Expected arguments
4121 # (none besides $self)
4122 #
4123 # Return values
4124 # 'undef' on improper arguments or if there is an error
4125 # 1 otherwise
4126  
4127 my ($self, $check) = @_;
4128  
4129 # Local variables
4130 my $nameExp;
4131  
4132 # Check for improper arguments
4133 if (defined $check) {
4134  
4135 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4136 }
4137  
4138 # Convert the name string into an expression
4139 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4140 $self->scriptObj,
4141 $self->tokenGroupObj,
4142 );
4143  
4144 if (! defined $nameExp) {
4145  
4146 return $self->scriptObj->setError(
4147 'missing_or_illegal_expression',
4148 $self->_objClass . '->parse',
4149 );
4150 }
4151  
4152 # Check that nothing follows the expression
4153 if (! $self->tokenGroupObj->testStatementEnd()) {
4154  
4155 return $self->scriptObj->setError(
4156 'unexpected_keywords,_operators_or_expressions',
4157 $self->_objClass . '->parse',
4158 );
4159 }
4160  
4161 # Store the expression, so $self->implement can retrieve it
4162 $self->ivAdd('parseDataHash', 'name', $nameExp);
4163  
4164 # Parsing complete
4165 return 1;
4166 }
4167  
4168 sub implement {
4169  
4170 # Called by LA::Line->implement directly after a call to $self->parse
4171 #
4172 # Expected arguments
4173 # (none besides $self)
4174 #
4175 # Return values
4176 # 'undef' on improper arguments or if there is an error
4177 # 1 otherwise
4178  
4179 my ($self, $check) = @_;
4180  
4181 # Local variables
4182 my (
4183 $nameExp, $name, $profile,
4184 @interfaceList, @newList,
4185 );
4186  
4187 # Check for improper arguments
4188 if (defined $check) {
4189  
4190 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4191 }
4192  
4193 # Retrieve the argument stored by $self->parse
4194 $nameExp = $self->ivShow('parseDataHash', 'name');
4195 # Evaluate the expression
4196 $name = $nameExp->evaluate();
4197  
4198 # Specify which profile to use
4199 if (defined $self->scriptObj->useProfile) {
4200 $profile = $self->scriptObj->useProfile;
4201 } else {
4202 $profile = $self->scriptObj->session->currentWorld->name;
4203 }
4204  
4205 # Send the command
4206 if (
4207 $self->scriptObj->session->pseudoCmd(
4208 'deletealias <' . $name . '> -d ' . $profile,
4209 $self->scriptObj->pseudoCmdMode,
4210 )
4211 ) {
4212 # Update the LA::Script's IVs
4213 @interfaceList = $self->scriptObj->indepInterfaceList;
4214 if (@interfaceList) {
4215  
4216 do {
4217 my ($tempName, $tempProfile, $tempCategory);
4218  
4219 $tempName = shift @interfaceList;
4220 $tempProfile = shift @interfaceList;
4221 $tempCategory = shift @interfaceList;
4222  
4223 if ($tempName ne $name || $tempProfile ne $profile) {
4224  
4225 # This isn't the interface just deleted - reinstate it in the list
4226 push (@newList, $tempName, $tempProfile, $tempCategory);
4227 }
4228  
4229 } until (! @interfaceList);
4230  
4231 # Replace the list, missing the alias we've removed
4232 $self->scriptObj->set_indepInterfaceList(@newList);
4233 }
4234  
4235 if ($self->scriptObj->indepInterfaceName eq $name) {
4236  
4237 $self->scriptObj->set_indepInterfaceName(undef);
4238 }
4239  
4240 } else {
4241  
4242 # Store the fact that creation of the alias failed
4243 $self->scriptObj->set_indepInterfaceName(undef);
4244 }
4245  
4246 # Implementation complete
4247 return 1;
4248 }
4249 }
4250  
4251 { package Language::Axbasic::Statement::delgauge;
4252  
4253 use strict;
4254 use warnings;
4255 # use diagnostics;
4256  
4257 use Glib qw(TRUE FALSE);
4258  
4259 @Language::Axbasic::Statement::delgauge::ISA = qw(
4260 Language::Axbasic
4261 Language::Axbasic::Statement
4262 );
4263  
4264 # DELGAUGE expression
4265 # WINDELGAUGE expression
4266  
4267 ##################
4268 # Methods
4269  
4270 sub parse {
4271  
4272 # Called by LA::Line->parse directly after a call to LA::Statement->new
4273 #
4274 # Expected arguments
4275 # (none besides $self)
4276 #
4277 # Return values
4278 # 'undef' on improper arguments or if there is an error
4279 # 1 otherwise
4280  
4281 my ($self, $check) = @_;
4282  
4283 # Local variables
4284 my $numberExp;
4285  
4286 # Check for improper arguments
4287 if (defined $check) {
4288  
4289 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4290 }
4291  
4292 # Convert the number into an expression
4293 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
4294 $self->scriptObj,
4295 $self->tokenGroupObj,
4296 );
4297  
4298 if (! defined $numberExp) {
4299  
4300 return $self->scriptObj->setError(
4301 'missing_or_illegal_expression',
4302 $self->_objClass . '->parse',
4303 );
4304 }
4305  
4306 # Check that nothing follows the expression
4307 if (! $self->tokenGroupObj->testStatementEnd()) {
4308  
4309 return $self->scriptObj->setError(
4310 'unexpected_keywords,_operators_or_expressions',
4311 $self->_objClass . '->parse',
4312 );
4313 }
4314  
4315 # Store the expression, so $self->implement can retrieve it
4316 $self->ivAdd('parseDataHash', 'number', $numberExp);
4317  
4318 # Parsing complete
4319 return 1;
4320 }
4321  
4322 sub implement {
4323  
4324 # Called by LA::Line->implement directly after a call to $self->parse
4325 #
4326 # Expected arguments
4327 # (none besides $self)
4328 #
4329 # Return values
4330 # 'undef' on improper arguments or if there is an error
4331 # 1 otherwise
4332  
4333 my ($self, $check) = @_;
4334  
4335 # Local variables
4336 my ($numberExp, $number);
4337  
4338 # Check for improper arguments
4339 if (defined $check) {
4340  
4341 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4342 }
4343  
4344 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
4345 if (! $self->scriptObj->parentTask) {
4346  
4347 # Implementation complete. Execution resumes from the next statement
4348 return 1;
4349 }
4350  
4351 # Retrieve the argument stored by $self->parse
4352 $numberExp = $self->ivShow('parseDataHash', 'number');
4353 # Evaluate the expression
4354 $number = $numberExp->evaluate();
4355  
4356 # $number must be an integer, >= 0 (but it doesn't need to be a gauge number which has
4357 # actually been created with an ADDGAUGE or ADDCONGAUGE statement)
4358 if ($number =~ m/\D/ || $number < 0) {
4359  
4360 return $self->scriptObj->setError(
4361 'invalid_gauge_number',
4362 $self->_objClass . '->implement',
4363 );
4364 }
4365  
4366 # Tell the Script task to delete the gauge
4367 if ($self->keyword eq 'delgauge') {
4368 $self->scriptObj->parentTask->deleteMainWinGauge($number);
4369 } elsif ($self->keyword eq 'windelgauge') {
4370 $self->scriptObj->parentTask->deleteTaskWinGauge($number);
4371 }
4372  
4373 # Implementation complete
4374 return 1;
4375 }
4376 }
4377  
4378 { package Language::Axbasic::Statement::delhook;
4379  
4380 use strict;
4381 use warnings;
4382 # use diagnostics;
4383  
4384 use Glib qw(TRUE FALSE);
4385  
4386 @Language::Axbasic::Statement::delhook::ISA = qw(
4387 Language::Axbasic
4388 Language::Axbasic::Statement
4389 );
4390  
4391 # DELHOOK expression
4392  
4393 ##################
4394 # Methods
4395  
4396 sub parse {
4397  
4398 # Called by LA::Line->parse directly after a call to LA::Statement->new
4399 #
4400 # Expected arguments
4401 # (none besides $self)
4402 #
4403 # Return values
4404 # 'undef' on improper arguments or if there is an error
4405 # 1 otherwise
4406  
4407 my ($self, $check) = @_;
4408  
4409 # Local variables
4410 my ($nameExp);
4411  
4412 # Check for improper arguments
4413 if (defined $check) {
4414  
4415 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4416 }
4417  
4418 # Convert the name string into an expression
4419 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4420 $self->scriptObj,
4421 $self->tokenGroupObj,
4422 );
4423  
4424 if (! defined $nameExp) {
4425  
4426 return $self->scriptObj->setError(
4427 'missing_or_illegal_expression',
4428 $self->_objClass . '->parse',
4429 );
4430 }
4431  
4432 # Check that nothing follows the expression
4433 if (! $self->tokenGroupObj->testStatementEnd()) {
4434  
4435 return $self->scriptObj->setError(
4436 'unexpected_keywords,_operators_or_expressions',
4437 $self->_objClass . '->parse',
4438 );
4439 }
4440  
4441 # Store the expression, so $self->implement can retrieve it
4442 $self->ivAdd('parseDataHash', 'name', $nameExp);
4443  
4444 # Parsing complete
4445 return 1;
4446 }
4447  
4448 sub implement {
4449  
4450 # Called by LA::Line->implement directly after a call to $self->parse
4451 #
4452 # Expected arguments
4453 # (none besides $self)
4454 #
4455 # Return values
4456 # 'undef' on improper arguments or if there is an error
4457 # 1 otherwise
4458  
4459 my ($self, $check) = @_;
4460  
4461 # Local variables
4462 my (
4463 $nameExp, $name, $profile,
4464 @interfaceList, @newList,
4465 );
4466  
4467 # Check for improper arguments
4468 if (defined $check) {
4469  
4470 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4471 }
4472  
4473 # Retrieve the argument stored by $self->parse
4474 $nameExp = $self->ivShow('parseDataHash', 'name');
4475 # Evaluate the expression
4476 $name = $nameExp->evaluate();
4477  
4478 # Specify which profile to use
4479 if (defined $self->scriptObj->useProfile) {
4480 $profile = $self->scriptObj->useProfile;
4481 } else {
4482 $profile = $self->scriptObj->session->currentWorld->name;
4483 }
4484  
4485 # Send the command
4486 if (
4487 $self->scriptObj->session->pseudoCmd(
4488 'deletehook <' . $name . '> -d ' . $profile,
4489 $self->scriptObj->pseudoCmdMode,
4490 )
4491 ) {
4492 # Update the LA::Script's IVs
4493 @interfaceList = $self->scriptObj->indepInterfaceList;
4494 if (@interfaceList) {
4495  
4496 do {
4497  
4498 my ($tempName, $tempProfile, $tempCategory);
4499  
4500 $tempName = shift @interfaceList;
4501 $tempProfile = shift @interfaceList;
4502 $tempCategory = shift @interfaceList;
4503  
4504 if ($tempName ne $name || $tempProfile ne $profile) {
4505  
4506 # This isn't the interface just deleted - reinstate it in the list
4507 push (@newList, $tempName, $tempProfile, $tempCategory);
4508 }
4509  
4510 } until (! @interfaceList);
4511  
4512 # Replace the list, missing the hook we've removed
4513 $self->scriptObj->set_indepInterfaceList(@newList);
4514 }
4515  
4516 if ($self->scriptObj->indepInterfaceName eq $name) {
4517  
4518 $self->scriptObj->set_indepInterfaceName(undef);
4519 }
4520  
4521 } else {
4522  
4523 # Store the fact that creation of the hook failed
4524 $self->scriptObj->set_indepInterfaceName(undef);
4525 }
4526  
4527 # Implementation complete
4528 return 1;
4529 }
4530 }
4531  
4532 { package Language::Axbasic::Statement::deliface;
4533  
4534 use strict;
4535 use warnings;
4536 # use diagnostics;
4537  
4538 use Glib qw(TRUE FALSE);
4539  
4540 @Language::Axbasic::Statement::deliface::ISA = qw(
4541 Language::Axbasic
4542 Language::Axbasic::Statement
4543 );
4544  
4545 # DELIFACE expression
4546  
4547 ##################
4548 # Methods
4549  
4550 sub parse {
4551  
4552 # Called by LA::Line->parse directly after a call to LA::Statement->new
4553 #
4554 # Expected arguments
4555 # (none besides $self)
4556 #
4557 # Return values
4558 # 'undef' on improper arguments or if there is an error
4559 # 1 otherwise
4560  
4561 my ($self, $check) = @_;
4562  
4563 # Local variables
4564 my $nameExp;
4565  
4566 # Check for improper arguments
4567 if (defined $check) {
4568  
4569 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4570 }
4571  
4572 # Convert the name string into an expression
4573 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4574 $self->scriptObj,
4575 $self->tokenGroupObj,
4576 );
4577  
4578 if (! defined $nameExp) {
4579  
4580 return $self->scriptObj->setError(
4581 'missing_or_illegal_expression',
4582 $self->_objClass . '->parse',
4583 );
4584 }
4585  
4586 # Check that nothing follows the expression
4587 if (! $self->tokenGroupObj->testStatementEnd()) {
4588  
4589 return $self->scriptObj->setError(
4590 'unexpected_keywords,_operators_or_expressions',
4591 $self->_objClass . '->parse',
4592 );
4593 }
4594  
4595 # Store the expression, so $self->implement can retrieve it
4596 $self->ivAdd('parseDataHash', 'name', $nameExp);
4597  
4598 # Parsing complete
4599 return 1;
4600 }
4601  
4602 sub implement {
4603  
4604 # Called by LA::Line->implement directly after a call to $self->parse
4605 #
4606 # Expected arguments
4607 # (none besides $self)
4608 #
4609 # Return values
4610 # 'undef' on improper arguments or if there is an error
4611 # 1 otherwise
4612  
4613 my ($self, $check) = @_;
4614  
4615 # Local variables
4616 my (
4617 $nameExp, $name, $obj,
4618 @interfaceList, @newList,
4619 );
4620  
4621 # Check for improper arguments
4622 if (defined $check) {
4623  
4624 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4625 }
4626  
4627 # Retrieve the argument stored by $self->parse
4628 $nameExp = $self->ivShow('parseDataHash', 'name');
4629 # Evaluate the expression
4630 $name = $nameExp->evaluate();
4631  
4632 # Check that the interface still exists and, if not, don't try to delete it
4633 if ($self->scriptObj->session->ivExists('interfaceHash', $name)) {
4634  
4635 $obj = $self->scriptObj->session->ivShow('interfaceHash', $name);
4636  
4637 # Delete the interface
4638 $self->scriptObj->session->pseudoCmd(
4639 'delete' . $obj->category . ' -i <' . $name . '>',
4640 $self->scriptObj->pseudoCmdMode,
4641 );
4642  
4643 # Update the LA::Script's list of interfaces
4644 @interfaceList = $self->scriptObj->depInterfaceList;
4645 foreach my $otherObj (@interfaceList) {
4646  
4647 if ($otherObj ne $obj) {
4648  
4649 push (@newList, $otherObj);
4650 }
4651 }
4652  
4653 $self->scriptObj->set_depInterfaceList(@newList);
4654  
4655 # Update the accompanying IV, if necessary
4656 if (
4657 defined $self->scriptObj->depInterfaceName
4658 && $self->scriptObj->depInterfaceName eq $name
4659 ) {
4660 $self->scriptObj->set_depInterfaceName(undef);
4661 }
4662  
4663 # Now, if we've just deleted an interface created by (for example) a WAITTRIG statement
4664 # - and if the parent task is waiting for that trigger to fire - it will now be
4665 # waiting forever; so we need to tell the task to stop waiting
4666 if (
4667 $self->scriptObj->parentTask
4668 && defined $self->scriptObj->parentTask->waitForInterface
4669 && $self->scriptObj->parentTask->waitForInterface eq $name
4670 ) {
4671 # Tell the task that the interface has expired
4672 $self->scriptObj->parentTask->resetInterface($obj);
4673 }
4674 }
4675  
4676 # Implementation complete
4677 return 1;
4678 }
4679 }
4680  
4681 { package Language::Axbasic::Statement::delmacro;
4682  
4683 use strict;
4684 use warnings;
4685 # use diagnostics;
4686  
4687 use Glib qw(TRUE FALSE);
4688  
4689 @Language::Axbasic::Statement::delmacro::ISA = qw(
4690 Language::Axbasic
4691 Language::Axbasic::Statement
4692 );
4693  
4694 # DELMACRO expression
4695  
4696 ##################
4697 # Methods
4698  
4699 sub parse {
4700  
4701 # Called by LA::Line->parse directly after a call to LA::Statement->new
4702 #
4703 # Expected arguments
4704 # (none besides $self)
4705 #
4706 # Return values
4707 # 'undef' on improper arguments or if there is an error
4708 # 1 otherwise
4709  
4710 my ($self, $check) = @_;
4711  
4712 # Local variables
4713 my $nameExp;
4714  
4715 # Check for improper arguments
4716 if (defined $check) {
4717  
4718 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4719 }
4720  
4721 # Convert the name string into an expression
4722 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
4723 $self->scriptObj,
4724 $self->tokenGroupObj,
4725 );
4726  
4727 if (! defined $nameExp) {
4728  
4729 return $self->scriptObj->setError(
4730 'missing_or_illegal_expression',
4731 $self->_objClass . '->parse',
4732 );
4733 }
4734  
4735 # Check that nothing follows the expression
4736 if (! $self->tokenGroupObj->testStatementEnd()) {
4737  
4738 return $self->scriptObj->setError(
4739 'unexpected_keywords,_operators_or_expressions',
4740 $self->_objClass . '->parse',
4741 );
4742 }
4743  
4744 # Store the expression, so $self->implement can retrieve it
4745 $self->ivAdd('parseDataHash', 'name', $nameExp);
4746  
4747 # Parsing complete
4748 return 1;
4749 }
4750  
4751 sub implement {
4752  
4753 # Called by LA::Line->implement directly after a call to $self->parse when the
4754 # first token in the statement is the keyword 'delmacro'
4755 #
4756 # Expected arguments
4757 # (none besides $self)
4758 #
4759 # Return values
4760 # 'undef' on improper arguments or if there is an error
4761 # 1 otherwise
4762  
4763 my ($self, $check) = @_;
4764  
4765 # Local variables
4766 my (
4767 $nameExp, $name, $profile,
4768 @interfaceList, @newList,
4769 );
4770  
4771 # Check for improper arguments
4772 if (defined $check) {
4773  
4774 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4775 }
4776  
4777 # Retrieve the argument stored by $self->parse
4778 $nameExp = $self->ivShow('parseDataHash', 'name');
4779 # Evaluate the expression
4780 $name = $nameExp->evaluate();
4781  
4782 # Specify which profile to use
4783 if (defined $self->scriptObj->useProfile) {
4784 $profile = $self->scriptObj->useProfile;
4785 } else {
4786 $profile = $self->scriptObj->session->currentWorld->name;
4787 }
4788  
4789 # Send the command
4790 if (
4791 $self->scriptObj->session->pseudoCmd(
4792 'deletemacro <' . $name . '> -d ' . $profile,
4793 $self->scriptObj->pseudoCmdMode,
4794 )
4795 ) {
4796 # Update the LA::Script's IVs
4797 @interfaceList = $self->scriptObj->indepInterfaceList;
4798 if (@interfaceList) {
4799  
4800 do {
4801 my ($tempName, $tempProfile, $tempCategory);
4802  
4803 $tempName = shift @interfaceList;
4804 $tempProfile = shift @interfaceList;
4805 $tempCategory = shift @interfaceList;
4806  
4807 if ($tempName ne $name || $tempProfile ne $profile) {
4808  
4809 # This isn't the interface just deleted - reinstate it in the list
4810 push (@newList, $tempName, $tempProfile, $tempCategory);
4811 }
4812  
4813 } until (! @interfaceList);
4814  
4815 # Replace the list, missing the macro we've removed
4816 $self->scriptObj->set_indepInterfaceList(@newList);
4817 }
4818  
4819 if ($self->scriptObj->indepInterfaceName eq $name) {
4820  
4821 $self->scriptObj->set_indepInterfaceName(undef);
4822 }
4823  
4824 } else {
4825  
4826 # Store the fact that creation of the macro failed
4827 $self->scriptObj->set_indepInterfaceName(undef);
4828 }
4829  
4830 # Implementation complete
4831 return 1;
4832 }
4833 }
4834  
4835 { package Language::Axbasic::Statement::delstatus;
4836  
4837 use strict;
4838 use warnings;
4839 # use diagnostics;
4840  
4841 use Glib qw(TRUE FALSE);
4842  
4843 @Language::Axbasic::Statement::delstatus::ISA = qw(
4844 Language::Axbasic
4845 Language::Axbasic::Statement
4846 );
4847  
4848 # DELSTATUS expression
4849 # WINDELSTATUS expression
4850  
4851 ##################
4852 # Methods
4853  
4854 sub parse {
4855  
4856 # Called by LA::Line->parse directly after a call to LA::Statement->new
4857 #
4858 # Expected arguments
4859 # (none besides $self)
4860 #
4861 # Return values
4862 # 'undef' on improper arguments or if there is an error
4863 # 1 otherwise
4864  
4865 my ($self, $check) = @_;
4866  
4867 # Local variables
4868 my $numberExp;
4869  
4870 # Check for improper arguments
4871 if (defined $check) {
4872  
4873 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
4874 }
4875  
4876 # Convert the number into an expression
4877 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
4878 $self->scriptObj,
4879 $self->tokenGroupObj,
4880 );
4881  
4882 if (! defined $numberExp) {
4883  
4884 return $self->scriptObj->setError(
4885 'missing_or_illegal_expression',
4886 $self->_objClass . '->parse',
4887 );
4888 }
4889  
4890 # Check that nothing follows the expression
4891 if (! $self->tokenGroupObj->testStatementEnd()) {
4892  
4893 return $self->scriptObj->setError(
4894 'unexpected_keywords,_operators_or_expressions',
4895 $self->_objClass . '->parse',
4896 );
4897 }
4898  
4899 # Store the expression, so $self->implement can retrieve it
4900 $self->ivAdd('parseDataHash', 'number', $numberExp);
4901  
4902 # Parsing complete
4903 return 1;
4904 }
4905  
4906 sub implement {
4907  
4908 # Called by LA::Line->implement directly after a call to $self->parse
4909 #
4910 # Expected arguments
4911 # (none besides $self)
4912 #
4913 # Return values
4914 # 'undef' on improper arguments or if there is an error
4915 # 1 otherwise
4916  
4917 my ($self, $check) = @_;
4918  
4919 # Local variables
4920 my ($numberExp, $number);
4921  
4922 # Check for improper arguments
4923 if (defined $check) {
4924  
4925 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
4926 }
4927  
4928 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
4929 if (! $self->scriptObj->parentTask) {
4930  
4931 # Implementation complete. Execution resumes from the next statement
4932 return 1;
4933 }
4934  
4935 # Retrieve the argument stored by $self->parse
4936 $numberExp = $self->ivShow('parseDataHash', 'number');
4937 # Evaluate the expression
4938 $number = $numberExp->evaluate();
4939  
4940 # $number must be an integer, >= 0 (but it doesn't need to be a status bar number which has
4941 # actually been created with an ADDSTATUS or ADDCONSTATUS statement)
4942 if ($number =~ m/\D/ || $number < 0) {
4943  
4944 return $self->scriptObj->setError(
4945 'invalid_status_bar_number',
4946 $self->_objClass . '->implement',
4947 );
4948 }
4949  
4950 # Tell the Script task to delete the status bar
4951 if ($self->keyword eq 'delstatus') {
4952 $self->scriptObj->parentTask->deleteMainWinStatusBar($number);
4953 } elsif ($self->keyword eq 'windelstatus') {
4954 $self->scriptObj->parentTask->deleteTaskWinStatusBar($number);
4955 }
4956  
4957 # Implementation complete
4958 return 1;
4959 }
4960 }
4961  
4962 { package Language::Axbasic::Statement::deltimer;
4963  
4964 use strict;
4965 use warnings;
4966 # use diagnostics;
4967  
4968 use Glib qw(TRUE FALSE);
4969  
4970 @Language::Axbasic::Statement::deltimer::ISA = qw(
4971 Language::Axbasic
4972 Language::Axbasic::Statement
4973 );
4974  
4975 # DELTIMER expression
4976  
4977 ##################
4978 # Methods
4979  
4980 sub parse {
4981  
4982 # Called by LA::Line->parse directly after a call to LA::Statement->new
4983 #
4984 # Expected arguments
4985 # (none besides $self)
4986 #
4987 # Return values
4988 # 'undef' on improper arguments or if there is an error
4989 # 1 otherwise
4990  
4991 my ($self, $check) = @_;
4992  
4993 # Local variables
4994 my ($nameExp);
4995  
4996 # Check for improper arguments
4997 if (defined $check) {
4998  
4999 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5000 }
5001  
5002 # Convert the name string into an expression
5003 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
5004 $self->scriptObj,
5005 $self->tokenGroupObj,
5006 );
5007  
5008 if (! defined $nameExp) {
5009  
5010 return $self->scriptObj->setError(
5011 'missing_or_illegal_expression',
5012 $self->_objClass . '->parse',
5013 );
5014 }
5015  
5016 # Check that nothing follows the expression
5017 if (! $self->tokenGroupObj->testStatementEnd()) {
5018  
5019 return $self->scriptObj->setError(
5020 'unexpected_keywords,_operators_or_expressions',
5021 $self->_objClass . '->parse',
5022 );
5023 }
5024  
5025 # Store the expression, so $self->implement can retrieve it
5026 $self->ivAdd('parseDataHash', 'name', $nameExp);
5027  
5028 # Parsing complete
5029 return 1;
5030 }
5031  
5032 sub implement {
5033  
5034 # Called by LA::Line->implement directly after a call to $self->parse
5035 #
5036 # Expected arguments
5037 # (none besides $self)
5038 #
5039 # Return values
5040 # 'undef' on improper arguments or if there is an error
5041 # 1 otherwise
5042  
5043 my ($self, $check) = @_;
5044  
5045 # Local variables
5046 my (
5047 $nameExp, $name, $profile,
5048 @interfaceList, @newList,
5049 );
5050  
5051 # Check for improper arguments
5052 if (defined $check) {
5053  
5054 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5055 }
5056  
5057 # Retrieve the argument stored by $self->parse
5058 $nameExp = $self->ivShow('parseDataHash', 'name');
5059 # Evaluate the expression
5060 $name = $nameExp->evaluate();
5061  
5062 # Specify which profile to use
5063 if (defined $self->scriptObj->useProfile) {
5064 $profile = $self->scriptObj->useProfile;
5065 } else {
5066 $profile = $self->scriptObj->session->currentWorld->name;
5067 }
5068  
5069 # Send the command
5070 if (
5071 $self->scriptObj->session->pseudoCmd(
5072 'deletetimer <' . $name . '> -d ' . $profile,
5073 $self->scriptObj->pseudoCmdMode,
5074 )
5075 ) {
5076 # Update the LA::Script's IVs
5077 @interfaceList = $self->scriptObj->indepInterfaceList;
5078 if (@interfaceList) {
5079  
5080 do {
5081 my ($tempName, $tempProfile, $tempCategory);
5082  
5083 $tempName = shift @interfaceList;
5084 $tempProfile = shift @interfaceList;
5085 $tempCategory = shift @interfaceList;
5086  
5087 if ($tempName ne $name || $tempProfile ne $profile) {
5088  
5089 # This isn't the interface just deleted - reinstate it in the list
5090 push (@newList, $tempName, $tempProfile, $tempCategory);
5091 }
5092  
5093 } until (! @interfaceList);
5094  
5095 # Replace the list, missing the timer we've removed
5096 $self->scriptObj->set_indepInterfaceList(@newList);
5097 }
5098  
5099 if ($self->scriptObj->indepInterfaceName eq $name) {
5100  
5101 $self->scriptObj->set_indepInterfaceName(undef);
5102 }
5103  
5104 } else {
5105  
5106 # Store the fact that creation of the timer failed
5107 $self->scriptObj->set_indepInterfaceName(undef);
5108 }
5109  
5110 # Implementation complete
5111 return 1;
5112 }
5113 }
5114  
5115 { package Language::Axbasic::Statement::deltrig;
5116  
5117 use strict;
5118 use warnings;
5119 # use diagnostics;
5120  
5121 use Glib qw(TRUE FALSE);
5122  
5123 @Language::Axbasic::Statement::deltrig::ISA = qw(
5124 Language::Axbasic
5125 Language::Axbasic::Statement
5126 );
5127  
5128 # DELTRIG expression
5129  
5130 ##################
5131 # Methods
5132  
5133 sub parse {
5134  
5135 # Called by LA::Line->parse directly after a call to LA::Statement->new
5136 #
5137 # Expected arguments
5138 # (none besides $self)
5139 #
5140 # Return values
5141 # 'undef' on improper arguments or if there is an error
5142 # 1 otherwise
5143  
5144 my ($self, $check) = @_;
5145  
5146 # Local variables
5147 my $nameExp;
5148  
5149 # Check for improper arguments
5150 if (defined $check) {
5151  
5152 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5153 }
5154  
5155 # Convert the name string into an expression
5156 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
5157 $self->scriptObj,
5158 $self->tokenGroupObj,
5159 );
5160  
5161 if (! defined $nameExp) {
5162  
5163 return $self->scriptObj->setError(
5164 'missing_or_illegal_expression',
5165 $self->_objClass . '->parse',
5166 );
5167 }
5168  
5169 # Check that nothing follows the expression
5170 if (! $self->tokenGroupObj->testStatementEnd()) {
5171  
5172 return $self->scriptObj->setError(
5173 'unexpected_keywords,_operators_or_expressions',
5174 $self->_objClass . '->parse',
5175 );
5176 }
5177  
5178 # Store the expression, so $self->implement can retrieve it
5179 $self->ivAdd('parseDataHash', 'name', $nameExp);
5180  
5181 # Parsing complete
5182 return 1;
5183 }
5184  
5185 sub implement {
5186  
5187 # Called by LA::Line->implement directly after a call to $self->parse
5188 #
5189 # Expected arguments
5190 # (none besides $self)
5191 #
5192 # Return values
5193 # 'undef' on improper arguments or if there is an error
5194 # 1 otherwise
5195  
5196 my ($self, $check) = @_;
5197  
5198 # Local variables
5199 my (
5200 $nameExp, $name, $profile,
5201 @interfaceList, @newList,
5202 );
5203  
5204 # Check for improper arguments
5205 if (defined $check) {
5206  
5207 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5208 }
5209  
5210 # Retrieve the argument stored by $self->parse
5211 $nameExp = $self->ivShow('parseDataHash', 'name');
5212 # Evaluate the expression
5213 $name = $nameExp->evaluate();
5214  
5215 # Specify which profile to use
5216 if (defined $self->scriptObj->useProfile) {
5217 $profile = $self->scriptObj->useProfile;
5218 } else {
5219 $profile = $self->scriptObj->session->currentWorld->name;
5220 }
5221  
5222 # Send the command
5223 if (
5224 $self->scriptObj->session->pseudoCmd(
5225 'deletetrigger <' . $name . '> -d ' . $profile,
5226 $self->scriptObj->pseudoCmdMode,
5227 )
5228 ) {
5229 # Update the LA::Script's IVs
5230 @interfaceList = $self->scriptObj->indepInterfaceList;
5231 if (@interfaceList) {
5232  
5233 do {
5234 my ($tempName, $tempProfile, $tempCategory);
5235  
5236 $tempName = shift @interfaceList;
5237 $tempProfile = shift @interfaceList;
5238 $tempCategory = shift @interfaceList;
5239  
5240 if ($tempName ne $name || $tempProfile ne $profile) {
5241  
5242 # This isn't the interface just deleted - reinstate it in the list
5243 push (@newList, $tempName, $tempProfile, $tempCategory);
5244 }
5245  
5246 } until (! @interfaceList);
5247  
5248 # Replace the list, missing the trigger we've removed
5249 $self->scriptObj->set_indepInterfaceList(@newList);
5250 }
5251  
5252 if ($self->scriptObj->indepInterfaceName eq $name) {
5253  
5254 $self->scriptObj->set_indepInterfaceName(undef);
5255 }
5256  
5257 } else {
5258  
5259 # Store the fact that creation of the trigger failed
5260 $self->scriptObj->set_indepInterfaceName(undef);
5261 }
5262  
5263 # Implementation complete
5264 return 1;
5265 }
5266 }
5267  
5268 { package Language::Axbasic::Statement::dim;
5269  
5270 use strict;
5271 use warnings;
5272 # use diagnostics;
5273  
5274 use Glib qw(TRUE FALSE);
5275  
5276 @Language::Axbasic::Statement::dim::ISA = qw(
5277 Language::Axbasic
5278 Language::Axbasic::Statement
5279 );
5280  
5281 # DIM variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
5282 # DIM GLOBAL variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
5283 # DIM LOCAL variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
5284  
5285 ##################
5286 # Methods
5287  
5288 sub parse {
5289  
5290 # Called by LA::Line->parse directly after a call to LA::Statement->new
5291 #
5292 # Expected arguments
5293 # (none besides $self)
5294 #
5295 # Return values
5296 # 'undef' on improper arguments or if there is an error
5297 # 1 otherwise
5298  
5299 my ($self, $check) = @_;
5300  
5301 # Local variables
5302 my ($token, $specialFlag);
5303  
5304 # Check for improper arguments
5305 if (defined $check) {
5306  
5307 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5308 }
5309  
5310 # DIM GLOBAL statement
5311 $token = $self->tokenGroupObj->shiftMatchingToken('global');
5312 if (defined $token) {
5313  
5314 # Temporarily set the IV that allows undeclared global arrays to be created
5315 $self->scriptObj->set_declareMode('global_array');
5316  
5317 # Check for DIM GLOBAL LOCAL
5318 $token = $self->tokenGroupObj->shiftMatchingToken('local');
5319 if (defined $token) {
5320  
5321 return $self->scriptObj->setError(
5322 'unexpected_keywords,_operators_or_expressions',
5323 $self->_objClass . '->parse',
5324 );
5325 }
5326 }
5327  
5328 # DIM LOCAL statement
5329 $token = $self->tokenGroupObj->shiftMatchingToken('local');
5330 if (defined $token) {
5331  
5332 # Temporarily set the IV that allows undeclared local arrays to be created
5333 $self->scriptObj->set_declareMode('local_array');
5334  
5335 # Check for DIM LOCAL GLOBAL
5336 $token = $self->tokenGroupObj->shiftMatchingToken('global');
5337 if (defined $token) {
5338  
5339 return $self->scriptObj->setError(
5340 'unexpected_keywords,_operators_or_expressions',
5341 $self->_objClass . '->parse',
5342 );
5343 }
5344 }
5345  
5346 # Check there is at least one variable name (e.g. that we don't have a solo 'DIM' or
5347 # 'DIM GLOBAL' statement)
5348 if (! defined $self->tokenGroupObj->lookAhead()) {
5349  
5350 return $self->scriptObj->setError(
5351 'syntax_error',
5352 $self->_objClass . '->parse',
5353 );
5354 }
5355  
5356 if ($self->scriptObj->declareMode eq 'default') {
5357  
5358 # Temporarily set the IV that allows undeclared global arrays to be created
5359 $self->scriptObj->set_declareMode('global_array');
5360 }
5361  
5362 if ($self->scriptObj->executionMode eq 'line_num') {
5363  
5364 # In programmes with line numbers, we don't allow DIM .. (10 TO 20)
5365 $specialFlag = FALSE;
5366  
5367 } else {
5368  
5369 # A TRUE argument tells LA::Expression::Lvalue->new to attempt to extract an
5370 # LA::Expression::SpecialArgList, rather than an an LA::Expression::ArgList
5371 $specialFlag = TRUE;
5372 }
5373  
5374 # Process each array in turn (if several appear on the same line, they are separated by
5375 # commas)
5376 do {
5377  
5378 my $expression = Language::Axbasic::Expression::Lvalue->new(
5379 $self->scriptObj,
5380 $self->tokenGroupObj,
5381 $specialFlag,
5382 );
5383  
5384 if (! defined $expression) {
5385  
5386 return $self->scriptObj->setError(
5387 'missing_or_illegal_expression',
5388 $self->_objClass . '->parse',
5389 );
5390  
5391 } else {
5392  
5393 # Save the expression object so $self->implement can use it, if it is called
5394 $self->ivPush('parseDataList', $expression);
5395 }
5396  
5397 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
5398  
5399 # We're finished creating arrays
5400 $self->scriptObj->set_declareMode('default');
5401  
5402 # Parsing complete
5403 return 1;
5404 }
5405  
5406 sub implement {
5407  
5408 # Called by LA::Line->implement directly after a call to $self->parse
5409 #
5410 # Expected arguments
5411 # (none besides $self)
5412 #
5413 # Return values
5414 # 'undef' on improper arguments or if there is an error
5415 # 1 otherwise
5416  
5417 my ($self, $check) = @_;
5418  
5419 # Local variables
5420 my @expList;
5421  
5422 # Check for improper arguments
5423 if (defined $check) {
5424  
5425 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5426 }
5427  
5428 # Import the list of expressions saved by $self->parse
5429 @expList = $self->parseDataList;
5430  
5431 # Create each array, and set its dimensions
5432 foreach my $expression (@expList) {
5433  
5434 my (@upperList, @boundList, @flatList);
5435  
5436 # If the $expression appeared in a line like DIM var, rather than the correct
5437 # DIM var(10), then ->argListObj won't be defined
5438 if (! defined $expression->argListObj) {
5439  
5440 return $self->scriptObj->setError(
5441 'invalid_expression_in_DIM_statement',
5442 $self->_objClass . '->implement',
5443 );
5444 }
5445  
5446 if ($self->scriptObj->executionMode eq 'line_num') {
5447  
5448 # Set up the array. ->evaluate returns a list of upper bounds
5449 @upperList = $expression->argListObj->evaluate();
5450  
5451 # Convert that to a flat list in groups of two, in the form
5452 # (lower, upper, lower, upper...)
5453 # For programmes with line numbers, the lower bound is always 0 (see the explanatory
5454 # comments in LA::Variable::Array->new)
5455 # For any expression that could not be evaluated, an 'undef' value was placed in
5456 # @boundList, so we need to check for that too
5457 foreach my $value (@upperList) {
5458  
5459 if (! defined $value || $value =~ m/\D/) {
5460  
5461 return $self->scriptObj->setError(
5462 'invalid_bound_for_array_dimension',
5463 $self->_objClass . '->implement',
5464 );
5465  
5466 } else {
5467  
5468 push (@flatList, 0, $value);
5469 }
5470 }
5471  
5472 } else {
5473  
5474 # Set up the array. ->evaluate returns a list of list references. Each list
5475 # reference represents a dimension and specifies the bounds of that dimension;
5476 # either in the form (upper) or (lower, upper)
5477 @boundList = $expression->argListObj->evaluate();
5478  
5479 # Convert that to a flat list in groups of two, in the form
5480 # (lower, upper, lower, upper...)
5481 # For programmes without line numbers, we use 1 as the lower bound, if not
5482 # specified
5483 # For any expression that could not be evaluated, an 'undef' value was placed in
5484 # @boundList, so we need to check for that too
5485 foreach my $listRef (@boundList) {
5486  
5487 foreach my $value (@$listRef) {
5488  
5489 if (! defined $value || ! ($value =~ m/^[-]?\d+$/)) {
5490  
5491 return $self->scriptObj->setError(
5492 'invalid_bound_for_array_dimension',
5493 $self->_objClass . '->implement',
5494 );
5495 }
5496 }
5497  
5498 if (scalar (@$listRef) == 1) {
5499  
5500 # If the lower bound is not specified, it is 1; therefore in that case, the
5501 # upper bound cannot be less than 1)
5502 if ($$listRef[0] < 1) {
5503  
5504 return $self->scriptObj->setError(
5505 'invalid_bound_for_array_dimension',
5506 $self->_objClass . '->implement',
5507 );
5508  
5509 } else {
5510  
5511 push (@flatList, 1);
5512 }
5513 }
5514  
5515 push (@flatList, @$listRef);
5516 }
5517 }
5518  
5519 # Create the array
5520 $expression->varObj->dimension(@flatList);
5521 }
5522  
5523 # Implementation complete
5524 return 1;
5525 }
5526 }
5527  
5528 { package Language::Axbasic::Statement::do;
5529  
5530 use strict;
5531 use warnings;
5532 # use diagnostics;
5533  
5534 use Glib qw(TRUE FALSE);
5535  
5536 @Language::Axbasic::Statement::do::ISA = qw(
5537 Language::Axbasic
5538 Language::Axbasic::Statement
5539 );
5540  
5541 # DO
5542  
5543 ##################
5544 # Methods
5545  
5546 sub parse {
5547  
5548 # Called by LA::Line->parse directly after a call to LA::Statement->new
5549 #
5550 # Expected arguments
5551 # (none besides $self)
5552 #
5553 # Return values
5554 # 'undef' on improper arguments or if there is an error
5555 # 1 otherwise
5556  
5557 my ($self, $check) = @_;
5558  
5559 # Local variables
5560 my $subObj;
5561  
5562 # Check for improper arguments
5563 if (defined $check) {
5564  
5565 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5566 }
5567  
5568 # The 'do' keyword is not available in primitive numbering mode
5569 if ($self->scriptObj->executionMode ne 'no_line_num') {
5570  
5571 return $self->scriptObj->setError(
5572 'statement_not_available_with_line_numbers',
5573 $self->_objClass . '->parse',
5574 );
5575 }
5576  
5577 # DO statements always appear on their own
5578 if (! $self->tokenGroupObj->testStatementEnd()) {
5579  
5580 return $self->scriptObj->setError(
5581 'unexpected_keywords,_operators_or_expressions',
5582 $self->_objClass . '->parse',
5583 );
5584 }
5585  
5586 # Add this DO statement to the DO code block stack for the current subroutine
5587 $subObj = $self->scriptObj->returnCurrentSub();
5588 $subObj->push_doStackList($self);
5589  
5590 # We don't know what the corresponding UNTIL statement is, yet
5591 $self->ivAdd('parseDataHash', 'until_statement', undef);
5592  
5593 # Parsing complete
5594 return 1;
5595 }
5596  
5597 sub implement {
5598  
5599 # Called by LA::Line->implement directly after a call to $self->parse
5600 #
5601 # Expected arguments
5602 # (none besides $self)
5603 #
5604 # Return values
5605 # 'undef' on improper arguments
5606 # 1 otherwise
5607  
5608 my ($self, $check) = @_;
5609  
5610 # Local variables
5611 my $subObj;
5612  
5613 # Check for improper arguments
5614 if (defined $check) {
5615  
5616 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5617 }
5618  
5619 # Add this 'do' statement to the code block stack for the current subroutine
5620 $subObj = $self->scriptObj->returnCurrentSub();
5621 $subObj->push_blockStackList($self);
5622  
5623 # Implementation complete
5624 return 1;
5625 }
5626 }
5627  
5628 { package Language::Axbasic::Statement::else;
5629  
5630 use strict;
5631 use warnings;
5632 # use diagnostics;
5633  
5634 use Glib qw(TRUE FALSE);
5635  
5636 @Language::Axbasic::Statement::else::ISA = qw(
5637 Language::Axbasic
5638 Language::Axbasic::Statement
5639 );
5640  
5641 # ELSE IF condition THEN
5642 # ELSEIF condition THEN
5643 # ELSE
5644  
5645 ##################
5646 # Methods
5647  
5648 sub parse {
5649  
5650 # Called by LA::Line->parse directly after a call to LA::Statement->new
5651 #
5652 # Expected arguments
5653 # (none besides $self)
5654 #
5655 # Return values
5656 # 'undef' on improper arguments or if there is an error
5657 # 1 otherwise
5658  
5659 my ($self, $check) = @_;
5660  
5661 # Local variables
5662 my ($subObj, $ifStatement, $elseIfFlag, $token, $condition);
5663  
5664 # Check for improper arguments
5665 if (defined $check) {
5666  
5667 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5668 }
5669  
5670 # The 'else' keyword is not available in primitive numbering mode
5671 if ($self->scriptObj->executionMode ne 'no_line_num') {
5672  
5673 return $self->scriptObj->setError(
5674 'statement_not_available_with_line_numbers',
5675 $self->_objClass . '->parse',
5676 );
5677 }
5678  
5679 # Get the IF statement which starts this code block
5680 $subObj = $self->scriptObj->returnCurrentSub();
5681 if (! $subObj->ifStackList) {
5682  
5683 return $self->scriptObj->setError(
5684 'ELSE_statement_without_matching_IF',
5685 $self->_objClass . '->parse',
5686 );
5687  
5688 } else {
5689  
5690 # The matching IF statement is the last one in the stack
5691 $ifStatement = $subObj->pop_ifStackList();
5692 }
5693  
5694 # Test for ELSEIF or ELSE IF
5695 if ($self->keyword eq 'elseif') {
5696 $elseIfFlag = TRUE;
5697 } else {
5698  
5699 $token = $self->tokenGroupObj->shiftMatchingToken('if');
5700 if (defined $token) {
5701  
5702 $elseIfFlag = TRUE;
5703 }
5704 }
5705  
5706 if ($elseIfFlag) {
5707  
5708 # ELSE IF / ELSEIF statement
5709  
5710 # If the IF statement has already seen a plain ELSE, it must not be be followed by
5711 # another ELSE IF
5712 if (defined $ifStatement->ivShow('parseDataHash', 'else_statement')) {
5713  
5714 return $self->scriptObj->setError(
5715 'ELSE_IF_statement_cannot_follow_ELSE',
5716 $self->_objClass . '->parse',
5717 );
5718 }
5719  
5720 # Everything up until 'then' is a conditional expression
5721 $condition = Language::Axbasic::Expression::LogicalOr->new(
5722 $self->scriptObj,
5723 $self->tokenGroupObj,
5724 );
5725  
5726 if (! defined $condition) {
5727  
5728 return $self->scriptObj->setError(
5729 'missing_or_illegal_conditional_expression',
5730 $self->_objClass . '->parse',
5731 );
5732  
5733 } else {
5734  
5735 # Store the condition expression, so $self->implement can retrieve it
5736 $self->ivAdd('parseDataHash', 'condition', $condition);
5737 }
5738  
5739 if (! defined $self->tokenGroupObj->shiftMatchingToken('then')) {
5740  
5741 return $self->scriptObj->setError(
5742 'missing_THEN_in_ELSE_IF_statement',
5743 $self->_objClass . '->parse',
5744 );
5745 }
5746  
5747 # There should be nothing after the THEN keyword
5748 if (! $self->tokenGroupObj->testStatementEnd()) {
5749  
5750 return $self->scriptObj->setError(
5751 'ELSE_IF_statement_not_terminated_by_THEN',
5752 $self->_objClass . '->parse',
5753 );
5754 }
5755  
5756 # Save this statement in the IF statement's list of ElSE IF statements
5757 $ifStatement->push_parseDataList($self);
5758  
5759 } else {
5760  
5761 # Plain ELSE statement
5762  
5763 # If the IF statement has already seen a plain ELSE, it must not be followed by another
5764 # ELSE
5765 if (defined $ifStatement->ivShow('parseDataHash', 'else_statement')) {
5766  
5767 return $self->scriptObj->setError(
5768 'multiple_ELSE_statements_in_IF_block',
5769 $self->_objClass . '->parse',
5770 );
5771 }
5772  
5773 # There should be nothing after the ELSE keyword. Use a unique error message to make
5774 # clear that ELSE must occur alone
5775 if (! $self->tokenGroupObj->testStatementEnd()) {
5776  
5777 return $self->scriptObj->setError(
5778 'unexpected_keywords,_operators_or_expressions_in_ELSE_statement',
5779 $self->_objClass . '->parse',
5780 )
5781 }
5782  
5783 # Inform the IF statement where its ELSE statement is
5784 $ifStatement->ivAdd('parseDataHash', 'else_statement', $self);
5785 }
5786  
5787 # Store the IF statement so this statement's ->implement can use it
5788 $self->add_parseDataHash('if_statement', $ifStatement);
5789 # Re-insert the IF statement back into its stack
5790 $subObj->push_ifStackList($ifStatement);
5791  
5792 # Parsing complete
5793 return 1;
5794 }
5795  
5796 sub implement {
5797  
5798 # Called by LA::Line->implement directly after a call to $self->parse
5799 #
5800 # Expected arguments
5801 # (none besides $self)
5802 #
5803 # Return values
5804 # 'undef' on improper arguments or if there is an error
5805 # 1 otherwise
5806  
5807 my ($self, $check) = @_;
5808  
5809 # Local variables
5810 my ($ifStatement, $endIfStatement, $subObj, $topStatement);
5811  
5812 # Check for improper arguments
5813 if (defined $check) {
5814  
5815 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5816 }
5817  
5818 # Retrieve the IF statement which starts this code block
5819 $ifStatement = $self->ivShow('parseDataHash', 'if_statement');
5820 # Get the matching END IF statement
5821 $endIfStatement = $ifStatement->ivShow('parseDataHash', 'end_if_statement');
5822  
5823 # This IF..ELSE IF..ELSE..END IF code block has now finished
5824 $subObj = $self->scriptObj->returnCurrentSub();
5825  
5826 # Execution continues at the next statement after END IF
5827 if (defined $endIfStatement->nextStatement) {
5828  
5829 # LA::Script->nextStatement is currently set to this statement; continue execution
5830 # as if this were the END statement
5831 $self->scriptObj->set_nextStatement($endIfStatement);
5832  
5833 } else {
5834  
5835 $self->scriptObj->set_nextStatement(undef);
5836 $self->scriptObj->set_nextLine($endIfStatement->lineObj->procLineNum + 1);
5837 }
5838  
5839 # Remove this code block from the standard code block stack.
5840 if (! $subObj->blockStackList) {
5841  
5842 return $self->scriptObj->setError(
5843 'ELSE_statement_without_matching_IF',
5844 $self->_objClass . '->implement',
5845 );
5846  
5847 } else {
5848  
5849 $topStatement = $subObj->pop_blockStackList();
5850  
5851 # The statement at the top of the stack must be an IF statement, not another kind of
5852 # code block
5853 if ($topStatement->keyword ne 'if') {
5854  
5855 return $self->scriptObj->setError(
5856 'ELSE_statement_without_matching_IF',
5857 $self->_objClass . '->implement',
5858 );
5859 }
5860 }
5861  
5862 # Implementation complete
5863 return 1;
5864 }
5865 }
5866  
5867 { package Language::Axbasic::Statement::emptywin;
5868  
5869 use strict;
5870 use warnings;
5871 # use diagnostics;
5872  
5873 use Glib qw(TRUE FALSE);
5874  
5875 @Language::Axbasic::Statement::emptywin::ISA = qw(
5876 Language::Axbasic
5877 Language::Axbasic::Statement
5878 );
5879  
5880 # EMPTYWIN
5881  
5882 ##################
5883 # Methods
5884  
5885 sub parse {
5886  
5887 # Called by LA::Line->parse directly after a call to LA::Statement->new
5888 #
5889 # Expected arguments
5890 # (none besides $self)
5891 #
5892 # Return values
5893 # 'undef' on improper arguments or if there is an error
5894 # 1 otherwise
5895  
5896 my ($self, $check) = @_;
5897  
5898 # Local variables
5899 my ($expression);
5900  
5901 # Check for improper arguments
5902 if (defined $check) {
5903  
5904 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5905 }
5906  
5907 # EMPTYWIN statements always appear on their own
5908 if (! $self->tokenGroupObj->testStatementEnd()) {
5909  
5910 return $self->scriptObj->setError(
5911 'unexpected_keywords,_operators_or_expressions',
5912 $self->_objClass . '->parse',
5913 );
5914 }
5915  
5916 # Parsing complete
5917 return 1;
5918 }
5919  
5920 sub implement {
5921  
5922 # Called by LA::Line->implement directly after a call to $self->parse
5923 #
5924 # Expected arguments
5925 # (none besides $self)
5926 #
5927 # Return values
5928 # 'undef' on improper arguments or if there is an error
5929 # 1 otherwise
5930  
5931 my ($self, $check) = @_;
5932  
5933 # Local variables
5934  
5935 # Check for improper arguments
5936 if (defined $check) {
5937  
5938 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
5939 }
5940  
5941 # If the Axbasic script is being run from within an Axmud task and the task window is open,
5942 # empty it. Otherwise, do nothing
5943 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
5944  
5945 # Clears the task window's textview
5946 $self->scriptObj->parentTask->clearBuffer();
5947 }
5948  
5949 # Implementation complete
5950 return 1;
5951 }
5952 }
5953  
5954 { package Language::Axbasic::Statement::end;
5955  
5956 use strict;
5957 use warnings;
5958 # use diagnostics;
5959  
5960 use Glib qw(TRUE FALSE);
5961  
5962 @Language::Axbasic::Statement::end::ISA = qw(
5963 Language::Axbasic
5964 Language::Axbasic::Statement
5965 );
5966  
5967 # END
5968 # END IF
5969 # END SUB
5970 # END SELECT
5971  
5972 ##################
5973 # Methods
5974  
5975 sub parse {
5976  
5977 # Called by LA::Line->parse directly after a call to LA::Statement->new
5978 #
5979 # Expected arguments
5980 # (none besides $self)
5981 #
5982 # Return values
5983 # 'undef' on improper arguments or if there is an error
5984 # 1 otherwise
5985  
5986 my ($self, $check) = @_;
5987  
5988 # Local variables
5989 my ($token, $currentSub, $selectStatement, $ifStatement);
5990  
5991 # Check for improper arguments
5992 if (defined $check) {
5993  
5994 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
5995 }
5996  
5997 # Is this an 'END', 'END IF', 'END SELECT', 'END SUB'?
5998 $token = $self->tokenGroupObj->shiftToken();
5999 if (! defined $token) {
6000  
6001 # END statement
6002 $self->ivAdd('parseDataHash', 'end_sub_flag', FALSE);
6003  
6004 # Check that there isn't more than one 'end' statement in the script
6005 if ($self->scriptObj->endStatementFlag) {
6006  
6007 return $self->scriptObj->setError(
6008 'duplicate_END_statement',
6009 $self->_objClass . '->parse',
6010 );
6011  
6012 } else {
6013  
6014 # LA::Script->parse produces an error if, after parsing, it hasn't noticed one
6015 # (and only one) END statement
6016 $self->scriptObj->set_endStatementFlag(TRUE);
6017 }
6018  
6019 } elsif ($token->tokenText eq 'if') {
6020  
6021 # END IF statement
6022 $self->ivAdd('parseDataHash', 'end_if_flag', 1);
6023  
6024 # Check that nothing follows the END IF keywords
6025 if (! defined $self->tokenGroupObj->testStatementEnd()) {
6026  
6027 return $self->scriptObj->setError(
6028 'unexpected_keywords,_operators_or_expressions',
6029 $self->_objClass . '->parse',
6030 );
6031 }
6032  
6033 # Find the matching IF statement
6034 $currentSub = $self->scriptObj->returnCurrentSub();
6035 if (! $currentSub->ifStackList) {
6036  
6037 return $self->scriptObj->setError(
6038 'END_IF_statement_without_matching_IF',
6039 $self->_objClass . '->parse',
6040 );
6041  
6042 } else {
6043  
6044 # The matching IF statement is the last one in the stack
6045 $ifStatement = $currentSub->pop_ifStackList();
6046 $ifStatement->add_parseDataHash('end_if_statement', $self);
6047 # Store the matching statement for ->implement to use
6048 $self->ivAdd('parseDataHash', 'if_statement', $ifStatement);
6049 }
6050  
6051 } elsif ($token->tokenText eq 'select') {
6052  
6053 # END SELECT statement
6054 $self->ivAdd('parseDataHash', 'end_select_flag', 1);
6055  
6056 # END SELECT is not available in primitive numbering mode
6057 if ($self->scriptObj->executionMode ne 'no_line_num') {
6058  
6059 return $self->scriptObj->setError(
6060 'statement_not_available_with_line_numbers',
6061 $self->_objClass . '->parse',
6062 );
6063 }
6064  
6065 # Check that nothing follows the END SELECT keywords
6066 if (! defined $self->tokenGroupObj->testStatementEnd()) {
6067  
6068 return $self->scriptObj->setError(
6069 'unexpected_keywords,_operators_or_expressions',
6070 $self->_objClass . '->parse',
6071 );
6072 }
6073  
6074 # Find the matching SELECT CASE statement
6075 $currentSub = $self->scriptObj->returnCurrentSub();
6076 if (! $currentSub->selectStackList) {
6077  
6078 return $self->scriptObj->setError(
6079 'END_SELECT_statement_without_matching_SELECT_CASE',
6080 $self->_objClass . '->parse',
6081 );
6082  
6083 } else {
6084  
6085 # The matching SELECT CASE statement is the last one in the stack
6086 $selectStatement = $currentSub->pop_selectStackList();
6087 $selectStatement->add_parseDataHash('end_select_statement', $self);
6088 # Store the matching statement for ->implement to use
6089 $self->ivAdd('parseDataHash', 'select_statement', $selectStatement);
6090 }
6091  
6092 } elsif ($token->tokenText eq 'sub') {
6093  
6094 # END SUB statement
6095 $self->ivAdd('parseDataHash', 'end_sub_flag', TRUE);
6096  
6097 # END SUB is not available in primitive numbering mode
6098 if ($self->scriptObj->executionMode ne 'no_line_num') {
6099  
6100 return $self->scriptObj->setError(
6101 'statement_not_available_with_line_numbers',
6102 $self->_objClass . '->parse',
6103 );
6104 }
6105  
6106 # Check that nothing follows the END SUB keywords
6107 if (! defined $self->tokenGroupObj->testStatementEnd()) {
6108  
6109 return $self->scriptObj->setError(
6110 'unexpected_keywords,_operators_or_expressions',
6111 $self->_objClass . '->parse',
6112 );
6113 }
6114  
6115 # Check that we're inside a subroutine declaration
6116 if (! $self->scriptObj->currentParseSub) {
6117  
6118 return $self->scriptObj->setError(
6119 'mismatched_\'end_sub\'_statement',
6120 $self->_objClass . '->parse',
6121 );
6122 }
6123  
6124 # Otherwise, this is the end of the currently parsed subroutine declaration
6125 $currentSub = $self->scriptObj->currentParseSub;
6126 $currentSub->set_terminateStatement($self);
6127 $self->scriptObj->set_currentParseSub(undef);
6128  
6129 # $self->implement needs to know which subroutine is being ended
6130 $self->ivAdd('parseDataHash', 'sub_ref', $currentSub);
6131  
6132 } else {
6133  
6134 # END followed by something other than IF, SELECT or SUB
6135 return $self->scriptObj->setError(
6136 'unexpected_keywords,_operators_or_expressions',
6137 $self->_objClass . '->parse',
6138 );
6139 }
6140  
6141 # Parsing complete
6142 return 1;
6143 }
6144  
6145 sub implement {
6146  
6147 # Called by LA::Line->implement directly after a call to $self->parse
6148 #
6149 # Expected arguments
6150 # (none besides $self)
6151 #
6152 # Return values
6153 # 'undef' on improper arguments or if there is an error
6154 # 1 otherwise
6155  
6156 my ($self, $check) = @_;
6157  
6158 # Local variables
6159 my ($subObj, $callStatement, $topStatement);
6160  
6161 # Check for improper arguments
6162 if (defined $check) {
6163  
6164 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6165 }
6166  
6167 $subObj = $self->scriptObj->returnCurrentSub();
6168  
6169 if ($self->ivShow('parseDataHash', 'end_if_flag')) {
6170  
6171 # END IF statement
6172  
6173 # This IF..END IF code block has now finished
6174 if (! $subObj->blockStackList) {
6175  
6176 return $self->scriptObj->setError(
6177 'END_IF_statement_without_matching_IF',
6178 $self->_objClass . '->implement',
6179 );
6180  
6181 } else {
6182  
6183 $topStatement = $subObj->pop_blockStackList();
6184 # The statement at the top of the stack must be a IF statement, not another kind of
6185 # code block
6186 if ($topStatement->keyword ne 'if') {
6187  
6188 return $self->scriptObj->setError(
6189 'END_IF_statement_without_matching_IF',
6190 $self->_objClass . '->implement',
6191 );
6192 }
6193 }
6194  
6195 } elsif ($self->ivShow('parseDataHash', 'end_select_flag')) {
6196  
6197 # END SELECT statement
6198  
6199 # This SELECT CASE..CASE..END SELECT code block has now finished
6200 $subObj->pop_selectStackList();
6201  
6202 # Also remove this code block from the standard code block stack.
6203 if (! $subObj->blockStackList) {
6204  
6205 return $self->scriptObj->setError(
6206 'END_SELECT_statement_without_matching_SELECT_CASE',
6207 $self->_objClass . '->implement',
6208 );
6209  
6210 } else {
6211  
6212 $topStatement = $subObj->pop_blockStackList();
6213  
6214 # The statement at the top of the stack must be a WHILE statement, not another kind
6215 # of code block
6216 if ($topStatement->keyword ne 'select') {
6217  
6218 return $self->scriptObj->setError(
6219 'END_SELECT_statement_without_matching_SELECT_CASE',
6220 $self->_objClass . '->implement',
6221 );
6222 }
6223 }
6224  
6225 } elsif ($self->ivShow('parseDataHash', 'end_sub_flag')) {
6226  
6227 # END SUB statement
6228 $subObj = $self->ivShow('parseDataHash', 'sub_ref');
6229  
6230 # Execution resumes at the first statement after the one that called the subroutine
6231 $callStatement = $subObj->callStatement;
6232  
6233 # The next statement to execute is the statement after that
6234 if (defined $callStatement->nextStatement) {
6235  
6236 # LA::Script->nextStatement is currently set to this statement; continue execution
6237 # as if this were the GOSUB statement
6238 $self->scriptObj->set_nextStatement($callStatement);
6239  
6240 } else {
6241  
6242 $self->scriptObj->set_nextStatement(undef);
6243 $self->scriptObj->set_nextLine($callStatement->lineObj->procLineNum + 1);
6244 }
6245  
6246 # The subroutine's return value is 0 (for numeric) and '' (for strings). Set the return
6247 # variable, if there is one
6248 if (defined $subObj->returnVar) {
6249  
6250 if ($subObj->returnVarType eq 'numeric') {
6251 $subObj->returnVar->set(0);
6252 } else {
6253 $subObj->returnVar->set('');
6254 }
6255 }
6256  
6257 # Update the script's subroutine stack
6258 $self->scriptObj->popSubStack();
6259  
6260 } else {
6261  
6262 # END statement
6263  
6264 # Execution of the Axbasic script can now stop
6265 if ($self->scriptObj->executionStatus ne 'finished') {
6266  
6267 # 'wait_input' means that parsing/implementation of the script has finished
6268 $self->scriptObj->set_executionStatus('finished');
6269 # 'finished' means that parsing/implementation finished without an error
6270 $self->scriptObj->set_scriptStatus('finished')
6271 }
6272  
6273 # (Do nothing if the execution status has already been set to 3)
6274 }
6275  
6276 # Implementation complete
6277 return 1;
6278 }
6279 }
6280  
6281 { package Language::Axbasic::Statement::erase;
6282  
6283 use strict;
6284 use warnings;
6285 # use diagnostics;
6286  
6287 use Glib qw(TRUE FALSE);
6288 # Include module here, as well as in Axbasic.pm, so that .../t/00-compile.t won't fail
6289 use Fcntl qw(SEEK_SET SEEK_END);
6290  
6291 @Language::Axbasic::Statement::erase::ISA = qw(
6292 Language::Axbasic
6293 Language::Axbasic::Statement
6294 );
6295  
6296 # ERASE #channel
6297  
6298 ##################
6299 # Methods
6300  
6301 sub parse {
6302  
6303 # Called by LA::Line->parse directly after a call to LA::Statement->new
6304 #
6305 # Expected arguments
6306 # (none besides $self)
6307 #
6308 # Return values
6309 # 'undef' on improper arguments or if there is an error
6310 # 1 otherwise
6311  
6312 my ($self, $check) = @_;
6313  
6314 # Local variables
6315 my ($channelToken, $channel, $nameFlag);
6316  
6317 # Check for improper arguments
6318 if (defined $check) {
6319  
6320 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6321 }
6322  
6323 # Get the channel token. For ERASE statements, it must not include a colon at the end
6324 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
6325 if (! defined $channelToken || $channelToken->tokenText =~ m/\:$/) {
6326  
6327 return $self->scriptObj->setError(
6328 'syntax_error',
6329 $self->_objClass . '->parse',
6330 );
6331  
6332 } else {
6333  
6334 # Store the channel number
6335 $channelToken->tokenText =~ m/([0-9]+)/;
6336 $channel = $1;
6337  
6338 # True BASIC specifies that the channel must be in the range 1-999; same range used by
6339 # Axbasic
6340 if ($channel < 1 || $channel > 999) {
6341  
6342 return $self->scriptObj->setError(
6343 'file_channel_NUM_out_of_range',
6344 $self->_objClass . '->parse',
6345 'NUM', $channel,
6346 );
6347  
6348 } else {
6349  
6350 $self->ivAdd('parseDataHash', 'channel', $channel);
6351 }
6352 }
6353  
6354 # Check that nothing follows the file channel
6355 if (! $self->tokenGroupObj->testStatementEnd()) {
6356  
6357 return $self->scriptObj->setError(
6358 'unexpected_keywords,_operators_or_expressions',
6359 $self->_objClass . '->parse',
6360 );
6361 }
6362  
6363 # Parsing complete
6364 return 1;
6365 }
6366  
6367 sub implement {
6368  
6369 # Called by LA::Line->implement directly after a call to $self->parse
6370 #
6371 # Expected arguments
6372 # (none besides $self)
6373 #
6374 # Return values
6375 # 'undef' on improper arguments or if there is an error
6376 # 1 otherwise
6377  
6378 my ($self, $check) = @_;
6379  
6380 # Local variables
6381 my ($channel, $channelObj);
6382  
6383 # Check for improper arguments
6384 if (defined $check) {
6385  
6386 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6387 }
6388  
6389 # Retrieve the variables stored by ->parse
6390 $channel = $self->ivShow('parseDataHash', 'channel');
6391  
6392 # Check that the file channel exists
6393 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
6394  
6395 return $self->scriptObj->setError(
6396 'file_channel_NUM_not_open',
6397 $self->_objClass . '->implement',
6398 'NUM', $channel,
6399 );
6400  
6401 } else {
6402  
6403 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
6404 }
6405  
6406 # Check that writing to the file channel is allowed
6407 if ($channelObj->accessType eq 'input') {
6408  
6409 return $self->scriptObj->setError(
6410 'file_channel_NUM_is_read_only',
6411 $self->_objClass . '->implement',
6412 'NUM', $channel,
6413 );
6414 }
6415  
6416 # Move the pointer to the beginning of the file, then erase its contents
6417 seek($channelObj->fileHandle, 0, Fcntl::SEEK_SET);
6418 truncate($channelObj->fileHandle, 0);
6419  
6420 # Implementation complete
6421 return 1;
6422 }
6423 }
6424  
6425 { package Language::Axbasic::Statement::error;
6426  
6427 use strict;
6428 use warnings;
6429 # use diagnostics;
6430  
6431 use Glib qw(TRUE FALSE);
6432  
6433 @Language::Axbasic::Statement::error::ISA = qw(
6434 Language::Axbasic
6435 Language::Axbasic::Statement
6436 );
6437  
6438 # ERROR expression
6439  
6440 ##################
6441 # Methods
6442  
6443 sub parse {
6444  
6445 # Called by LA::Line->parse directly after a call to LA::Statement->new
6446 #
6447 # Expected arguments
6448 # (none besides $self)
6449 #
6450 # Return values
6451 # 'undef' on improper arguments or if there is an error
6452 # 1 otherwise
6453  
6454 my ($self, $check) = @_;
6455  
6456 # Local variables
6457 my $expression;
6458  
6459 # Check for improper arguments
6460 if (defined $check) {
6461  
6462 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6463 }
6464  
6465 # Get the expression and store it for ->implement to use
6466 $expression = Language::Axbasic::Expression::Arithmetic->new(
6467 $self->scriptObj,
6468 $self->tokenGroupObj,
6469 );
6470  
6471 if (! defined $expression) {
6472  
6473 return $self->scriptObj->setError(
6474 'missing_or_illegal_expression ',
6475 $self->_objClass . '->parse',
6476 );
6477  
6478 } else {
6479  
6480 $self->ivAdd('parseDataHash', 'expression', $expression);
6481 }
6482  
6483 # There should be nothing after the expression
6484 if (! $self->tokenGroupObj->testStatementEnd()) {
6485  
6486 return $self->scriptObj->setError(
6487 'unexpected_keywords,_operators_or_expressions',
6488 $self->_objClass . '->parse',
6489 );
6490 }
6491  
6492 # Parsing complete
6493 return 1;
6494 }
6495  
6496 sub implement {
6497  
6498 # Called by LA::Line->implement directly after a call to $self->parse
6499 #
6500 # Expected arguments
6501 # (none besides $self)
6502 #
6503 # Return values
6504 # 'undef' on improper arguments or if there is an error
6505 # 1 otherwise
6506  
6507 my ($self, $check) = @_;
6508  
6509 # Local variables
6510 my ($expression, $string);
6511  
6512 # Check for improper arguments
6513 if (defined $check) {
6514  
6515 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6516 }
6517  
6518 # Retrieve the expression to be written
6519 $expression = $self->ivShow('parseDataHash', 'expression');
6520 # Evaluate the expression to get a scalar value
6521 $string = $expression->evaluate();
6522  
6523 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
6524 # the error message appears on a new line
6525 if ($self->scriptObj->column != 0) {
6526  
6527 $self->scriptObj->session->writeText('', 'after');
6528 $self->scriptObj->set_column(0);
6529 }
6530  
6531 # Write the error message to the 'main' window
6532 $self->scriptObj->session->writeError($string);
6533  
6534 # Implementation complete
6535 return 1;
6536 }
6537 }
6538  
6539 { package Language::Axbasic::Statement::exit;
6540  
6541 use strict;
6542 use warnings;
6543 # use diagnostics;
6544  
6545 use Glib qw(TRUE FALSE);
6546  
6547 @Language::Axbasic::Statement::exit::ISA = qw(
6548 Language::Axbasic
6549 Language::Axbasic::Statement
6550 );
6551  
6552 # EXIT DO
6553 # EXIT SUB
6554 # EXIT WHILE
6555  
6556 ##################
6557 # Methods
6558  
6559 sub parse {
6560  
6561 # Called by LA::Line->parse directly after a call to LA::Statement->new
6562 #
6563 # Expected arguments
6564 # (none besides $self)
6565 #
6566 # Return values
6567 # 'undef' on improper arguments or if there is an error
6568 # 1 otherwise
6569  
6570 my ($self, $check) = @_;
6571  
6572 # Local variables
6573 my $token;
6574  
6575 # Check for improper arguments
6576 if (defined $check) {
6577  
6578 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6579 }
6580  
6581 # The 'exit' keyword is not available in primitive numbering mode
6582 if ($self->scriptObj->executionMode ne 'no_line_num') {
6583  
6584 return $self->scriptObj->setError(
6585 'statement_not_available_with_line_numbers',
6586 $self->_objClass . '->parse',
6587 );
6588 }
6589  
6590 $token = $self->tokenGroupObj->shiftToken();
6591 if (
6592 ! defined $token
6593 || (
6594 $token->tokenText ne 'do' # EXIT DO
6595 && $token->tokenText ne 'sub' # EXIT SUB
6596 && $token->tokenText ne 'while' # EXIT WHILE
6597 )
6598 ) {
6599 # EXIT must be followed by DO, SUB or WHILE
6600 return $self->scriptObj->setError(
6601 'syntax error',
6602 $self->_objClass . '->parse',
6603 );
6604  
6605 } elsif (defined $self->tokenGroupObj->lookAhead()) {
6606  
6607 return $self->scriptObj->setError(
6608 'unexpected_keywords,_operators_or_expressions',
6609 $self->_objClass . '->parse',
6610 );
6611  
6612 } else {
6613  
6614 # Save the type of exit for ->implement
6615 $self->ivAdd('parseDataHash', 'keyword', $token->tokenText);
6616  
6617 # Parsing complete
6618 return 1;
6619 }
6620 }
6621  
6622 sub implement {
6623  
6624 # Called by LA::Line->implement directly after a call to $self->parse
6625 #
6626 # Expected arguments
6627 # (none besides $self)
6628 #
6629 # Return values
6630 # 'undef' on improper arguments or if there is an error
6631 # 1 otherwise
6632  
6633 my ($self, $check) = @_;
6634  
6635 # Local variables
6636 my ($keyword, $subObj, $matchStatement, $resumeStatement, $exitFlag);
6637  
6638 # Check for improper arguments
6639 if (defined $check) {
6640  
6641 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6642 }
6643  
6644 # Retrieve the keyword that followed the EXIT keyword
6645 $keyword = $self->ivShow('parseDataHash', 'keyword');
6646 # Get the current subroutine
6647 $subObj = $self->scriptObj->returnCurrentSub();
6648  
6649 if ($keyword eq 'do' || $keyword eq 'while') {
6650  
6651 # Get the corresponding DO/WHILE statement from the current subroutine's code block
6652 # stack. Keep removing code blocks from the top of the stack until we get the right
6653 # one
6654 if (! $subObj->blockStackList) {
6655  
6656 # EXIT_DO_statement_without_matching_DO
6657 # EXIT_WHILE_statement_without_matching_WHILE
6658 return $self->scriptObj->setError(
6659 'EXIT_' . uc($keyword) . '_statement_without_matching_' . uc($keyword),
6660 $self->_objClass . '->implement',
6661 );
6662 }
6663  
6664 do {
6665 $matchStatement = $subObj->pop_blockStackList();
6666  
6667 # Check that it's a DO/WHILE statement - not the start of another kind of code block
6668 if ($matchStatement->keyword eq $keyword) {
6669  
6670 # We've found the statement we're looking for
6671 $exitFlag = TRUE;
6672 }
6673  
6674 } until ($exitFlag || ! $subObj->blockStackList);
6675  
6676 if (! $exitFlag) {
6677  
6678 # EXIT_DO_statement_without_matching_DO
6679 # EXIT_WHILE_statement_without_matching_WHILE
6680 return $self->scriptObj->setError(
6681 'EXIT_' . uc($keyword) . '_statement_without_matching_' . uc($keyword),
6682 $self->_objClass . '->implement',
6683 );
6684  
6685 } elsif ($keyword eq 'do') {
6686  
6687 # Get the DO statement's corresponding UNTIL statement
6688 $resumeStatement = $matchStatement->ivShow('parseDataHash', 'until_statement');
6689  
6690 } else {
6691  
6692 # Get the WHILE statement's corresponding LOOP statement
6693 $resumeStatement = $matchStatement->ivShow('parseDataHash', 'loop_statement');
6694 }
6695  
6696 } elsif ($keyword eq 'sub') {
6697  
6698 # EXIT SUB is interpreted exactly the same way as END SUB, except that EXIT SUB won't
6699 # cause an error at the ->parse stage if it doesn't match an earlier SUB statement
6700 if ($subObj->name eq '*main') {
6701  
6702 return $self->scriptObj->setError(
6703 'EXIT_SUB_statement_used_outside_subroutine',
6704 $self->_objClass . '->implement',
6705 );
6706 }
6707  
6708 # Execution resumes at the first statement after the one that called the subroutine
6709 $resumeStatement = $subObj->callStatement;
6710  
6711 # The subroutine's return value is 0 (for numeric) and '' (for strings). Set the return
6712 # variable, if there is one
6713 if (defined $subObj->returnVar) {
6714  
6715 if ($subObj->returnVarType eq 'numeric') {
6716 $subObj->returnVar->set(0);
6717 } else {
6718 $subObj->returnVar->set('');
6719 }
6720 }
6721  
6722 # Update the script's subroutine stack
6723 $self->scriptObj->popSubStack();
6724 }
6725  
6726 if ($resumeStatement) {
6727  
6728 # The next statement to execute is the statement after that
6729 if (defined $resumeStatement->nextStatement) {
6730  
6731 # LA::Script->nextStatement is currently set to this statement; continue execution
6732 # as if this were the Do/SUB/WHILE statement
6733 $self->scriptObj->set_nextStatement($resumeStatement);
6734  
6735 } else {
6736  
6737 $self->scriptObj->set_nextStatement(undef);
6738 $self->scriptObj->set_nextLine($resumeStatement->lineObj->procLineNum + 1);
6739 }
6740 }
6741  
6742 # Implementation complete
6743 return 1;
6744 }
6745 }
6746  
6747 { package Language::Axbasic::Statement::flashwin;
6748  
6749 use strict;
6750 use warnings;
6751 # use diagnostics;
6752  
6753 use Glib qw(TRUE FALSE);
6754  
6755 @Language::Axbasic::Statement::flashwin::ISA = qw(
6756 Language::Axbasic
6757 Language::Axbasic::Statement
6758 );
6759  
6760 # FLASHWIN
6761  
6762 ##################
6763 # Methods
6764  
6765 sub parse {
6766  
6767 # Called by LA::Line->parse directly after a call to LA::Statement->new
6768 #
6769 # Expected arguments
6770 # (none besides $self)
6771 #
6772 # Return values
6773 # 'undef' on improper arguments or if there is an error
6774 # 1 otherwise
6775  
6776 my ($self, $check) = @_;
6777  
6778 # Local variables
6779 my ($expression);
6780  
6781 # Check for improper arguments
6782 if (defined $check) {
6783  
6784 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6785 }
6786  
6787 # FLASHWIN statements always appear on their own
6788 if (! $self->tokenGroupObj->testStatementEnd()) {
6789  
6790 return $self->scriptObj->setError(
6791 'unexpected_keywords,_operators_or_expressions',
6792 $self->_objClass . '->parse',
6793 );
6794 }
6795  
6796 # Parsing complete
6797 return 1;
6798 }
6799  
6800 sub implement {
6801  
6802 # Called by LA::Line->implement directly after a call to $self->parse
6803 #
6804 # Expected arguments
6805 # (none besides $self)
6806 #
6807 # Return values
6808 # 'undef' on improper arguments or if there is an error
6809 # 1 otherwise
6810  
6811 my ($self, $check) = @_;
6812  
6813 # Local variables
6814  
6815 # Check for improper arguments
6816 if (defined $check) {
6817  
6818 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
6819 }
6820  
6821 # If the Axbasic script is being run from within an Axmud task and the task window is open,
6822 # set the window's urgency hint. Otherwise, do nothing
6823 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->winObj) {
6824  
6825 # Sets the window urgency hint
6826 $self->scriptObj->parentTask->winObj->setUrgent();
6827 }
6828  
6829 # Implementation complete
6830 return 1;
6831 }
6832 }
6833  
6834 { package Language::Axbasic::Statement::for;
6835  
6836 use strict;
6837 use warnings;
6838 # use diagnostics;
6839  
6840 use Glib qw(TRUE FALSE);
6841  
6842 @Language::Axbasic::Statement::for::ISA = qw(
6843 Language::Axbasic
6844 Language::Axbasic::Statement
6845 );
6846  
6847 # FOR variable-name = expression TO expression [ STEP expression ]
6848 # FOR EACH variable-name IN variable-name
6849  
6850 ##################
6851 # Methods
6852  
6853 sub parse {
6854  
6855 # Called by LA::Line->parse directly after a call to LA::Statement->new
6856 #
6857 # Expected arguments
6858 # (none besides $self)
6859 #
6860 # Return values
6861 # 'undef' on improper arguments or if there is an error
6862 # 1 otherwise
6863  
6864 my ($self, $check) = @_;
6865  
6866 # Local variables
6867 my ($token, $lvalue, $initExp, $termExp, $stepExp, $newTokenGroup, $expression);
6868  
6869 # Check for improper arguments
6870 if (defined $check) {
6871  
6872 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
6873 }
6874  
6875 # There are two formats for a FOR statement. Store the type, so $self->implement can
6876 # retrieve it
6877 $token = $self->tokenGroupObj->shiftMatchingToken('each');
6878 if (! defined $token) {
6879 $self->ivAdd('parseDataHash', 'each_flag', FALSE);
6880 } else {
6881 $self->ivAdd('parseDataHash', 'each_flag', TRUE);
6882 }
6883  
6884 # Read the iterator variable name
6885 $lvalue = Language::Axbasic::Expression::Lvalue->new(
6886 $self->scriptObj,
6887 $self->tokenGroupObj,
6888 );
6889  
6890 if (! defined $lvalue) {
6891  
6892 return $self->scriptObj->setError(
6893 'missing_or_illegal_iterator',
6894 $self->_objClass . '->parse',
6895 );
6896  
6897 } elsif (
6898 ! $self->ivShow('parseDataHash', 'each_flag')
6899 && $lvalue->isa('Language::Axbasic::Expression::String')
6900 ) {
6901 return $self->scriptObj->setError(
6902 'missing_or_illegal_iterator',
6903 $self->_objClass . '->parse',
6904 );
6905  
6906 } else {
6907  
6908 # Store the iterator, so $self->implement can retrieve it
6909 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
6910 }
6911  
6912 if (! $self->ivShow('parseDataHash', 'each_flag')) {
6913  
6914 # First type: FOR variable-name = expression TO expression [ STEP expression ]
6915  
6916 # Read the assignment operator
6917 $token = $self->tokenGroupObj->shiftMatchingToken('=');
6918 if (! defined $token) {
6919  
6920 return $self->scriptObj->setError(
6921 'missing_assignment_operator',
6922 $self->_objClass . '->parse',
6923 );
6924 }
6925  
6926 # Read the initialisation expression
6927 $initExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6928 $self->scriptObj,
6929 $self->tokenGroupObj,
6930 );
6931  
6932 if (! defined $initExp) {
6933  
6934 return $self->scriptObj->setError(
6935 'missing_or_illegal_expression',
6936 $self->_objClass . '->parse',
6937 );
6938  
6939 } else {
6940  
6941 # Store the initialisation expression, so $self->implement can retrieve it
6942 $self->ivAdd('parseDataHash', 'init_exp', $initExp);
6943 }
6944  
6945 # Read the 'to' keyword
6946 $token = $self->tokenGroupObj->shiftMatchingToken('to');
6947 if (! defined $token) {
6948  
6949 return $self->scriptObj->setError(
6950 'syntax_error',
6951 $self->_objClass . '->parse',
6952 );
6953 }
6954  
6955 # Until the keyword 'step', or the end of the statement, we're copying the termination
6956 # expression
6957 $termExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6958 $self->scriptObj,
6959 $self->tokenGroupObj,
6960 );
6961  
6962 if (! defined $termExp) {
6963  
6964 return $self->scriptObj->setError(
6965 'missing_or_illegal_expression',
6966 $self->_objClass . '->parse',
6967 );
6968  
6969 } else {
6970  
6971 # Store the initialisation expression, so $self->implement can retrieve it
6972 $self->ivAdd('parseDataHash', 'term_exp', $termExp);
6973 }
6974  
6975 # If there is anything left, it should be a 'step' keyword. If 'step' isn't specified,
6976 # use the default increment of +1
6977 $token = $self->tokenGroupObj->shiftMatchingToken('step');
6978 if (defined $token) {
6979  
6980 $stepExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
6981 $self->scriptObj,
6982 $self->tokenGroupObj,
6983 );
6984  
6985 if (! defined $stepExp) {
6986  
6987 return $self->scriptObj->setError(
6988 'missing_or_illegal_expression',
6989 $self->_objClass . '->parse',
6990 );
6991  
6992 } else {
6993  
6994 # Store the step expression, so $self->implement can retrieve it
6995 $self->ivAdd('parseDataHash', 'step_exp', $stepExp);
6996 }
6997  
6998 } elsif (! $self->tokenGroupObj->testStatementEnd()) {
6999  
7000 # There shouldn't be anything after the 'step' expression
7001 return $self->scriptObj->setError(
7002 'unexpected_keywords,_operators_or_expressions',
7003 $self->_objClass . '->parse',
7004 );
7005  
7006 } else {
7007  
7008 # Create a separate token group to hold a token containing '1', and lex it, so we
7009 # can save the '1' as an expression
7010 $newTokenGroup = Language::Axbasic::TokenGroup->new($self->scriptObj, '1');
7011 $newTokenGroup->lex();
7012 $stepExp = Language::Axbasic::Expression::Arithmetic::Numeric->new(
7013 $self->scriptObj,
7014 $newTokenGroup,
7015 );
7016  
7017 # Store the step expression, so $self->implement can retrieve it
7018 $self->ivAdd('parseDataHash', 'step_exp', $stepExp);
7019 }
7020  
7021 } else {
7022  
7023 # Second type: FOR EACH variable-name IN variable-name
7024  
7025 # Read the 'in' keyword
7026 $token = $self->tokenGroupObj->shiftMatchingToken('in');
7027 if (! defined $token) {
7028  
7029 return $self->scriptObj->setError(
7030 'syntax_error',
7031 $self->_objClass . '->parse',
7032 );
7033 }
7034  
7035 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
7036 # LA::Variable->lookup that we're intentionally referring to an array variable, such
7037 # as that created by
7038 # DIM var (10)
7039 # ...by a variable name that looks like a scalar, i.e.
7040 # SORT var
7041 $self->scriptObj->set_declareMode('simple');
7042  
7043 # Get the variable name
7044 $expression = Language::Axbasic::Expression::Lvalue->new(
7045 $self->scriptObj,
7046 $self->tokenGroupObj,
7047 );
7048  
7049 if (! defined $expression) {
7050  
7051 return $self->scriptObj->setError(
7052 'missing_or_illegal_array_variable',
7053 $self->_objClass . '->parse',
7054 );
7055 }
7056  
7057 # Reset the temporary IV
7058 $self->scriptObj->set_declareMode('default');
7059  
7060 if (! $self->tokenGroupObj->testStatementEnd()) {
7061  
7062 return $self->scriptObj->setError(
7063 'unexpected_keywords,_operators_or_expressions',
7064 $self->_objClass . '->parse',
7065 );
7066 }
7067  
7068 # Store the variable for ->implement to use
7069 $self->ivAdd('parseDataHash', 'array_exp', $expression);
7070 }
7071  
7072 # Parsing complete
7073 return 1;
7074 }
7075  
7076 sub implement {
7077  
7078 # Called by LA::Line->implement directly after a call to $self->parse
7079 #
7080 # Expected arguments
7081 # (none besides $self)
7082 #
7083 # Return values
7084 # 'undef' on improper arguments
7085 # 1 otherwise
7086  
7087 my ($self, $check) = @_;
7088  
7089 # Local variables
7090 my (
7091 $eachFlag, $lvalue, $initExp, $arrayExp, $result, $iterVar, $subObj, $elementVar,
7092 @indexList,
7093 );
7094  
7095 # Check for improper arguments
7096 if (defined $check) {
7097  
7098 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7099 }
7100  
7101 # Retrieve the variables stored by ->parse
7102 $eachFlag = $self->ivShow('parseDataHash', 'each_flag');
7103 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
7104 $initExp = $self->ivShow('parseDataHash', 'init_exp');
7105 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
7106  
7107 # Get the variable object for the iterator
7108 $iterVar = $lvalue->variable;
7109 if (! defined $iterVar) {
7110  
7111 return $self->scriptObj->setDebug(
7112 'Couldn\'t set up iterator in FOR statement',
7113 $self->_objClass . '->implement',
7114 );
7115 }
7116  
7117 # There are two formats for a FOR statement
7118 if (! $eachFlag) {
7119  
7120 # First type: FOR variable-name = expression TO expression [ STEP expression ]
7121  
7122 # Evaluate the initialisation expression, and set the iterator with the value
7123 $result = $initExp->evaluate();
7124 if (! defined $result) {
7125  
7126 return $self->scriptObj->setDebug(
7127 'Couldn\'t evaluate initialisation expression in FOR statement',
7128 $self->_objClass . '->implement',
7129 );
7130  
7131 } else {
7132  
7133 $iterVar->set($result);
7134 }
7135  
7136 } else {
7137  
7138 # Second type: FOR EACH variable-name IN variable-name
7139  
7140 # If the array is empty, then we can't iterate over it (and there's no way to jump to
7141 # the NEXT statement)
7142 if ((scalar $arrayExp->varObj->cellList) <= 1) {
7143  
7144 return $self->scriptObj->setError(
7145 'cannot_iterate_over_empty_array',
7146 $self->_objClass . '->implement',
7147 );
7148  
7149 } else {
7150  
7151 # Otherwise, Axbasic handles multi-dimensional arrays with lists inside lists. Each
7152 # list represents a dimension and contains the lower bound, followed by an
7153 # optional list of value. (In multi-dimensional arrays, all dimensions have at
7154 # least one value)
7155 # Create a list of indices, each referring to a value in a dimension. The ->getCell
7156 # function takes account of the first item in every dimension, which is the lower
7157 # bound, hence the minimum index for each dimension is 0
7158 for (my $i = 1; $i <= $arrayExp->varObj->dimCount; $i++) {
7159  
7160 push (@indexList, 0);
7161 }
7162  
7163 # The NEXT statement increments the array index/indices, until we reach the end of
7164 # the array
7165 $self->ivAdd('parseDataHash', 'index_list_ref', \@indexList);
7166  
7167 # Retrieve the variable that's the first element of the array, and set the iterator
7168 # with its value. Ignore the cell numbered 0 - FOR EACH assumes the first
7169 # significant cell is #1
7170 $elementVar = $arrayExp->varObj->getCell(@indexList);
7171 if (! $elementVar) {
7172  
7173 return $self->scriptObj->setError(
7174 'empty_array_in_FOR_EACH_statement',
7175 $self->_objClass . '->implement',
7176 );
7177  
7178 } else {
7179  
7180 $iterVar->set($elementVar->value);
7181 }
7182 }
7183 }
7184  
7185 # Add this 'for' statement to the code block stack for the current subroutine
7186 $subObj = $self->scriptObj->returnCurrentSub();
7187 $subObj->push_blockStackList($self);
7188  
7189 # Implementation complete
7190 return 1;
7191 }
7192 }
7193  
7194 { package Language::Axbasic::Statement::global;
7195  
7196 use strict;
7197 use warnings;
7198 # use diagnostics;
7199  
7200 use Glib qw(TRUE FALSE);
7201  
7202 @Language::Axbasic::Statement::global::ISA = qw(
7203 Language::Axbasic
7204 Language::Axbasic::Statement
7205 );
7206  
7207 # GLOBAL variable-name [ , variable-name ... ]
7208  
7209 ##################
7210 # Methods
7211  
7212 sub parse {
7213  
7214 # Called by LA::Line->parse directly after a call to LA::Statement->new
7215 #
7216 # Expected arguments
7217 # (none besides $self)
7218 #
7219 # Return values
7220 # 'undef' on improper arguments or if there is an error
7221 # 1 otherwise
7222  
7223 my ($self, $check) = @_;
7224  
7225 # Local variables
7226 my ($token, $argListObj, $lvalue);
7227  
7228 # Check for improper arguments
7229 if (defined $check) {
7230  
7231 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7232 }
7233  
7234 # The 'global' keyword is not available in primitive numbering mode
7235 if ($self->scriptObj->executionMode ne 'no_line_num') {
7236  
7237 return $self->scriptObj->setError(
7238 'statement_not_available_with_line_numbers',
7239 $self->_objClass . '->parse',
7240 );
7241 }
7242  
7243 # Temporarily set the IV that allows undeclared variables to be created
7244 $self->scriptObj->set_declareMode('global_scalar');
7245  
7246 # Process each array in turn (if several appear on the same line, they are separated by
7247 # commas)
7248 do {
7249  
7250 $lvalue = Language::Axbasic::Expression::Lvalue->new(
7251 $self->scriptObj,
7252 $self->tokenGroupObj,
7253 );
7254  
7255 if (! defined $lvalue) {
7256  
7257 return $self->scriptObj->setError(
7258 'missing_or_illegal_variable',
7259 $self->_objClass . '->parse',
7260 );
7261 }
7262  
7263 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
7264  
7265 # Reset the temporary IV
7266 $self->scriptObj->set_declareMode('default');
7267  
7268 # Check there is nothing else (except for the statement separator, :)
7269 if (! defined $self->tokenGroupObj->testStatementEnd()) {
7270  
7271 return $self->scriptObj->setError(
7272 'unexpected_keywords,_operators_or_expressions',
7273 $self->_objClass . '->parse',
7274 );
7275 }
7276  
7277 # Parsing complete
7278 return 1;
7279 }
7280  
7281 # sub implement {} # No ->implement method - LA::Variable->lookup has already added the
7282 # variable to LA::Script->globalScalarHash or ->globalArrayHash
7283 }
7284  
7285 { package Language::Axbasic::Statement::gosub;
7286  
7287 use strict;
7288 use warnings;
7289 # use diagnostics;
7290  
7291 use Glib qw(TRUE FALSE);
7292  
7293 @Language::Axbasic::Statement::gosub::ISA = qw(
7294 Language::Axbasic
7295 Language::Axbasic::Statement
7296 );
7297  
7298 # GOSUB expression
7299  
7300 ##################
7301 # Methods
7302  
7303 sub parse {
7304  
7305 # Called by LA::Line->parse directly after a call to LA::Statement->new
7306 #
7307 # Expected arguments
7308 # (none besides $self)
7309 #
7310 # Return values
7311 # 'undef' on improper arguments or if there is an error
7312 # 1 otherwise
7313  
7314 my ($self, $check) = @_;
7315  
7316 # Local variables
7317 my $expression;
7318  
7319 # Check for improper arguments
7320 if (defined $check) {
7321  
7322 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7323 }
7324  
7325 # The 'gosub' keyword is only available in primitive numbering mode
7326 if ($self->scriptObj->executionMode ne 'line_num') {
7327  
7328 return $self->scriptObj->setError(
7329 'statement_not_available_without_line_numbers',
7330 $self->_objClass . '->parse',
7331 );
7332 }
7333  
7334 # The rest of the statement is an expression for the line to call
7335 $expression = Language::Axbasic::Expression::Arithmetic->new(
7336 $self->scriptObj,
7337 $self->tokenGroupObj,
7338 );
7339  
7340 if (! defined $expression) {
7341  
7342 return $self->scriptObj->setError(
7343 'missing_or_illegal_expression',
7344 $self->_objClass . '->parse',
7345 );
7346 }
7347  
7348 # Check that nothing follows the expression
7349 if (! $self->tokenGroupObj->testStatementEnd()) {
7350  
7351 return $self->scriptObj->setError(
7352 'unexpected_keywords,_operators_or_expression',
7353 $self->_objClass . '->parse',
7354 );
7355 }
7356  
7357 # Store the gosub expression, so $self->implement can retrieve it
7358 $self->ivAdd('parseDataHash', 'expression', $expression);
7359  
7360 # Parsing complete
7361 return 1;
7362 }
7363  
7364 sub implement {
7365  
7366 # Called by LA::Line->implement directly after a call to $self->parse
7367 #
7368 # Expected arguments
7369 # (none besides $self)
7370 #
7371 # Return values
7372 # 'undef' on improper arguments
7373 # 1 otherwise
7374  
7375 my ($self, $check) = @_;
7376  
7377 # Local variables
7378 my ($expression, $lineNumber);
7379  
7380 # Check for improper arguments
7381 if (defined $check) {
7382  
7383 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7384 }
7385  
7386 # Retrieve the variable stored by ->parse
7387 $expression = $self->ivShow('parseDataHash', 'expression');
7388  
7389 # Evaluate the expression to get the line number (because $expression could be 'x+17/3' as
7390 # well as '20')
7391 $lineNumber = $expression->evaluate();
7392 if (! defined $lineNumber || ! ($lineNumber =~ /^\d+$/)) {
7393  
7394 return $self->scriptObj->setError(
7395 'illegal_line_number_NUM',
7396 $self->_objClass . '->implement',
7397 'NUM', $lineNumber,
7398 );
7399 }
7400  
7401 # Check that the primitive line number exists
7402 if (! $self->scriptObj->ivExists('primLineHash', $lineNumber)) {
7403  
7404 return $self->scriptObj->setError(
7405 'line_number_NUM_not_found',
7406 $self->_objClass . '->implement',
7407 'NUM', $lineNumber,
7408 );
7409  
7410 } else {
7411  
7412 # Push the current statement onto the GOSUB stack
7413 $self->scriptObj->push_gosubStackList($self);
7414  
7415 # The line in the expression is the next line to be executed
7416 $self->scriptObj->set_nextLine($self->scriptObj->ivShow('primLineHash', $lineNumber));
7417  
7418 $self->scriptObj->set_nextStatement(undef);
7419 }
7420  
7421 # Implementation complete
7422 return 1;
7423 }
7424 }
7425  
7426 { package Language::Axbasic::Statement::goto;
7427  
7428 use strict;
7429 use warnings;
7430 # use diagnostics;
7431  
7432 use Glib qw(TRUE FALSE);
7433  
7434 @Language::Axbasic::Statement::goto::ISA = qw(
7435 Language::Axbasic
7436 Language::Axbasic::Statement
7437 );
7438  
7439 # GOTO expression
7440  
7441 ##################
7442 # Methods
7443  
7444 sub parse {
7445  
7446 # Called by LA::Line->parse directly after a call to LA::Statement->new
7447 #
7448 # Expected arguments
7449 # (none besides $self)
7450 #
7451 # Return values
7452 # 'undef' on improper arguments or if there is an error
7453 # 1 otherwise
7454  
7455 my ($self, $check) = @_;
7456  
7457 # Local variables
7458 my $expression;
7459  
7460 # Check for improper arguments
7461 if (defined $check) {
7462  
7463 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7464 }
7465  
7466 # The 'goto' keyword is only available in primitive numbering mode
7467 if ($self->scriptObj->executionMode ne 'line_num') {
7468  
7469 return $self->scriptObj->setError(
7470 'statement_not_available_without_line_numbers',
7471 $self->_objClass . '->parse',
7472 );
7473 }
7474  
7475 # The rest of the statement is an expression for the line to go to
7476 $expression = Language::Axbasic::Expression::Arithmetic->new(
7477 $self->scriptObj,
7478 $self->tokenGroupObj,
7479 );
7480  
7481 if (! defined $expression) {
7482  
7483 return $self->scriptObj->setError(
7484 'missing_or_illegal_expression ',
7485 $self->_objClass . '->parse',
7486 );
7487 }
7488  
7489 # Check that nothing follows the expression
7490 if (! $self->tokenGroupObj->testStatementEnd()) {
7491  
7492 return $self->scriptObj->setError(
7493 'unexpected_keywords,_operators_or_expressions',
7494 $self->_objClass . '->parse',
7495 );
7496 }
7497  
7498 # Store the arithmetic expression, so $self->implement can retrieve it
7499 $self->ivAdd('parseDataHash', 'expression', $expression);
7500  
7501 # Parsing complete
7502 return 1;
7503 }
7504  
7505 sub implement {
7506  
7507 # Called by LA::Line->implement directly after a call to $self->parse
7508 #
7509 # Expected arguments
7510 # (none besides $self)
7511 #
7512 # Return values
7513 # 'undef' on improper arguments
7514 # 1 otherwise
7515  
7516 my ($self, $check) = @_;
7517  
7518 # Local variables
7519 my ($expression, $lineNumber);
7520  
7521 # Check for improper arguments
7522 if (defined $check) {
7523  
7524 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7525 }
7526  
7527 # Retrieve the variable stored by ->parse
7528 $expression = $self->ivShow('parseDataHash', 'expression');
7529  
7530 # Evaluate the expression to get the line number (because $expression could be 'x+17/3' as
7531 # well as '20')
7532 $lineNumber = $expression->evaluate();
7533 if (! defined $lineNumber || ! ($lineNumber =~ /^\d+$/)) {
7534  
7535 return $self->scriptObj->setError(
7536 'illegal_line_number_NUM',
7537 $self->_objClass . '->implement',
7538 'NUM', $lineNumber,
7539 );
7540 }
7541  
7542 # Check that the primitive line number exists
7543 if (! $self->scriptObj->ivExists('primLineHash', $lineNumber)) {
7544  
7545 return $self->scriptObj->setError(
7546 'line_number_NUM_not_found',
7547 $self->_objClass . '->implement',
7548 'NUM', $lineNumber,
7549 );
7550  
7551 } else {
7552  
7553 # That's the next line to be executed
7554 $self->scriptObj->set_nextLine(
7555 $self->scriptObj->ivShow('primLineHash', $lineNumber),
7556 );
7557 $self->scriptObj->set_nextStatement(undef);
7558 }
7559  
7560 # Implementation complete
7561 return 1;
7562 }
7563 }
7564  
7565 { package Language::Axbasic::Statement::help;
7566  
7567 use strict;
7568 use warnings;
7569 # use diagnostics;
7570  
7571 use Glib qw(TRUE FALSE);
7572  
7573 @Language::Axbasic::Statement::help::ISA = qw(
7574 Language::Axbasic
7575 Language::Axbasic::Statement
7576 );
7577  
7578 # HELP
7579 # HELP expression
7580  
7581 ##################
7582 # Methods
7583  
7584 sub parse {
7585  
7586 # Called by LA::Line->parse directly after a call to LA::Statement->new
7587 #
7588 # Expected arguments
7589 # (none besides $self)
7590 #
7591 # Return values
7592 # 'undef' on improper arguments or if there is an error
7593 # 1 otherwise
7594  
7595 my ($self, $check) = @_;
7596  
7597 # Local variables
7598 my $expression;
7599  
7600 # Check for improper arguments
7601 if (defined $check) {
7602  
7603 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7604 }
7605  
7606 if ($self->tokenGroupObj->testStatementEnd()) {
7607  
7608 # HELP
7609  
7610 $self->ivAdd('parseDataHash', 'expression', undef);
7611  
7612 } else {
7613  
7614 # HELP Expression
7615  
7616 # Get the expression and store it for ->implement to use.
7617 $expression = Language::Axbasic::Expression::Arithmetic->new(
7618 $self->scriptObj,
7619 $self->tokenGroupObj,
7620 );
7621  
7622 if (! defined $expression) {
7623  
7624 return $self->scriptObj->setError(
7625 'missing_or_illegal_expression ',
7626 $self->_objClass . '->parse',
7627 );
7628  
7629 } else {
7630  
7631 $self->ivAdd('parseDataHash', 'expression', $expression);
7632 }
7633  
7634 # There should be nothing after the expression
7635 if (! $self->tokenGroupObj->testStatementEnd()) {
7636  
7637 return $self->scriptObj->setError(
7638 'unexpected_keywords,_operators_or_expressions',
7639 $self->_objClass . '->parse',
7640 );
7641 }
7642 }
7643  
7644 # Parsing complete
7645 return 1;
7646 }
7647  
7648 sub implement {
7649  
7650 # Called by LA::Line->implement directly after a call to $self->parse
7651 #
7652 # Expected arguments
7653 # (none besides $self)
7654 #
7655 # Return values
7656 # 'undef' on improper arguments or if there is an error
7657 # 1 otherwise
7658  
7659 my ($self, $check) = @_;
7660  
7661 # Local variables
7662 my ($expression, $topic);
7663  
7664 # Check for improper arguments
7665 if (defined $check) {
7666  
7667 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7668 }
7669  
7670 # Retrieve the expression to be displayed
7671 $expression = $self->ivShow('parseDataHash', 'expression');
7672 if (! defined $expression) {
7673  
7674 # 'HELP' is the same as the client command ';axbasichelp'
7675 $self->scriptObj->session->pseudoCmd('axbasichelp', $self->scriptObj->pseudoCmdMode);
7676  
7677 } else {
7678  
7679 # 'HELP Expression' is the same as the client command ';axbasichelp <topic>'
7680 $topic = $expression->evaluate();
7681 $self->scriptObj->session->pseudoCmd(
7682 'axbasichelp <' . $topic . '>',
7683 $self->scriptObj->pseudoCmdMode,
7684 );
7685 }
7686  
7687 # Implementation complete
7688 return 1;
7689 }
7690 }
7691  
7692 { package Language::Axbasic::Statement::if;
7693  
7694 use strict;
7695 use warnings;
7696 # use diagnostics;
7697  
7698 use Glib qw(TRUE FALSE);
7699  
7700 @Language::Axbasic::Statement::if::ISA = qw(
7701 Language::Axbasic
7702 Language::Axbasic::Statement
7703 );
7704  
7705 # IF condition THEN statement [ : statement ...] [ ELSE statement [ : statement ...]]
7706 # IF condition THEN statement [ : statement ...] [ ELSEIF condition [ : statement ...]]
7707 # IF condition THEN expression [ ELSE expression ]
7708 #
7709 # IF condition THEN
7710 # statement
7711 # statement
7712 # ELSE IF condition THEN
7713 # statement
7714 # ELSEIF condition THEN
7715 # statement
7716 # ELSE
7717 # statement
7718 # END IF
7719  
7720 ##################
7721 # Methods
7722  
7723 sub parse {
7724  
7725 # Called by LA::Line->parse directly after a call to LA::Statement->new
7726 #
7727 # Expected arguments
7728 # (none besides $self)
7729 #
7730 # Return values
7731 # 'undef' on improper arguments or if there is an error
7732 # 1 otherwise
7733  
7734 my ($self, $check) = @_;
7735  
7736 # Local variables
7737 my (
7738 $condition, $newTokenGroup, $previousStatement, $thenStatement, $elseStatement,
7739 $otherStatement, $subObj, $token,
7740 );
7741  
7742 # Check for improper arguments
7743 if (defined $check) {
7744  
7745 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
7746 }
7747  
7748 # Everything up until 'then' is a conditional expression
7749 $condition = Language::Axbasic::Expression::LogicalOr->new(
7750 $self->scriptObj,
7751 $self->tokenGroupObj,
7752 );
7753  
7754 if (! defined $condition) {
7755  
7756 return $self->scriptObj->setError(
7757 'missing_or_illegal_conditional_expression',
7758 $self->_objClass . '->parse',
7759 );
7760  
7761 } else {
7762  
7763 # Store the condition expression, so $self->implement can retrieve it
7764 $self->ivAdd('parseDataHash', 'condition', $condition);
7765 }
7766  
7767 if (! defined $self->tokenGroupObj->shiftMatchingToken('then')) {
7768  
7769 return $self->scriptObj->setError(
7770 'syntax_error',
7771 $self->_objClass . '->parse',
7772 );
7773 }
7774  
7775 # Everything up until 'else' or the end of the line is one or more statements to do if the
7776 # 'if' condition is true
7777 if (! defined $self->tokenGroupObj->lookAhead()) {
7778  
7779 # This statement is the start of a multi-line IF..END IF code block
7780 # Add it to the IF code block stack for the current subroutine
7781 $subObj = $self->scriptObj->returnCurrentSub();
7782 $subObj->push_ifStackList($self);
7783  
7784 # We don't know where the corresponding END IF statement is yet
7785 $self->ivAdd('parseDataHash', 'end_if_statement', undef);
7786  
7787 } else {
7788  
7789 # Import all the tokens until the ELSE or ELSEIF statement (if there is no ELSE of ELSE
7790 # IF, just import all the tokens)
7791 $newTokenGroup = Language::Axbasic::TokenGroup->new($self->scriptObj);
7792 $newTokenGroup->importTokens($self->tokenGroupObj, 'else', 'elseif');
7793  
7794 # Create a new statement to parse the 'then' clause, and parse the statement
7795 # 'line_num_ok' tells the new statement that it's parsing a 'then/else', so that
7796 # 'then 20' is parsed like 'then goto 20'
7797 $thenStatement = Language::Axbasic::Statement->new(
7798 $self->scriptObj,
7799 $self->lineObj,
7800 $newTokenGroup,
7801 'line_num_ok',
7802 );
7803  
7804 if (! defined $thenStatement) {
7805  
7806 return $self->scriptObj->setError(
7807 'syntax_error',
7808 $self->_objClass . '->parse',
7809 );
7810  
7811 } else {
7812  
7813 $thenStatement->parse();
7814 $previousStatement = $thenStatement;
7815 }
7816  
7817 # Deal with [: Statement]
7818 while (defined ($newTokenGroup->shiftTokenIfCategory('statement_end'))) {
7819  
7820 # A plain line number, like 'then 20', is only allowed in the first 'then/else'
7821 # statement
7822 $otherStatement = Language::Axbasic::Statement->new(
7823 $self->scriptObj,
7824 $self->lineObj,
7825 $newTokenGroup,
7826 );
7827  
7828 $otherStatement->parse();
7829 $previousStatement->set_nextStatement($otherStatement);
7830 $previousStatement = $otherStatement;
7831 }
7832  
7833 # Make sure we don't do the 'else' after the 'then'!
7834 $previousStatement->set_nextStatement(undef);
7835  
7836 # If there is anything left in $self->tokenGroup, it's the ELSE / ELSEIF clause
7837 # If we find an initial ELSEIF token, the following code is much simpler if we pretend
7838 # that it was two tokens, ELSE and IF
7839 $token = $self->tokenGroupObj->shiftMatchingToken('else');
7840 if (! defined $token) {
7841  
7842 $token = $self->tokenGroupObj->lookAhead();
7843 if (defined $token && $token->tokenText eq 'elseif') {
7844  
7845 # Pretend we have shifted an ELSE token, and convert the first remaining token
7846 # to an IF
7847 $token->set_tokenText('if');
7848  
7849 } else {
7850  
7851 $token = undef;
7852 }
7853 }
7854  
7855 if (defined $token) {
7856  
7857 # Use up all the remaining tokens
7858 $elseStatement = Language::Axbasic::Statement->new(
7859 $self->scriptObj,
7860 $self->lineObj,
7861 $self->tokenGroupObj,
7862 'line_num_ok',
7863 );
7864  
7865 if (! defined $elseStatement) {
7866  
7867 return $self->scriptObj->setError(
7868 'syntax_error',
7869 $self->_objClass . '->parse',
7870 );
7871  
7872 } else {
7873  
7874 $elseStatement->parse();
7875 $previousStatement = $elseStatement;
7876 }
7877  
7878 while (defined($self->tokenGroupObj->shiftTokenIfCategory('statement_end'))) {
7879  
7880 $otherStatement = Language::Axbasic::Statement->new(
7881 $self->scriptObj,
7882 $self->lineObj,
7883 $self->tokenGroupObj,
7884 );
7885  
7886 $otherStatement->parse();
7887 $previousStatement->set_nextStatement($otherStatement);
7888 $previousStatement = $otherStatement;
7889 }
7890  
7891 $previousStatement->set_nextStatement(undef);
7892  
7893 if (! $self->tokenGroupObj->testStatementEnd()) {
7894  
7895 return $self->scriptObj->setError(
7896 'unexpected_keywords,_operators_or_expressions',
7897 $self->_objClass . '->parse',
7898 )
7899 }
7900  
7901 } elsif (! $self->tokenGroupObj->testStatementEnd()) {
7902  
7903 return $self->scriptObj->setError(
7904 'unexpected_keywords,_operators_or_expressions',
7905 $self->_objClass . '->parse',
7906 )
7907 }
7908  
7909 # Save the 'then' and 'else' statements, so ->implement can retrieve them
7910 $self->ivAdd('parseDataHash', 'then_statement', $thenStatement);
7911 $self->ivAdd('parseDataHash', 'else_statement', $elseStatement);
7912 }
7913  
7914 # Parsing complete
7915 return 1;
7916 }
7917  
7918 sub implement {
7919  
7920 # Called by LA::Line->implement directly after a call to $self->parse
7921 #
7922 # Expected arguments
7923 # (none besides $self)
7924 #
7925 # Return values
7926 # 'undef' on improper arguments
7927 # 1 otherwise
7928  
7929 my ($self, $check) = @_;
7930  
7931 # Local variables
7932 my (
7933 $subObj, $thenStatement, $elseStatement, $condition, $endIfStatement, $nextStatement,
7934 @statementList,
7935 );
7936  
7937 # Check for improper arguments
7938 if (defined $check) {
7939  
7940 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
7941 }
7942  
7943 # Retrieve the stored data
7944 $thenStatement = $self->ivShow('parseDataHash', 'then_statement');
7945 $elseStatement = $self->ivShow('parseDataHash', 'else_statement');
7946  
7947 # Single-line IF..THEN..ELSE statement
7948 if ($thenStatement) {
7949  
7950 $condition = $self->ivShow('parseDataHash', 'condition');
7951  
7952 # Decide which statement should be executed next, depending on whether the $condition is
7953 # true, or not
7954 if ($condition->evaluate()) {
7955  
7956 # Execute the 'then' statement (which always exists)
7957 $self->ivPoke('nextStatement', $thenStatement);
7958  
7959 } else {
7960  
7961 # Execute the 'else' statement (if it exists), or just continue on to the next
7962 # statement in the script (if it doesn't)
7963 $self->ivPoke('nextStatement', $elseStatement);
7964 }
7965  
7966 # Multi-line IF..END IF statement
7967 } else {
7968  
7969 # (Any ELSE IF statements are stored in $self->parseDataList)
7970  
7971 # Find the ELSE statement, if there is one
7972 $elseStatement = $self->ivShow('parseDataHash', 'else_statement');
7973 # Find the END IF statement
7974 $endIfStatement = $self->ivShow('parseDataHash', 'end_if_statement');
7975  
7976 # Compile a list of conditions to evaluate, starting with the one in the
7977 # current statement, followed by all the ELSE IF statements
7978 @statementList = ($self, $self->parseDataList);
7979  
7980 # Evaluate each condition, looking for the first one which evaluates to
7981 # 'true'
7982 OUTER: foreach my $statement (@statementList) {
7983  
7984 my $cond = $statement->ivShow('parseDataHash', 'condition');
7985  
7986 if ($cond->evaluate()) {
7987  
7988 $nextStatement = $statement;
7989 last OUTER;
7990 }
7991 }
7992  
7993 if (! $nextStatement && $elseStatement) {
7994  
7995 # The conditions in IF and ELSE IF are all false, but there is an
7996 # ELSE clause, so use it
7997 $nextStatement = $elseStatement;
7998 }
7999  
8000 if (! $nextStatement) {
8001  
8002 # All conditions are false (and there is no ELSE clause), so we need to skip to the
8003 # end of the IF..END IF code block
8004 if (defined $endIfStatement->nextStatement) {
8005  
8006 # LA::Script->nextStatement is currently set to this statement; continue
8007 # execution as if this were the END statement
8008 $self->scriptObj->set_nextStatement($endIfStatement);
8009  
8010 } else {
8011  
8012 $self->scriptObj->set_nextStatement(undef);
8013 $self->scriptObj->set_nextLine($endIfStatement->lineObj->procLineNum + 1);
8014 }
8015  
8016 } else {
8017  
8018 # Add this IF..END IF code block to the main code block stack, since we're going
8019 # to execute it now. The corresponding END IF statement will remove it.
8020 $subObj = $self->scriptObj->returnCurrentSub();
8021 $subObj->push_blockStackList($self);
8022  
8023 if (defined $nextStatement->nextStatement) {
8024  
8025 # LA::Script->nextStatement is currently set to this statement; continue
8026 # execution as if this were the ELSE statement
8027 $self->scriptObj->set_nextStatement($nextStatement);
8028  
8029 } else {
8030  
8031 $self->scriptObj->set_nextStatement(undef);
8032 $self->scriptObj->set_nextLine($nextStatement->lineObj->procLineNum + 1);
8033 }
8034 }
8035 }
8036  
8037 return 1;
8038 }
8039 }
8040  
8041 { package Language::Axbasic::Statement::input;
8042  
8043 use strict;
8044 use warnings;
8045 # use diagnostics;
8046  
8047 use Glib qw(TRUE FALSE);
8048  
8049 @Language::Axbasic::Statement::input::ISA = qw(
8050 Language::Axbasic
8051 Language::Axbasic::Statement
8052 );
8053  
8054 # INPUT [ constant ; ] variable-name [ , variable-name ... ]
8055 # INPUT #channel: variable-name [ , variable-name ... ]
8056  
8057 ##################
8058 # Methods
8059  
8060 sub parse {
8061  
8062 # Called by LA::Line->parse directly after a call to LA::Statement->new
8063 #
8064 # Expected arguments
8065 # (none besides $self)
8066 #
8067 # Return values
8068 # 'undef' on improper arguments or if there is an error
8069 # 1 otherwise
8070  
8071 my ($self, $check) = @_;
8072  
8073 # Local variables
8074 my (
8075 $token, $channel, $promptExp,
8076 @lvalueList,
8077 );
8078  
8079 # Check for improper arguments
8080 if (defined $check) {
8081  
8082 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8083 }
8084  
8085 # First token can be a constant, a file channel or the first of the variable names
8086 $token = $self->tokenGroupObj->lookAhead();
8087 if (! defined $token) {
8088  
8089 return $self->scriptObj->setError(
8090 'syntax_error',
8091 $self->_objClass . '->parse',
8092 );
8093  
8094 # Get the file channel, if specified
8095 } elsif ($token->category eq 'file_channel') {
8096  
8097 $self->tokenGroupObj->shiftToken();
8098  
8099 # For INPUT statements, the file channel must include a colon at the end (e.g. '#5:' )
8100 if (! ($token->tokenText =~ m/\:$/)) {
8101  
8102 return $self->scriptObj->setError(
8103 'syntax_error',
8104 $self->_objClass . '->parse',
8105 );
8106 }
8107  
8108 # Get the channel number
8109 $token->tokenText =~ m/([0-9]+)/;
8110 $channel = $1;
8111  
8112 # True BASIC specifies that the channel must be in the range 1-999; same range used by
8113 # Axbasic
8114 if ($channel < 1 || $channel > 999) {
8115  
8116 return $self->scriptObj->setError(
8117 'file_channel_NUM_out_of_range',
8118 $self->_objClass . '->parse',
8119 'NUM', $channel,
8120 );
8121  
8122 } else {
8123  
8124 # Store the channel number; this also informs $self->implement that we're reading
8125 # from a file, not the user's keyboard
8126 $self->ivAdd('parseDataHash', 'channel', $channel);
8127 }
8128  
8129 # Get the optional prompt text, if specified
8130 } elsif ($token->category eq 'string_constant') {
8131  
8132 # A text prompt was specified - it requires either a following comma or semicolon
8133 $promptExp = Language::Axbasic::Expression::Constant::String->new(
8134 $self->scriptObj,
8135 $self->tokenGroupObj,
8136 );
8137  
8138 if (! defined $self->tokenGroupObj->shiftMatchingToken(';')) {
8139  
8140 return $self->scriptObj->setError(
8141 'missing_separator_after_INPUT_prompt',
8142 $self->_objClass . '->parse',
8143 );
8144 }
8145 }
8146  
8147 # The rest of the arguments are variable names, separated by commas
8148 do {
8149  
8150 my $expression = Language::Axbasic::Expression::Lvalue->new(
8151 $self->scriptObj,
8152 $self->tokenGroupObj,
8153 );
8154  
8155 if (! defined $expression) {
8156  
8157 return $self->scriptObj->setError(
8158 'missing_or_illegal_variable',
8159 $self->_objClass . '->parse',
8160 );
8161  
8162 } else {
8163  
8164 push (@lvalueList, $expression);
8165 }
8166  
8167 } until (! defined $self->tokenGroupObj->shiftMatchingToken(','));
8168  
8169 # Save the components so that $self->implement can retrieve them
8170 $self->ivAdd('parseDataHash', 'prompt_exp', $promptExp);
8171 $self->ivPush('parseDataList', @lvalueList);
8172  
8173 # Parsing complete
8174 return 1;
8175 }
8176  
8177 sub implement {
8178  
8179 # Called by LA::Line->implement directly after a call to $self->parse
8180 #
8181 # Expected arguments
8182 # (none besides $self)
8183 #
8184 # Return values
8185 # 'undef' on improper arguments or if there is an error
8186 # 1 otherwise
8187  
8188 my ($self, $check) = @_;
8189  
8190 # Local variables
8191 my (
8192 $channel, $channelObj, $fileHandle, $promptExp, $prompt, $taskObj,
8193 @lvalueList,
8194 );
8195  
8196 # Check for improper arguments
8197 if (defined $check) {
8198  
8199 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8200 }
8201  
8202 # Retrieve the components stored by $self->parse
8203 $channel = $self->ivShow('parseDataHash', 'channel');
8204 $promptExp = $self->ivShow('parseDataHash', 'prompt_exp');
8205 @lvalueList = $self->parseDataList;
8206  
8207 # Deal with reading from a file, if a file channel was specified
8208 if (defined $channel) {
8209  
8210 # Check that the file channel exists
8211 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
8212  
8213 return $self->scriptObj->setError(
8214 'file_channel_NUM_not_open',
8215 $self->_objClass . '->implement',
8216 'NUM', $channel,
8217 );
8218  
8219 } else {
8220  
8221 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
8222 $fileHandle = $channelObj->fileHandle;
8223 }
8224  
8225 # Check that reading from the file channel is allowed
8226 if ($channelObj->accessType eq 'output') {
8227  
8228 return $self->scriptObj->setError(
8229 'file_channel_NUM_is_write_only',
8230 $self->_objClass . '->implement',
8231 'NUM', $channel,
8232 );
8233 }
8234  
8235 # Check that the pointer hasn't already reached end-of-file
8236 if (eof($fileHandle)) {
8237  
8238 return $self->scriptObj->setError(
8239 'end_of_file_on_channel_NUM',
8240 $self->_objClass . '->implement',
8241 'NUM', $channel,
8242 );
8243 }
8244  
8245 # Read a file line for each value expected
8246 for (my $count = 0; $count < scalar @lvalueList; $count++) {
8247  
8248 my ($lvalue, $varObj, $line);
8249  
8250 $lvalue = $lvalueList[$count];
8251 $varObj = $lvalue->variable;
8252 if (! $varObj) {
8253  
8254 # Subscript out of bounds, or similar error, has already been set
8255 return undef;
8256 }
8257  
8258 # Read a line from the file
8259 $line = <$fileHandle>;
8260 chomp $line;
8261  
8262 if (! defined $line) {
8263  
8264 return $self->scriptObj->setError(
8265 'end_of_file_on_channel_NUM',
8266 $self->_objClass . '->implement',
8267 'NUM', $channel,
8268 );
8269  
8270 } else {
8271  
8272 # Set the variable
8273 if ($line) {
8274  
8275 $varObj->set($line);
8276  
8277 } else {
8278  
8279 if (ref($varObj) =~ m/Numeric/) {
8280 $varObj->set(0);
8281 } else {
8282 $varObj->set('');
8283 }
8284 }
8285 }
8286 }
8287  
8288 } else {
8289  
8290 # Otherwise, we're reading from the user's keyboard. Evaluate the prompt expression (if
8291 # there is one)
8292 if ($promptExp) {
8293  
8294 $prompt = $promptExp->evaluate();
8295 }
8296  
8297 # Import the parent task (if any)
8298 $taskObj = $self->scriptObj->parentTask;
8299  
8300 # If the task window is open and an entry box is available, use that window to get the
8301 # input. Otherwise, open 'dialogue' windows to get the input
8302 if ($taskObj && $taskObj->taskWinEntryFlag) {
8303  
8304 # Display the prompt text, if it exists; if it doesn't, we must still display a
8305 # question mark, because many BASIC scripts use a format like
8306 # 10 print "tell me";
8307 # 20 input a$
8308 # ...which forces Axmud to display unrelated text on the same line as the prompt
8309 if ($prompt) {
8310 $taskObj->insertPrint($prompt . '? ');
8311 } else {
8312 $taskObj->insertPrint('? ');
8313 }
8314  
8315 # Tell the script object how many lines of input to expect
8316 $self->scriptObj->set_inputList(@lvalueList);
8317  
8318 # Mark this script as 'waiting for INPUT' - it will be resumed automatically when
8319 # the user types in the task window's entry box
8320 $self->scriptObj->set_scriptStatus('wait_input');
8321  
8322 } else {
8323  
8324 # Display the prompt text, if it exists; if it doesn't, we must still display a
8325 # question mark, because many BASIC scripts use a format like
8326 # 10 print "tell me";
8327 # 20 input a$
8328 # ...which forces Axmud to display unrelated text on the same line as the prompt
8329 # NB The prompt is displayed both in the dialogue box, and also in the 'main' or
8330 # task window
8331 if ($taskObj && $taskObj->taskWinFlag) {
8332  
8333 if ($prompt) {
8334 $taskObj->insertPrint($prompt . '? ');
8335 } else {
8336 $taskObj->insertPrint('? ');
8337 }
8338  
8339 } else {
8340  
8341 if ($prompt) {
8342 $self->scriptObj->session->writeText($prompt . '? ', 'echo');
8343 } else {
8344 $self->scriptObj->session->writeText('? ', 'echo');
8345 }
8346 }
8347  
8348 # Use dialogue boxes - one for each value expected
8349 for (my $count = 0; $count < scalar @lvalueList; $count++) {
8350  
8351 my ($lvalue, $varObj, $msg, $result);
8352  
8353 $lvalue = $lvalueList[$count];
8354 $varObj = $lvalue->variable;
8355 if (! $varObj) {
8356  
8357 # Subscript out of bounds, or similar error, has already been set
8358 return undef;
8359 }
8360  
8361 if ($prompt) {
8362 $msg = $prompt . '?';
8363 } else {
8364 $msg = 'Value?';
8365 }
8366  
8367 if (scalar @lvalueList > 1) {
8368  
8369 $msg .= ' (' . ($count + 1) . '/' . scalar @lvalueList . ')';
8370 }
8371  
8372 # Open a 'dialogue' window to allow the user to input a value
8373 $result = $self->scriptObj->session->mainWin->showEntryDialogue(
8374 'Axbasic INPUT (' . $self->scriptObj->name . ')',
8375 $msg,
8376 );
8377  
8378 if (! defined $result) {
8379  
8380 # User clicked 'cancel' or closed the window
8381 if (! $taskObj || ! $taskObj->taskWinFlag) {
8382  
8383 $self->scriptObj->session->writeText(' '); # Cancel the earlier 'echo'
8384 }
8385  
8386 return $self->scriptObj->setError(
8387 'user_declined_input_error',
8388 $self->_objClass . '->implement',
8389 );
8390  
8391 } elsif ($result) {
8392  
8393 # Set the variable
8394 $varObj->set($result);
8395  
8396 # Also display it in the 'main' / task window
8397 if ($taskObj && $taskObj->taskWinFlag) {
8398 $taskObj->insertPrint($result, 'echo');
8399 } else {
8400 $self->scriptObj->session->writeText($result);
8401 }
8402  
8403 } else {
8404  
8405 # No value entered, so use a null value
8406 if (ref($varObj) =~ m/Numeric/) {
8407 $varObj->set(0);
8408 } else {
8409 $varObj->set('');
8410 }
8411  
8412 # Cancel the earlier 'echo' in the 'main' window
8413 if (! $taskObj || ! $taskObj->taskWinFlag) {
8414  
8415 $self->scriptObj->session->writeText(' ');
8416 }
8417 }
8418 }
8419 }
8420 }
8421  
8422 # Implementation complete
8423 return 1;
8424 }
8425 }
8426  
8427 { package Language::Axbasic::Statement::let;
8428  
8429 use strict;
8430 use warnings;
8431 # use diagnostics;
8432  
8433 use Glib qw(TRUE FALSE);
8434  
8435 @Language::Axbasic::Statement::let::ISA = qw(
8436 Language::Axbasic
8437 Language::Axbasic::Statement
8438 );
8439  
8440 # [LET] variable-name = expression
8441 # [LET] variable-name = CALL subroutine-name
8442 # [LET] variable-name = CALL subroutine-name ( [ expression [ , expression ... ] ] )
8443 # [LET] variable-name = DIMENSIONS array-variable
8444 # [LET] variable-name = LOWER array-variable
8445 # [LET] variable-name = SIZE array-variable
8446 # [LET] variable-name = UPPER array-variable
8447  
8448 ##################
8449 # Methods
8450  
8451 sub parse {
8452  
8453 # Called by LA::Line->parse directly after a call to LA::Statement->new when the first token
8454 # in the statement is the keyword 'let', or when the first token in the statement isn't a
8455 # keyword (which is an implied 'let')
8456 #
8457 # Expected arguments
8458 # (none besides $self)
8459 #
8460 # Return values
8461 # 'undef' on improper arguments or if there is an error
8462 # 1 otherwise
8463  
8464 my ($self, $check) = @_;
8465  
8466 # Local variables
8467 my ($lvalue, $token, $subNameToken, $argListObj, $arrayExp, $scalarExp);
8468  
8469 # Check for improper arguments
8470 if (defined $check) {
8471  
8472 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8473 }
8474  
8475 # Get the variable name
8476 $lvalue = Language::Axbasic::Expression::Lvalue->new(
8477 $self->scriptObj,
8478 $self->tokenGroupObj,
8479 );
8480  
8481 if (! defined $lvalue) {
8482  
8483 return $self->scriptObj->setError(
8484 'missing_or_illegal_variable',
8485 $self->_objClass . '->parse',
8486 );
8487 }
8488  
8489 # Extract the assignment operator
8490 $token = $self->tokenGroupObj->shiftTokenIfCategory('assignment_operator');
8491 if (! defined $token) {
8492  
8493 return $self->scriptObj->setError(
8494 'syntax_error',
8495 $self->_objClass . '->parse',
8496 );
8497 }
8498  
8499 # The rest of the statement is either:
8500 # 1. A subroutine call as a CALL statement, the return value of which should be assigned
8501 # to the scalar variable
8502 # 2. The keywords DIMENSIONS, LOWER, SIZE or UPPER followed by an array variable; the
8503 # value is assigned to the scalar variable (only DIMENSIONS can be used with
8504 # multi-dimensional arrays)
8505 # 3. A scalar expression, the value of which should be assigned to the variable
8506 $token = $self->tokenGroupObj->lookAhead();
8507 if (! defined $token) {
8508  
8509 return $self->scriptObj->setError(
8510 'syntax_error',
8511 $self->_objClass . '->parse',
8512 );
8513 }
8514  
8515 if ($token->tokenText eq 'call') {
8516  
8517 # Eat the 'call' token
8518 $token = $self->tokenGroupObj->shiftToken();
8519  
8520 # Process the subroutine call using code from the CALL statement
8521 Language::Axbasic::Statement::call->parse($self);
8522  
8523 # Save the variable object. LA::Statement::call->implement will use it
8524 $self->ivAdd('parseDataHash', 'call_var', $lvalue->varObj);
8525  
8526 } elsif (
8527 $token->tokenText eq 'dimensions'
8528 || $token->tokenText eq 'lower'
8529 || $token->tokenText eq 'size'
8530 || $token->tokenText eq 'upper'
8531 ) {
8532 # Eat the keyword token
8533 $token = $self->tokenGroupObj->shiftToken();
8534  
8535 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
8536 # LA::Variable->lookup that we're intentionally referring to an array variable, such
8537 # as that created by
8538 # DIM var (10)
8539 # ...by a variable name that looks like a scalar, i.e.
8540 # SORT var
8541 $self->scriptObj->set_declareMode('simple');
8542  
8543 # Get the variable name
8544 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
8545 $self->scriptObj,
8546 $self->tokenGroupObj,
8547 );
8548  
8549 if (! defined $arrayExp) {
8550  
8551 return $self->scriptObj->setError(
8552 'missing_or_illegal_variable',
8553 $self->_objClass . '->parse',
8554 );
8555 }
8556  
8557 # Reset the temporary IV
8558 $self->scriptObj->set_declareMode('default');
8559  
8560 # Save the scalar variable and the array expression so $self->implement can use them,
8561 # if it is called
8562 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
8563 if ($token->tokenText eq 'dimensions') {
8564 $self->ivAdd('parseDataHash', 'dims_exp', $arrayExp);
8565 } elsif ($token->tokenText eq 'lower') {
8566 $self->ivAdd('parseDataHash', 'lower_exp', $arrayExp);
8567 } elsif ($token->tokenText eq 'size') {
8568 $self->ivAdd('parseDataHash', 'size_exp', $arrayExp);
8569 } else {
8570 $self->ivAdd('parseDataHash', 'upper_exp', $arrayExp);
8571 }
8572  
8573 } else {
8574  
8575 $scalarExp = Language::Axbasic::Expression::Arithmetic->new(
8576 $self->scriptObj,
8577 $self->tokenGroupObj,
8578 );
8579  
8580 if (! defined $scalarExp) {
8581  
8582 return $self->scriptObj->setError(
8583 'missing_or_illegal_expression',
8584 $self->_objClass . '->parse',
8585 );
8586 }
8587  
8588 # Save the variable and the scalar expression so $self->implement can use them, if it
8589 # is called
8590 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
8591 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
8592 }
8593  
8594 # Parsing complete
8595 return 1;
8596 }
8597  
8598 sub implement {
8599  
8600 # Called by LA::Line->implement directly after a call to $self->parse
8601 #
8602 # Expected arguments
8603 # (none besides $self)
8604 #
8605 # Return values
8606 # 'undef' on improper arguments or if there is an error
8607 # 1 otherwise
8608  
8609 my ($self, $check) = @_;
8610  
8611 # Local variables
8612 my ($lvalue, $assignVar, $arrayExp, $scalarExp, $value);
8613  
8614 # Check for improper arguments
8615 if (defined $check) {
8616  
8617 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8618 }
8619  
8620 # LET var$ = CALL subname
8621 # LET var$ = CALL subname (arglist)
8622 if ($self->ivExists('parseDataHash', 'call_var')) {
8623  
8624 # Process the subroutine call using code from the CALL statement
8625 Language::Axbasic::Statement::call->implement($self);
8626  
8627 # LET var$ = DIMENSIONS arrayname
8628 # LET var$ = LOWER arrayname
8629 # LET var$ = SIZE arrayname
8630 # LET var$ = UPPER arrayname
8631 # LET var$ = expression
8632 } else {
8633  
8634 # Get the assignment variable stored by $self->parse
8635 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
8636  
8637 $assignVar = $lvalue->variable;
8638 if (! defined $assignVar) {
8639  
8640 # Subscript out of bounds, or similar error, has already been set
8641 return undef;
8642 }
8643  
8644 # LET var$ = DIMENSIONS arrayname
8645 if ($self->ivExists('parseDataHash', 'dims_exp')) {
8646  
8647 # Get the other value stored by $self->parse
8648 $arrayExp = $self->ivShow('parseDataHash', 'dims_exp');
8649 # Set the variable's value
8650 $assignVar->set($arrayExp->varObj->dimCount);
8651  
8652 # LET var$ = LOWER arrayname
8653 } elsif ($self->ivExists('parseDataHash', 'lower_exp')) {
8654  
8655 # Get the other value stored by $self->parse
8656 $arrayExp = $self->ivShow('parseDataHash', 'lower_exp');
8657  
8658 if ($arrayExp->varObj->dimCount > 1) {
8659  
8660 return $self->scriptObj->setError(
8661 'LOWER_cannot_operate_on_multi-dimensional_array',
8662 $self->_objClass . '->implement',
8663 );
8664  
8665 } else {
8666  
8667 # Set the variable's value
8668 $assignVar->set($arrayExp->varObj->ivIndex('cellList', 0));
8669 }
8670  
8671 # LET var$ = SIZE arrayname
8672 } elsif ($self->ivExists('parseDataHash', 'size_exp')) {
8673  
8674 # Get the other value stored by $self->parse
8675 $arrayExp = $self->ivShow('parseDataHash', 'size_exp');
8676  
8677 if ($arrayExp->varObj->dimCount > 1) {
8678  
8679 return $self->scriptObj->setError(
8680 'SIZE_cannot_operate_on_multi-dimensional_array',
8681 $self->_objClass . '->implement',
8682 );
8683  
8684 } else {
8685  
8686 # Set the variable's value, taking account of the first item in ->cellList,
8687 # which is the lower bound
8688 $assignVar->set((scalar ($arrayExp->varObj->cellList)) - 1);
8689 }
8690  
8691 # LET var$ = UPPER arrayname
8692 } elsif ($self->ivExists('parseDataHash', 'upper_exp')) {
8693  
8694 # Get the other value stored by $self->parse
8695 $arrayExp = $self->ivShow('parseDataHash', 'upper_exp');
8696  
8697 if ($arrayExp->varObj->dimCount > 1) {
8698  
8699 return $self->scriptObj->setError(
8700 'UPPER_cannot_operate_on_multi-dimensional_array',
8701 $self->_objClass . '->implement',
8702 );
8703  
8704 } else {
8705  
8706 # Set the variable's value, taking account of the first item in ->cellList,
8707 # which is the lower bound
8708 $assignVar->set(
8709 $arrayExp->varObj->ivIndex('cellList', 0)
8710 + (scalar ($arrayExp->varObj->cellList)) - 2
8711 );
8712 }
8713  
8714 # LET var$ = expression
8715 } else {
8716  
8717 # Get the other value stored by $self->parse
8718 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
8719 # Set the variable's value
8720 $value = $scalarExp->evaluate();
8721 $assignVar->set($value);
8722 }
8723 }
8724  
8725 # Implementation complete
8726 return 1;
8727 }
8728 }
8729  
8730 { package Language::Axbasic::Statement::local;
8731  
8732 use strict;
8733 use warnings;
8734 # use diagnostics;
8735  
8736 use Glib qw(TRUE FALSE);
8737  
8738 @Language::Axbasic::Statement::local::ISA = qw(
8739 Language::Axbasic
8740 Language::Axbasic::Statement
8741 );
8742  
8743 # LOCAL variable-name [ , variable-name ... ]
8744  
8745 ##################
8746 # Methods
8747  
8748 sub parse {
8749  
8750 # Called by LA::Line->parse directly after a call to LA::Statement->new
8751 #
8752 # Expected arguments
8753 # (none besides $self)
8754 #
8755 # Return values
8756 # 'undef' on improper arguments or if there is an error
8757 # 1 otherwise
8758  
8759 my ($self, $check) = @_;
8760  
8761 # Local variables
8762 my ($token, $argListObj);
8763  
8764 # Check for improper arguments
8765 if (defined $check) {
8766  
8767 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8768 }
8769  
8770 # The 'local' keyword is not available in primitive numbering mode
8771 if ($self->scriptObj->executionMode ne 'no_line_num') {
8772  
8773 return $self->scriptObj->setError(
8774 'statement_not_available_with_line_numbers',
8775 $self->_objClass . '->parse',
8776 );
8777 }
8778  
8779 # Temporarily set the IV that allows undeclared variables to be created
8780 $self->scriptObj->set_declareMode('local_scalar');
8781  
8782 # Process each array in turn (if several appear on the same line, they are separated by
8783 # commas)
8784 do {
8785  
8786 my $lvalue = Language::Axbasic::Expression::Lvalue->new(
8787 $self->scriptObj,
8788 $self->tokenGroupObj,
8789 );
8790  
8791 if (! defined $lvalue) {
8792  
8793 return $self->scriptObj->setError(
8794 'missing_or_illegal_variable',
8795 $self->_objClass . '->parse',
8796 );
8797 }
8798  
8799 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
8800  
8801 # Reset the temporary IV
8802 $self->scriptObj->set_declareMode('default');
8803  
8804 # Check there is nothing else (except for the statement separator, :)
8805 if (! defined $self->tokenGroupObj->testStatementEnd()) {
8806  
8807 return $self->scriptObj->setError(
8808 'unexpected_keywords,_operators_or_expressions',
8809 $self->_objClass . '->parse',
8810 );
8811 }
8812  
8813 # Save the arglist so that ->implement can add all these variables to the global variable
8814 # hash, when the line is executed
8815 $self->ivAdd('parseDataHash', 'arg_list_obj', $argListObj);
8816  
8817 # Parsing complete
8818 return 1;
8819 }
8820  
8821 # sub implement {} # No ->implement method - LA::Variable->lookup has already added the
8822 # variable to LA::Subroutine->localScalarHash or ->localArrayHash
8823 }
8824  
8825 { package Language::Axbasic::Statement::login;
8826  
8827 use strict;
8828 use warnings;
8829 # use diagnostics;
8830  
8831 use Glib qw(TRUE FALSE);
8832  
8833 @Language::Axbasic::Statement::login::ISA = qw(
8834 Language::Axbasic
8835 Language::Axbasic::Statement
8836 );
8837  
8838 # LOGIN
8839  
8840 ##################
8841 # Methods
8842  
8843 sub parse {
8844  
8845 # Called by LA::Line->parse directly after a call to LA::Statement->new
8846 #
8847 # Expected arguments
8848 # (none besides $self)
8849  
8850 # Return values
8851 # 'undef' on improper arguments or if there is an error
8852 # 1 otherwise
8853  
8854 my ($self, $check) = @_;
8855  
8856 # Check for improper arguments
8857 if (defined $check) {
8858  
8859 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8860 }
8861  
8862 # LOGIN statements always appear on their own
8863 if (! $self->tokenGroupObj->testStatementEnd()) {
8864  
8865 return $self->scriptObj->setError(
8866 'unexpected_keywords,_operators_or_expressions',
8867 $self->_objClass . '->parse',
8868 );
8869 }
8870  
8871 # Parsing complete
8872 return 1;
8873 }
8874  
8875 sub implement {
8876  
8877 # Called by LA::Line->implement directly after a call to $self->parse
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 # Check for improper arguments
8889 if (defined $check) {
8890  
8891 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
8892 }
8893  
8894 # Tell the GA::Session that the automatic login is complete (if the character is already
8895 # marked as 'logged in', nothing happens
8896 $self->scriptObj->session->doLogin();
8897  
8898 # Implementation complete
8899 return 1;
8900 }
8901 }
8902  
8903 { package Language::Axbasic::Statement::loop;
8904  
8905 use strict;
8906 use warnings;
8907 # use diagnostics;
8908  
8909 use Glib qw(TRUE FALSE);
8910  
8911 @Language::Axbasic::Statement::loop::ISA = qw(
8912 Language::Axbasic
8913 Language::Axbasic::Statement
8914 );
8915  
8916 # LOOP
8917  
8918 ##################
8919 # Methods
8920  
8921 sub parse {
8922  
8923 # Called by LA::Line->parse directly after a call to LA::Statement->new
8924 #
8925 # Expected arguments
8926 # (none besides $self)
8927 #
8928 # Return values
8929 # 'undef' on improper arguments or if there is an error
8930 # 1 otherwise
8931  
8932 my ($self, $check) = @_;
8933  
8934 # Local variables
8935 my ($subObj, $whileStatement);
8936  
8937 # Check for improper arguments
8938 if (defined $check) {
8939  
8940 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
8941 }
8942  
8943 # The 'loop' keyword is not available in primitive numbering mode
8944 if ($self->scriptObj->executionMode ne 'no_line_num') {
8945  
8946 return $self->scriptObj->setError(
8947 'statement_not_available_with_line_numbers',
8948 $self->_objClass . '->parse',
8949 );
8950 }
8951  
8952 # LOOP statements always appear on their own
8953 if (! $self->tokenGroupObj->testStatementEnd()) {
8954  
8955 return $self->scriptObj->setError(
8956 'unexpected_keywords,_operators_or_expressions',
8957 $self->_objClass . '->parse',
8958 );
8959 }
8960  
8961 # Find the matching WHILE statement, which should already have been parsed
8962 $subObj = $self->scriptObj->returnCurrentSub();
8963 if (! $subObj->whileStackList) {
8964  
8965 return $self->scriptObj->setError(
8966 'LOOP_statement_without_matching_WHILE',
8967 $self->_objClass . '->parse',
8968 );
8969  
8970 } else {
8971  
8972 $whileStatement = $subObj->pop_whileStackList();
8973  
8974 # Tell the WHILE statement's ->implement what its matching LOOP statement (i.e. this
8975 # one) is
8976 $whileStatement->add_parseDataHash('loop_statement', $self);
8977 # Store the WHILE statement so this statement's ->implement can use it
8978 $self->ivAdd('parseDataHash', 'while_statement', $whileStatement);
8979 }
8980  
8981 # Parsing complete
8982 return 1;
8983 }
8984  
8985 sub implement {
8986  
8987 # Called by LA::Line->implement directly after a call to $self->parse
8988 #
8989 # Expected arguments
8990 # (none besides $self)
8991 #
8992 # Return values
8993 # 'undef' on improper arguments or if there is an error
8994 # 1 otherwise
8995  
8996 my ($self, $check) = @_;
8997  
8998 # Local variables
8999 my ($subObj, $whileStatement);
9000  
9001 # Check for improper arguments
9002 if (defined $check) {
9003  
9004 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9005 }
9006  
9007 # Remove this code block from the standard code block stack. (The WHILE statement puts it
9008 # straight back, if the code block is to be executed again.)
9009 $subObj = $self->scriptObj->returnCurrentSub();
9010 if (! $subObj->blockStackList) {
9011  
9012 return $self->scriptObj->setError(
9013 'LOOP_statement_without_matching_WHILE',
9014 $self->_objClass . '->implement',
9015 );
9016 }
9017  
9018 $whileStatement = $subObj->pop_blockStackList();
9019  
9020 # The statement at the top of the stack must be a WHILE statement, not another kind of code
9021 # block
9022 if ($whileStatement->keyword ne 'while') {
9023  
9024 return $self->scriptObj->setError(
9025 'LOOP_statement_without_matching_WHILE',
9026 $self->_objClass . '->implement',
9027 );
9028 }
9029  
9030 # Nothing records a statement's previous statement on the same line (if any), so just
9031 # re-implement the WHILE statement, as if it had been called directly from
9032 # LA::Script->implement
9033 $self->scriptObj->set_nextStatement($whileStatement);
9034 return $whileStatement->implement();
9035 }
9036 }
9037  
9038 { package Language::Axbasic::Statement::move;
9039  
9040 use strict;
9041 use warnings;
9042 # use diagnostics;
9043  
9044 use Glib qw(TRUE FALSE);
9045  
9046 @Language::Axbasic::Statement::move::ISA = qw(
9047 Language::Axbasic
9048 Language::Axbasic::Statement
9049 );
9050  
9051 # MOVE expression
9052  
9053 ##################
9054 # Methods
9055  
9056 sub parse {
9057  
9058 # Called by LA::Line->parse directly after a call to LA::Statement->new
9059 #
9060 # Expected arguments
9061 # (none besides $self)
9062 #
9063 # Return values
9064 # 'undef' on improper arguments or if there is an error
9065 # 1 otherwise
9066  
9067 my ($self, $check) = @_;
9068  
9069 # Local variables
9070 my $expression;
9071  
9072 # Check for improper arguments
9073 if (defined $check) {
9074  
9075 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9076 }
9077  
9078 # Get the expression and store it for ->implement to use
9079 $expression = Language::Axbasic::Expression::Arithmetic->new(
9080 $self->scriptObj,
9081 $self->tokenGroupObj,
9082 );
9083  
9084 if (! defined $expression) {
9085  
9086 return $self->scriptObj->setError(
9087 'missing_or_illegal_expression',
9088 $self->_objClass . '->parse',
9089 );
9090  
9091 } else {
9092  
9093 $self->ivAdd('parseDataHash', 'expression', $expression);
9094 }
9095  
9096 # There should be nothing after the expression
9097 if (! $self->tokenGroupObj->testStatementEnd()) {
9098  
9099 return $self->scriptObj->setError(
9100 'unexpected_keywords,_operators_or_expressions',
9101 $self->_objClass . '->parse',
9102 );
9103 }
9104  
9105 # Parsing complete
9106 return 1;
9107 }
9108  
9109 sub implement {
9110  
9111 # Called by LA::Line->implement directly after a call to $self->parse
9112 #
9113 # Expected arguments
9114 # (none besides $self)
9115 #
9116 # Return values
9117 # 'undef' on improper arguments or if there is an error
9118 # 1 otherwise
9119  
9120 my ($self, $check) = @_;
9121  
9122 # Local variables
9123 my ($expression, $cmd);
9124  
9125 # Check for improper arguments
9126 if (defined $check) {
9127  
9128 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9129 }
9130  
9131 # Retrieve the expression to be played
9132 $expression = $self->ivShow('parseDataHash', 'expression');
9133 # Evaluate the expression to get a world command
9134 $cmd = $expression->evaluate();
9135  
9136 # Send the command to the world
9137 $self->scriptObj->session->moveCmd($cmd);
9138  
9139 # Implementation complete
9140 return 1;
9141 }
9142 }
9143  
9144 { package Language::Axbasic::Statement::multi;
9145  
9146 use strict;
9147 use warnings;
9148 # use diagnostics;
9149  
9150 use Glib qw(TRUE FALSE);
9151  
9152 @Language::Axbasic::Statement::multi::ISA = qw(
9153 Language::Axbasic
9154 Language::Axbasic::Statement
9155 );
9156  
9157 # MULTI expression
9158  
9159 ##################
9160 # Methods
9161  
9162 sub parse {
9163  
9164 # Called by LA::Line->parse directly after a call to LA::Statement->new
9165 #
9166 # Expected arguments
9167 # (none besides $self)
9168 #
9169 # Return values
9170 # 'undef' on improper arguments or if there is an error
9171 # 1 otherwise
9172  
9173 my ($self, $check) = @_;
9174  
9175 # Local variables
9176 my $expression;
9177  
9178 # Check for improper arguments
9179 if (defined $check) {
9180  
9181 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9182 }
9183  
9184 # Get the expression and store it for ->implement to use
9185 $expression = Language::Axbasic::Expression::Arithmetic->new(
9186 $self->scriptObj,
9187 $self->tokenGroupObj,
9188 );
9189  
9190 if (! defined $expression) {
9191  
9192 return $self->scriptObj->setError(
9193 'missing_or_illegal_expression',
9194 $self->_objClass . '->parse',
9195 );
9196  
9197 } else {
9198  
9199 $self->ivAdd('parseDataHash', 'expression', $expression);
9200 }
9201  
9202 # There should be nothing after the expression
9203 if (! $self->tokenGroupObj->testStatementEnd()) {
9204  
9205 return $self->scriptObj->setError(
9206 'unexpected_keywords,_operators_or_expressions',
9207 $self->_objClass . '->parse',
9208 );
9209 }
9210  
9211 # Parsing complete
9212 return 1;
9213 }
9214  
9215 sub implement {
9216  
9217 # Called by LA::Line->implement directly after a call to $self->parse
9218 #
9219 # Expected arguments
9220 # (none besides $self)
9221 #
9222 # Return values
9223 # 'undef' on improper arguments or if there is an error
9224 # 1 otherwise
9225  
9226 my ($self, $check) = @_;
9227  
9228 # Local variables
9229 my ($expression, $string);
9230  
9231 # Check for improper arguments
9232 if (defined $check) {
9233  
9234 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9235 }
9236  
9237 # Retrieve the expression to be written
9238 $expression = $self->ivShow('parseDataHash', 'expression');
9239 # Evaluate the expression to get a scalar value
9240 $string = $expression->evaluate();
9241  
9242 # Execute the expression as a multi command
9243 $self->scriptObj->session->multiCmd($string);
9244  
9245 # Implementation complete
9246 return 1;
9247 }
9248 }
9249  
9250 { package Language::Axbasic::Statement::next;
9251  
9252 use strict;
9253 use warnings;
9254 # use diagnostics;
9255  
9256 use Glib qw(TRUE FALSE);
9257  
9258 @Language::Axbasic::Statement::next::ISA = qw(
9259 Language::Axbasic
9260 Language::Axbasic::Statement
9261 );
9262  
9263 # NEXT variable-name
9264  
9265 ##################
9266 # Methods
9267  
9268 sub parse {
9269  
9270 # Called by LA::Line->parse directly after a call to LA::Statement->new
9271 #
9272 # Expected arguments
9273 # (none besides $self)
9274 #
9275 # Return values
9276 # 'undef' on improper arguments or if there is an error
9277 # 1 otherwise
9278  
9279 my ($self, $check) = @_;
9280  
9281 # Local variables
9282 my $lvalue;
9283  
9284 # Check for improper arguments
9285 if (defined $check) {
9286  
9287 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9288 }
9289  
9290 # Read the iterator variable name
9291 $lvalue = Language::Axbasic::Expression::Lvalue->new(
9292 $self->scriptObj,
9293 $self->tokenGroupObj,
9294 );
9295  
9296 if (! defined $lvalue) {
9297  
9298 return $self->scriptObj->setError(
9299 'missing_or_illegal_iterator',
9300 $self->_objClass . '->parse',
9301 );
9302  
9303 # v1.2.120 Removed for FOR EACH statements
9304 # } elsif ($lvalue->isa('Language::Axbasic::Expression::String')) {
9305 #
9306 # return $self->scriptObj->setError(
9307 # 'missing_or_illegal_iterator',
9308 # $self->_objClass . '->parse',
9309 # );
9310  
9311 } else {
9312  
9313 # Store the iterator, so $self->implement can retrieve it
9314 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
9315 }
9316  
9317 # Check there's nothing else in the statement after the iterator
9318 if (! $self->tokenGroupObj->testStatementEnd()) {
9319  
9320 return $self->scriptObj->setError(
9321 'unexpected_keywords,_operators_or_expressions',
9322 $self->_objClass . '->parse',
9323 );
9324 }
9325  
9326 # Parsing complete
9327 return 1;
9328 }
9329  
9330 sub implement {
9331  
9332 # Called by LA::Line->implement directly after a call to $self->parse
9333 #
9334 # Expected arguments
9335 # (none besides $self)
9336 #
9337 # Return values
9338 # 'undef' on improper arguments or if there is an error
9339 # 1 otherwise
9340  
9341 my ($self, $check) = @_;
9342  
9343 # Local variables
9344 my (
9345 $lvalue, $subObj, $forStatement, $exitFlag, $forEachFlag, $forTermExp, $forStepExp,
9346 $forArrayExp, $forArrayIndex, $term, $step, $var, $value, $iterVar, $elementVar,
9347 $loopFlag, $indexListRef, $dim, $termFlag,
9348 );
9349  
9350 # Check for improper arguments
9351 if (defined $check) {
9352  
9353 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9354 }
9355  
9356 # Retrieve the iterator stored by $self->parse
9357 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
9358  
9359 # Get the corresponding FOR statement from the current subroutine's code block stack. Keep
9360 # removing code blocks from the top of the stack until we get the right one
9361 $subObj = $self->scriptObj->returnCurrentSub();
9362 if (! $subObj->blockStackList) {
9363  
9364 return $self->scriptObj->setError(
9365 'NEXT_statement_without_matching_FOR',
9366 $self->_objClass . '->implement',
9367 );
9368 }
9369  
9370 do {
9371  
9372 $forStatement = $subObj->pop_blockStackList();
9373  
9374 # Check that it's a FOR statement - not the start of another kind of code block - and
9375 # that it's the right iterator
9376 if (
9377 $forStatement->keyword eq 'for'
9378 && $forStatement->ivShow('parseDataHash', 'lvalue')->varObj eq $lvalue->varObj
9379 ) {
9380 # We've found the statement we're looking for
9381 $exitFlag = TRUE;
9382 }
9383  
9384 } until ($exitFlag || ! $subObj->blockStackList);
9385  
9386 if (! $exitFlag) {
9387  
9388 return $self->scriptObj->setError(
9389 'NEXT_statement_without_matching_FOR',
9390 $self->_objClass . '->implement',
9391 );
9392 }
9393  
9394 # Import the stored data from the matching FOR statement
9395 $forEachFlag = $forStatement->ivShow('parseDataHash', 'each_flag');
9396 $forTermExp = $forStatement->ivShow('parseDataHash', 'term_exp');
9397 $forStepExp = $forStatement->ivShow('parseDataHash', 'step_exp');
9398 $forArrayExp = $forStatement->ivShow('parseDataHash', 'array_exp');
9399  
9400 # There are two formats for a FOR statement
9401 if (! $forEachFlag) {
9402  
9403 # First type: FOR variable-name = expression TO expression [ STEP expression ]
9404  
9405 # Evaluate the termination and step expressions. Store them so that, during a FOR..NEXT
9406 # loop, we only have to evaluate the expressions once
9407 if (! $self->ivExists('parseDataHash', 'term_value')) {
9408  
9409 $term = $forTermExp->evaluate();
9410 $step = $forStepExp->evaluate();
9411  
9412 $self->ivAdd('parseDataHash', 'term_value', $term);
9413 $self->ivAdd('parseDataHash', 'step_value', $step);
9414  
9415 } else {
9416  
9417 $term = $self->ivShow('parseDataHash', 'term_value');
9418 $step = $self->ivShow('parseDataHash', 'step_value');
9419 }
9420  
9421 # Increment the iterator variable
9422 $var = $lvalue->variable;
9423 $value = $var->value;
9424 $value += $step;
9425 $var->set($value);
9426  
9427 # Termination test
9428 if (($step > 0 && $value <= $term) || ($step < 0 && $value >= $term)) {
9429  
9430 # Perform another iteration of the loop
9431 $loopFlag = TRUE;
9432 }
9433  
9434 } else {
9435  
9436 # Second type: FOR EACH variable-name IN variable-name
9437  
9438 # On the next FOR loop, we will use the next element in the sequence
9439 $indexListRef = $forStatement->ivShow('parseDataHash', 'index_list_ref');
9440 # The array variable might be multi-dimensional, in which case we have multiple indexes,
9441 # one for each dimension. Increment the index(es) from the bottom up
9442 # e.g. For a 3x3 array, [1, 1], then [1, 2], [1, 3], [2, 1], [2, 2]...
9443 # Check each dimension in turn, starting with the last one
9444 $dim = scalar @$indexListRef;
9445 $exitFlag = FALSE;
9446  
9447 OUTER: do {
9448  
9449 $dim--;
9450  
9451 # Increment the index
9452 # e.g. In a 3x3 array, on the first spin of this loop, $dim is 2, and [1, 1]
9453 # becomes [1, 2]
9454 $$indexListRef[$dim] = $$indexListRef[$dim] + 1;
9455 # But on a later spin, [1, 3] becomes [1, 4], which does not exist in the array.
9456 # In that case, [1, 3] becomes [2, 1]
9457 my $cellVar = $forArrayExp->varObj->testCell(@$indexListRef);
9458  
9459 if (defined $cellVar) {
9460  
9461 # The cell now described by $indexListRef is valid, so we can proceed with the
9462 # next iteration of the FOR EACH loop
9463 $exitFlag = TRUE;
9464  
9465 } else {
9466  
9467 # The cell now described by $indexListRef is not valid
9468 if (! $dim) {
9469  
9470 # At the end of the array (e.g. [3, 3] ), so terminate the FOR EACH loop
9471 $termFlag = TRUE;
9472 $exitFlag = TRUE;
9473  
9474 } else {
9475  
9476 # Increment the indices, e.g. [1, 3] becomes [2, 1]
9477 $$indexListRef[$dim] = 1;
9478 }
9479 }
9480  
9481 } until ($exitFlag || ! $dim);
9482  
9483 # Termination test
9484 if (! $termFlag) {
9485  
9486 # Update the stored indices (commented out as not necessary for a list reference)
9487 # $forStatement->ivAdd('parseDataHash', 'index_list_ref', $indexListRef);
9488  
9489 # Retrieve the variable that's the next element of the array, and set the iterator
9490 # with its value
9491 $iterVar = $lvalue->variable;
9492 $elementVar = $forArrayExp->varObj->getCell(@$indexListRef);
9493 $iterVar->set($elementVar->value);
9494  
9495 # Perform another iteration of the loop
9496 $loopFlag = TRUE;
9497 }
9498 }
9499  
9500 if ($loopFlag) {
9501  
9502 # Perform another iteration of the loop. Go to the statement immediately after the
9503 # corresponding FOR statement
9504 if (defined $forStatement->nextStatement) {
9505  
9506 # LA::Script->nextStatement is currently set to this statement; continue execution
9507 # as if this were the GOSUB statement
9508 $self->scriptObj->set_nextStatement($forStatement);
9509  
9510 } else {
9511  
9512 # The FOR statement was the last (or only) statement on the line: use the next line
9513 $self->scriptObj->set_nextStatement(undef);
9514 $self->scriptObj->set_nextLine($forStatement->lineObj->procLineNum + 1);
9515 }
9516  
9517 # Put the corresponding 'for' statement back into the current subroutine's code
9518 # block stack
9519 $subObj->push_blockStackList($forStatement);
9520 }
9521  
9522 # Implementation complete
9523 return 1;
9524 }
9525 }
9526  
9527 { package Language::Axbasic::Statement::nextiface;
9528  
9529 use strict;
9530 use warnings;
9531 # use diagnostics;
9532  
9533 use Glib qw(TRUE FALSE);
9534  
9535 @Language::Axbasic::Statement::nextiface::ISA = qw(
9536 Language::Axbasic
9537 Language::Axbasic::Statement
9538 );
9539  
9540 # NEXTIFACE
9541  
9542 ##################
9543 # Methods
9544  
9545 sub parse {
9546  
9547 # Called by LA::Line->parse directly after a call to LA::Statement->new
9548 #
9549 # Expected arguments
9550 # (none besides $self)
9551 #
9552 # Return values
9553 # 'undef' on improper arguments or if there is an error
9554 # 1 otherwise
9555  
9556 my ($self, $check) = @_;
9557  
9558 # Local variables
9559 my ($subObj, $whileStatement);
9560  
9561 # Check for improper arguments
9562 if (defined $check) {
9563  
9564 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9565 }
9566  
9567 # NEXTIFACE statements always appear on their own
9568 if (! $self->tokenGroupObj->testStatementEnd()) {
9569  
9570 return $self->scriptObj->setError(
9571 'unexpected_keywords,_operators_or_expressions',
9572 $self->_objClass . '->parse',
9573 );
9574 }
9575  
9576 # Parsing complete
9577 return 1;
9578 }
9579  
9580 sub implement {
9581  
9582 # Called by LA::Line->implement directly after a call to $self->parse
9583 #
9584 # Expected arguments
9585 # (none besides $self)
9586 #
9587 # Return values
9588 # 'undef' on improper arguments or if there is an error
9589 # 1 otherwise
9590  
9591 my ($self, $check) = @_;
9592  
9593 # Check for improper arguments
9594 if (defined $check) {
9595  
9596 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9597 }
9598  
9599 # Do nothing, if the interface notification list is empty
9600 if (! $self->scriptObj->notificationList) {
9601  
9602 # Implementation complete
9603 return 1;
9604  
9605 } else {
9606  
9607 # Remove the current interface from the list
9608 $self->scriptObj->rmv_currentNotification();
9609 if ($self->scriptObj->notificationList) {
9610  
9611 # The next current notification is the first one in the list
9612 $self->scriptObj->set_currentNotification(0);
9613  
9614 } else {
9615  
9616 # The list is empty. Mark this with the value -1
9617 $self->scriptObj->set_currentNotification(-1);
9618 }
9619 }
9620  
9621 # Implementation complete
9622 return 1;
9623 }
9624 }
9625  
9626 { package Language::Axbasic::Statement::on;
9627  
9628 use strict;
9629 use warnings;
9630 # use diagnostics;
9631  
9632 use Glib qw(TRUE FALSE);
9633  
9634 @Language::Axbasic::Statement::on::ISA = qw(
9635 Language::Axbasic
9636 Language::Axbasic::Statement
9637 );
9638  
9639 # ON expression GOTO expression [ , expression ... ]
9640 # ON expression GOSUB expression [ , expression ... ]
9641  
9642 ##################
9643 # Methods
9644  
9645 sub parse {
9646  
9647 # Called by LA::Line->parse directly after a call to LA::Statement->new
9648 #
9649 # Expected arguments
9650 # (none besides $self)
9651 #
9652 # Return values
9653 # 'undef' on improper arguments or if there is an error
9654 # 1 otherwise
9655  
9656 my ($self, $check) = @_;
9657  
9658 # Local variables
9659 my (
9660 $expression, $token, $statementType,
9661 @lineList,
9662 );
9663  
9664 # Check for improper arguments
9665 if (defined $check) {
9666  
9667 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9668 }
9669  
9670 # The 'on' keyword is only available in primitive numbering mode
9671 if ($self->scriptObj->executionMode ne 'line_num') {
9672  
9673 return $self->scriptObj->setError(
9674 'statement_not_available_without_line_numbers',
9675 $self->_objClass . '->parse',
9676 );
9677 }
9678  
9679 # Everything up to the 'gosub' or 'goto' token is an arithmetic expression
9680 $expression = Language::Axbasic::Expression::Arithmetic->new(
9681 $self->scriptObj,
9682 $self->tokenGroupObj,
9683 );
9684  
9685 if (! defined $expression) {
9686  
9687 return $self->scriptObj->setError(
9688 'missing_or_illegal_expression',
9689 $self->_objClass . '->parse',
9690 );
9691 }
9692  
9693 # Extract the 'gosub'/'goto' token
9694 $token = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
9695 if (! defined $token || ($token->tokenText ne 'gosub' && $token->tokenText ne 'goto')) {
9696  
9697 return $self->scriptObj->setError(
9698 'syntax_error',
9699 $self->_objClass . '->parse',
9700 );
9701  
9702 } else {
9703  
9704 # Remember if it's a 'gosub' or a 'goto'
9705 $statementType = $token->tokenText;
9706 }
9707  
9708 # The remaining tokens should be line numbers, separated by commas
9709 do {
9710  
9711 my $lineNumber = Language::Axbasic::Expression::Arithmetic->new(
9712 $self->scriptObj,
9713 $self->tokenGroupObj,
9714 );
9715  
9716 if (! defined $lineNumber) {
9717  
9718 return $self->scriptObj->setError(
9719 'missing_or_illegal_expression',
9720 $self->_objClass . '->parse',
9721 );
9722  
9723 } else {
9724  
9725 push (@lineList, $lineNumber);
9726 }
9727  
9728 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
9729  
9730 # Store the data, so $self->implement can retrieve it
9731 $self->ivAdd('parseDataHash', 'expression', $expression);
9732 $self->ivAdd('parseDataHash', 'statement_type', $statementType);
9733 $self->ivPush('parseDataList', @lineList);
9734  
9735 # Parsing complete
9736 return 1;
9737 }
9738  
9739 sub implement {
9740  
9741 # Called by LA::Line->implement directly after a call to $self->parse
9742 #
9743 # Expected arguments
9744 # (none besides $self)
9745 #
9746 # Return values
9747 # 'undef' on improper arguments
9748 # 1 otherwise
9749  
9750 my ($self, $check) = @_;
9751  
9752 # Local variables
9753 my (
9754 $expression, $statementType, $line, $lineNumber, $value,
9755 @lineList,
9756 );
9757  
9758 # Check for improper arguments
9759 if (defined $check) {
9760  
9761 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
9762 }
9763  
9764 # Retrieve the data stored by ->parse
9765 $expression = $self->ivShow('parseDataHash', 'expression');
9766 $statementType = $self->ivShow('parseDataHash', 'statement_type');
9767 @lineList = $self->parseDataList;
9768  
9769 # Evaluate the main expression
9770 $value = $expression->evaluate();
9771 if (! defined $value || ! ($value =~ /^\d+$/) || $value > @lineList) {
9772  
9773 return $self->scriptObj->setError(
9774 'missing_or_illegal_expression',
9775 $self->_objClass . '->implement',
9776 'VALUE', $value,
9777 );
9778 }
9779  
9780 # If $value == n, the line number to jump to is the [n-1]th value in @lineList
9781 $line = $lineList[$value - 1];
9782 $lineNumber = $line->evaluate();
9783 if (! defined $lineNumber || ! ($lineNumber =~ /^\d+$/)) {
9784  
9785 return $self->scriptObj->setError(
9786 'illegal_line_number_NUM',
9787 $self->_objClass . '->implement',
9788 'NUM', $lineNumber,
9789 );
9790 }
9791  
9792 # Check that the primitive line number exists
9793 if (! $self->scriptObj->ivExists('primLineHash', $lineNumber)) {
9794  
9795 return $self->scriptObj->setError(
9796 'line_number_NUM_not_found',
9797 $self->_objClass . '->implement',
9798 'NUM', $lineNumber,
9799 );
9800 }
9801  
9802 if ($statementType eq 'gosub') {
9803  
9804 # Push the current statement onto the subroutine stack
9805 $self->scriptObj->push_gosubStackList($self);
9806 }
9807  
9808 # Set the next line/statement to be executed
9809 $self->scriptObj->set_nextLine($self->scriptObj->ivShow('primLineHash', $lineNumber));
9810 $self->scriptObj->set_nextStatement(undef);
9811  
9812 # Implementation complete
9813 return 1;
9814 }
9815 }
9816  
9817 { package Language::Axbasic::Statement::open;
9818  
9819 use strict;
9820 use warnings;
9821 # use diagnostics;
9822  
9823 use Glib qw(TRUE FALSE);
9824  
9825 @Language::Axbasic::Statement::open::ISA = qw(
9826 Language::Axbasic
9827 Language::Axbasic::Statement
9828 );
9829  
9830 # OPEN #channel: NAME expression
9831 # [, ORGANIZATION TEXT ] [, CREATE NEW|OLD|NEWOLD ] [, ACCESS OUTIN|INPUT|OUTPUT ]
9832 # OPEN #channel: NAME expression
9833 # [, ORGANIZATION expression ] [, CREATE expression ] [, ACCESS expression ]
9834  
9835 ##################
9836 # Methods
9837  
9838 sub parse {
9839  
9840 # Called by LA::Line->parse directly after a call to LA::Statement->new
9841 #
9842 # Expected arguments
9843 # (none besides $self)
9844 #
9845 # Return values
9846 # 'undef' on improper arguments or if there is an error
9847 # 1 otherwise
9848  
9849 my ($self, $check) = @_;
9850  
9851 # Local variables
9852 my ($channelToken, $channel, $nameFlag);
9853  
9854 # Check for improper arguments
9855 if (defined $check) {
9856  
9857 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
9858 }
9859  
9860 # Get the channel token. For OPEN statements, it must include a colon at the end
9861 # (e.g. '#5:' )
9862 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
9863 if (! defined $channelToken || ! ($channelToken->tokenText =~ m/\:$/)) {
9864  
9865 return $self->scriptObj->setError(
9866 'syntax_error',
9867 $self->_objClass . '->parse',
9868 );
9869  
9870 } else {
9871  
9872 # Store the channel number
9873 $channelToken->tokenText =~ m/([0-9]+)/;
9874 $channel = $1;
9875  
9876 # True BASIC specifies that the channel must be in the range 1-999; same range used by
9877 # Axbasic
9878 if ($channel < 1 || $channel > 999) {
9879  
9880 return $self->scriptObj->setError(
9881 'file_channel_NUM_out_of_range',
9882 $self->_objClass . '->parse',
9883 'NUM', $channel,
9884 );
9885  
9886 } else {
9887  
9888 $self->ivAdd('parseDataHash', 'channel', $channel);
9889 }
9890 }
9891  
9892 # The rest of the arguments will be separated by commas
9893 do {
9894  
9895 my ($token, $expression, $nextToken);
9896  
9897 $token = $self->tokenGroupObj->shiftToken();
9898 if ($token) {
9899  
9900 if ($token->category ne 'keyword') {
9901  
9902 return $self->scriptObj->setError(
9903 'syntax_error',
9904 $self->_objClass . '->parse',
9905 );
9906  
9907 } elsif ($token->tokenText eq 'name') {
9908  
9909 # Next token is an expression for the file name
9910 $expression = Language::Axbasic::Expression::Arithmetic->new(
9911 $self->scriptObj,
9912 $self->tokenGroupObj,
9913 );
9914  
9915 if (! defined $expression) {
9916  
9917 return $self->scriptObj->setError(
9918 'missing_or_illegal_expression',
9919 $self->_objClass . '->parse',
9920 );
9921  
9922 } else {
9923  
9924 # Store the file expression
9925 $self->ivAdd('parseDataHash', 'file_exp', $expression);
9926 $nameFlag = TRUE;
9927 }
9928  
9929 } elsif ($token->tokenText eq 'organization' || $token->tokenText eq 'org') {
9930  
9931 # Next token must be the keyword TEXT (True BASIC also uses STREAM, RANDOM,
9932 # RECORD and BYTE, but Axbasic does not implement them)
9933 # (Can also be an expression evaluating to 'text')
9934 $nextToken = $self->tokenGroupObj->shiftMatchingToken('text');
9935 if (! $nextToken) {
9936  
9937 $expression = Language::Axbasic::Expression::Arithmetic->new(
9938 $self->scriptObj,
9939 $self->tokenGroupObj,
9940 );
9941  
9942 if (! $expression) {
9943  
9944 return $self->scriptObj->setError(
9945 'syntax_error',
9946 $self->_objClass . '->parse',
9947 );
9948  
9949 } else {
9950  
9951 # Store the expression, for $self->implement to evaluate
9952 $self->ivAdd('parseDataHash', 'org_exp', $expression);
9953 }
9954  
9955 } else {
9956  
9957 # Axbasic only reads/writes text files, but we'll store value for
9958 # $self->implemement to retrieve anyway
9959 $self->ivAdd('parseDataHash', 'org_type', 'text');
9960 }
9961  
9962 } elsif ($token->tokenText eq 'create') {
9963  
9964 # Next token must be one of the keywords NEW, OLD, NEWOLD (can also be an
9965 # expression evaluating to 'new', 'old' or 'newold')
9966 $nextToken = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
9967 if (! $nextToken) {
9968  
9969 $expression = Language::Axbasic::Expression::Arithmetic->new(
9970 $self->scriptObj,
9971 $self->tokenGroupObj,
9972 );
9973  
9974 if (! $expression) {
9975  
9976 return $self->scriptObj->setError(
9977 'syntax_error',
9978 $self->_objClass . '->parse',
9979 );
9980  
9981 } else {
9982  
9983 # Store the expression, for $self->implement to evaluate
9984 $self->ivAdd('parseDataHash', 'create_exp', $expression);
9985 }
9986  
9987 } else {
9988  
9989 if (
9990 $nextToken->tokenText eq 'new'
9991 || $nextToken->tokenText eq 'old'
9992 || $nextToken->tokenText eq 'newold'
9993 ) {
9994 # Store the create file mode
9995 $self->ivAdd('parseDataHash', 'create_type', $nextToken->tokenText);
9996  
9997 } else {
9998  
9999 return $self->scriptObj->setError(
10000 'syntax_error',
10001 $self->_objClass . '->parse',
10002 );
10003 }
10004 }
10005  
10006 } elsif ($token->tokenText eq 'access') {
10007  
10008 # Next token must be one of the keywords OUTIN, INPUT, OUTPUT (can also be an
10009 # expression evaluating to 'outin', 'input' or 'output')
10010 $nextToken = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
10011 if (! $nextToken) {
10012  
10013 $expression = Language::Axbasic::Expression::Arithmetic->new(
10014 $self->scriptObj,
10015 $self->tokenGroupObj,
10016 );
10017  
10018 if (! $expression) {
10019  
10020 return $self->scriptObj->setError(
10021 'syntax_error',
10022 $self->_objClass . '->parse',
10023 );
10024  
10025 } else {
10026  
10027 # Store the expression, for $self->implement to evaluate
10028 $self->ivAdd('parseDataHash', 'access_exp', $expression);
10029 }
10030  
10031 } else {
10032  
10033 if (
10034 $nextToken->tokenText eq 'outin'
10035 || $nextToken->tokenText eq 'input'
10036 || $nextToken->tokenText eq 'output'
10037 ) {
10038 # Store the create file mode
10039 $self->ivAdd('parseDataHash', 'access_type', $nextToken->tokenText);
10040  
10041 } else {
10042  
10043 return $self->scriptObj->setError(
10044 'syntax_error',
10045 $self->_objClass . '->parse',
10046 );
10047 }
10048 }
10049  
10050 } else {
10051  
10052 return $self->scriptObj->setError(
10053 'syntax_error',
10054 $self->_objClass . '->parse',
10055 );
10056 }
10057 }
10058  
10059 } until (! defined $self->tokenGroupObj->shiftMatchingToken(','));
10060  
10061 # The NAME keyword, followed by a file expression, are compulsory
10062 if (! $nameFlag) {
10063  
10064 return $self->scriptObj->setError(
10065 'missing_file_NAME_in_OPEN_statement',
10066 $self->_objClass . '->parse',
10067 );
10068 }
10069  
10070 # Parsing complete
10071 return 1;
10072 }
10073  
10074 sub implement {
10075  
10076 # Called by LA::Line->implement directly after a call to $self->parse
10077 #
10078 # Expected arguments
10079 # (none besides $self)
10080 #
10081 # Return values
10082 # 'undef' on improper arguments or if there is an error
10083 # 1 otherwise
10084  
10085 my ($self, $check) = @_;
10086  
10087 # Local variables
10088 my (
10089 $channel, $fileExp, $orgType, $orgExp, $createType, $createExp, $accessType, $accessExp,
10090 $channelCount, $channelObj, $filePath, $file, $directory, $fileMode, $fileHandle,
10091 );
10092  
10093 # Check for improper arguments
10094 if (defined $check) {
10095  
10096 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10097 }
10098  
10099 # Retrieve the variables stored by ->parse
10100 $channel = $self->ivShow('parseDataHash', 'channel');
10101 $fileExp = $self->ivShow('parseDataHash', 'file_exp');
10102 $orgType = $self->ivShow('parseDataHash', 'org_type'); # Recognised, but not used
10103 $orgExp = $self->ivShow('parseDataHash', 'org_exp');
10104 $createType = $self->ivShow('parseDataHash', 'create_type');
10105 $createExp = $self->ivShow('parseDataHash', 'create_exp');
10106 $accessType = $self->ivShow('parseDataHash', 'access_type');
10107 $accessExp = $self->ivShow('parseDataHash', 'access_exp');
10108  
10109 # Check that the file channel is not already open
10110 if ($self->scriptObj->ivExists('fileChannelHash', $channel)) {
10111  
10112 return $self->scriptObj->setError(
10113 'file_channel_NUM_already_open',
10114 $self->_objClass . '->implement',
10115 'NUM', $channel,
10116 );
10117 }
10118  
10119 # Check that there aren't already too many channels open. True BASIC specifies a limit of
10120 # 25 simultaneous channels; same limit used by Axbasic
10121 $channelCount = $self->scriptObj->ivPairs('fileChannelHash');
10122 if ($channelCount >= 25) {
10123  
10124 return $self->scriptObj->setError(
10125 'file_channel_limit_reached',
10126 $self->_objClass . '->implement',
10127 'NUM', $channel,
10128 );
10129 }
10130  
10131 # OPEN statements can contain TEXT, NEW, OLD, NEWOLD, OUTIN, INPUT, OUTPUT option keywords.
10132 # If expressions were used instead, evaluate the expression
10133 if ($orgExp) {
10134  
10135 $orgType = lc($orgExp->evaluate());
10136 if (! $orgType || $orgType ne 'text') {
10137  
10138 return $self->scriptObj->setError(
10139 'invalid_option_in_OPEN_statement',
10140 $self->_objClass . '->implement',
10141 );
10142 }
10143 }
10144  
10145 if ($createExp) {
10146  
10147 $createType = lc($createExp->evaluate());
10148 if (
10149 ! $createType
10150 || ($createType ne 'new' && $createType ne 'old' && $createType ne 'newold')
10151 ) {
10152 return $self->scriptObj->setError(
10153 'invalid_option_in_OPEN_statement',
10154 $self->_objClass . '->implement',
10155 );
10156 }
10157 }
10158  
10159 if ($accessExp) {
10160  
10161 $accessType = lc($accessExp->evaluate());
10162 if (
10163 ! $accessType
10164 || ($accessType ne 'outin' && $accessType ne 'input' && $accessType ne 'output')
10165 ) {
10166 return $self->scriptObj->setError(
10167 'invalid_option_in_OPEN_statement',
10168 $self->_objClass . '->implement',
10169 );
10170 }
10171 }
10172  
10173 # OPEN statements can contain ORGANIZATION, CREATE and ACCESS option keywords but, if not,
10174 # set the default values
10175 if (! defined $orgType) {
10176  
10177 $orgType = 'text';
10178 }
10179  
10180 if (! defined $createType) {
10181  
10182 $createType = 'old';
10183 }
10184  
10185 if (! defined $accessType) {
10186  
10187 $accessType = 'outin';
10188 }
10189  
10190 # Evaluate the filepath expression
10191 $filePath = $fileExp->evaluate();
10192 if (! $filePath) {
10193  
10194 return $self->scriptObj->setError(
10195 'invalid_file_path',
10196 $self->_objClass . '->implement',
10197 );
10198  
10199 } else {
10200  
10201 # Assuming that $filePath is relative to the script's directory, convert it to an
10202 # absolute filepath
10203 # LA::Script->filePath is the path to the script's .bas file. Get its directory
10204 ($file, $directory) = File::Basename::fileparse($self->scriptObj->filePath);
10205 if ($directory) {
10206  
10207 $filePath = $directory . $filePath;
10208 }
10209 }
10210  
10211 # For CREATE NEW, display an error if the file already exists
10212 if ($createType eq 'new' && -e $filePath) {
10213  
10214 return $self->scriptObj->setError(
10215 'file_already_exists',
10216 $self->_objClass . '->implement',
10217 );
10218 }
10219  
10220 # For CREATE OLD, check that the file actually exists
10221 if ($createType eq 'old' && ! -e $filePath) {
10222  
10223 return $self->scriptObj->setError(
10224 'file_does_not_exist',
10225 $self->_objClass . '->implement',
10226 );
10227 }
10228  
10229 # CREATE NEW can't be used with ACCESS INPUT - can't read a file that doesn't exist
10230 if ($createType eq 'new' && $accessType eq 'input') {
10231  
10232 return $self->scriptObj->setError(
10233 'invalid_OPEN_statement_options',
10234 $self->_objClass . '->implement',
10235 );
10236 }
10237  
10238 # Axbasic simplifies things by opening a file in 'read/write' mode; every subsequent INPUT /
10239 # PRINT statement that uses this file channel checks the options specified by the CREATE
10240 # and ACCESS keywords, to make sure reading/writing is allowed
10241 if (! open ($fileHandle, "+>>", $filePath)) { # Read/write, create, don't truncate
10242  
10243 return $self->scriptObj->setError(
10244 'failed_to_open_file',
10245 $self->_objClass . '->implement',
10246 );
10247 }
10248  
10249 # However, for read-only and read/write modes, need to move the pointer to the beginning of
10250 # the file
10251 if ($accessType ne 'output') {
10252  
10253 seek($fileHandle, 0, Fcntl::SEEK_SET);
10254 }
10255  
10256 # File channel open. Create a file channel object
10257 $channelObj = Language::Axbasic::FileChannel->new(
10258 $self->scriptObj,
10259 $channel,
10260 $filePath,
10261 $fileHandle,
10262 $orgType,
10263 $createType,
10264 $accessType,
10265 );
10266  
10267 if (! $channelObj) {
10268  
10269 return $self->scriptObj->setError(
10270 'failed_to_open_channel',
10271 $self->_objClass . '->implement',
10272 );
10273  
10274 } else {
10275  
10276 # Update the script's IVs
10277 $self->scriptObj->add_fileChannel($channelObj);
10278  
10279 # Implementation complete
10280 return 1;
10281 }
10282 }
10283 }
10284  
10285 { package Language::Axbasic::Statement::openentry;
10286  
10287 use strict;
10288 use warnings;
10289 # use diagnostics;
10290  
10291 use Glib qw(TRUE FALSE);
10292  
10293 @Language::Axbasic::Statement::openentry::ISA = qw(
10294 Language::Axbasic
10295 Language::Axbasic::Statement
10296 );
10297  
10298 # OPENENTRY
10299  
10300 ##################
10301 # Methods
10302  
10303 sub parse {
10304  
10305 # Called by LA::Line->parse directly after a call to LA::Statement->new
10306 #
10307 # Expected arguments
10308 # (none besides $self)
10309 #
10310 # Return values
10311 # 'undef' on improper arguments or if there is an error
10312 # 1 otherwise
10313  
10314 my ($self, $check) = @_;
10315  
10316 # Local variables
10317 my ($expression);
10318  
10319 # Check for improper arguments
10320 if (defined $check) {
10321  
10322 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10323 }
10324  
10325 # OPENENTRY statements always appear on their own
10326 if (! $self->tokenGroupObj->testStatementEnd()) {
10327  
10328 return $self->scriptObj->setError(
10329 'unexpected_keywords,_operators_or_expressions',
10330 $self->_objClass . '->parse',
10331 );
10332 }
10333  
10334 # Parsing complete
10335 return 1;
10336 }
10337  
10338 sub implement {
10339  
10340 # Called by LA::Line->implement directly after a call to $self->parse
10341 #
10342 # Expected arguments
10343 # (none besides $self)
10344 #
10345 # Return values
10346 # 'undef' on improper arguments or if there is an error
10347 # 1 otherwise
10348  
10349 my ($self, $check) = @_;
10350  
10351 # Local variables
10352  
10353 # Check for improper arguments
10354 if (defined $check) {
10355  
10356 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10357 }
10358  
10359 # If the Axbasic script is being run from within an Axmud task, open the window (unless one
10360 # is already open). Otherwise, do nothing
10361 if ($self->scriptObj->parentTask && ! $self->scriptObj->parentTask->taskWinFlag) {
10362  
10363 # Open a task window with an entry box (by specifying these arguments, we get either a
10364 # 'grid' window or a pane object in the session's 'main' window, both using an
10365 # entry box)
10366 $self->scriptObj->parentTask->openWin('entry_fill', 'pane', 'grid');
10367 }
10368  
10369 # Implementation complete
10370 return 1;
10371 }
10372 }
10373  
10374 { package Language::Axbasic::Statement::openwin;
10375  
10376 use strict;
10377 use warnings;
10378 # use diagnostics;
10379  
10380 use Glib qw(TRUE FALSE);
10381  
10382 @Language::Axbasic::Statement::openwin::ISA = qw(
10383 Language::Axbasic
10384 Language::Axbasic::Statement
10385 );
10386  
10387 # OPENWIN
10388  
10389 ##################
10390 # Methods
10391  
10392 sub parse {
10393  
10394 # Called by LA::Line->parse directly after a call to LA::Statement->new
10395 #
10396 # Expected arguments
10397 # (none besides $self)
10398 #
10399 # Return values
10400 # 'undef' on improper arguments or if there is an error
10401 # 1 otherwise
10402  
10403 my ($self, $check) = @_;
10404  
10405 # Local variables
10406 my ($expression);
10407  
10408 # Check for improper arguments
10409 if (defined $check) {
10410  
10411 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10412 }
10413  
10414 # OPENWIN statements always appear on their own
10415 if (! $self->tokenGroupObj->testStatementEnd()) {
10416  
10417 return $self->scriptObj->setError(
10418 'unexpected_keywords,_operators_or_expressions',
10419 $self->_objClass . '->parse',
10420 );
10421 }
10422  
10423 # Parsing complete
10424 return 1;
10425 }
10426  
10427 sub implement {
10428  
10429 # Called by LA::Line->implement directly after a call to $self->parse
10430 #
10431 # Expected arguments
10432 # (none besides $self)
10433 #
10434 # Return values
10435 # 'undef' on improper arguments or if there is an error
10436 # 1 otherwise
10437  
10438 my ($self, $check) = @_;
10439  
10440 # Local variables
10441  
10442 # Check for improper arguments
10443 if (defined $check) {
10444  
10445 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10446 }
10447  
10448 # If the Axbasic script is being run from within an Axmud task, open the window (unless one
10449 # is already open). Otherwise, do nothing
10450 if ($self->scriptObj->parentTask && ! $self->scriptObj->parentTask->taskWinFlag) {
10451  
10452 # Open a task window with an entry box (by specifying these arguments, we get either a
10453 # 'grid' window or a pane object in the session's 'main' window, neither using an
10454 # entry box)
10455 $self->scriptObj->parentTask->openWin('basic_fill', 'entry', 'grid');
10456 }
10457  
10458 # Implementation complete
10459 return 1;
10460 }
10461 }
10462  
10463 { package Language::Axbasic::Statement::option;
10464  
10465 use strict;
10466 use warnings;
10467 # use diagnostics;
10468  
10469 use Glib qw(TRUE FALSE);
10470  
10471 @Language::Axbasic::Statement::option::ISA = qw(
10472 Language::Axbasic
10473 Language::Axbasic::Statement
10474 );
10475  
10476 # OPTION ANGLE DEGREES
10477 # OPTION ANGLE RADIANS
10478 # OPTION NEEDTASK
10479 # OPTION NOLET
10480 # OPTION PERSIST
10481 # OPTION PSEUDO expression
10482 # OPTION REDIRECT
10483 # OPTION REQUIRE expression
10484 # OPTION SILENT
10485 # OPTION TYPO
10486  
10487 ##################
10488 # Methods
10489  
10490 sub parse {
10491  
10492 # Called by LA::Line->parse directly after a call to LA::Statement->new
10493 #
10494 # Expected arguments
10495 # (none besides $self)
10496 #
10497 # Return values
10498 # 'undef' on improper arguments or if there is an error
10499 # 1 otherwise
10500  
10501 my ($self, $check) = @_;
10502  
10503 # Local variables
10504 my ($token, $expression, $value);
10505  
10506 # Check for improper arguments
10507 if (defined $check) {
10508  
10509 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10510 }
10511  
10512 # OPTION ANGLE DEGREES statement
10513 # OPTION ANGLE RADIANS statement
10514 $token = $self->tokenGroupObj->shiftMatchingToken('angle');
10515 if (defined $token) {
10516  
10517 $token = $self->tokenGroupObj->shiftMatchingToken('degrees');
10518 if (! defined $token) {
10519  
10520 $token = $self->tokenGroupObj->shiftMatchingToken('radians');
10521 }
10522  
10523 if (defined $token) {
10524  
10525 if (! $self->tokenGroupObj->testStatementEnd()) {
10526  
10527 return $self->scriptObj->setError(
10528 'unexpected_keywords,_operators_or_expressions',
10529 $self->_objClass . '->parse',
10530 );
10531  
10532 } elsif ($token->tokenText eq 'degrees') {
10533  
10534 $self->scriptObj->add_optionStatement('angle', 'degrees');
10535  
10536 } else {
10537  
10538 $self->scriptObj->add_optionStatement('angle', 'radians');
10539 }
10540  
10541 return 1;
10542  
10543 } else {
10544  
10545 return $self->scriptObj->setError(
10546 'syntax_error',
10547 $self->_objClass . '->parse',
10548 );
10549 }
10550 }
10551  
10552 # OPTION NEEDTASK statement
10553 $token = $self->tokenGroupObj->shiftMatchingToken('needtask');
10554 if (defined $token) {
10555  
10556 if (! $self->tokenGroupObj->testStatementEnd()) {
10557  
10558 return $self->scriptObj->setError(
10559 'unexpected_keywords,_operators_or_expressions',
10560 $self->_objClass . '->parse',
10561 );
10562  
10563 } elsif (! $self->scriptObj->parentTask) {
10564  
10565 return $self->scriptObj->setError(
10566 'script_cannot_run_without_parent_task',
10567 $self->_objClass . '->parse',
10568 );
10569  
10570 } else {
10571  
10572 $self->scriptObj->add_optionStatement('needtask', TRUE);
10573 return 1;
10574 }
10575 }
10576  
10577 # OPTION NOLET statement
10578 $token = $self->tokenGroupObj->shiftMatchingToken('nolet');
10579 if (defined $token) {
10580  
10581 if (! $self->tokenGroupObj->testStatementEnd()) {
10582  
10583 return $self->scriptObj->setError(
10584 'unexpected_keywords,_operators_or_expressions',
10585 $self->_objClass . '->parse',
10586 );
10587  
10588 } else {
10589  
10590 $self->scriptObj->add_optionStatement('nolet', TRUE);
10591 return 1;
10592 }
10593 }
10594  
10595 # OPTION PERSIST statement
10596 $token = $self->tokenGroupObj->shiftMatchingToken('persist');
10597 if (defined $token) {
10598  
10599 if (! $self->tokenGroupObj->testStatementEnd()) {
10600  
10601 return $self->scriptObj->setError(
10602 'unexpected_keywords,_operators_or_expressions',
10603 $self->_objClass . '->parse',
10604 );
10605  
10606 } else {
10607  
10608 $self->scriptObj->add_optionStatement('persist', TRUE);
10609 return 1;
10610 }
10611 }
10612  
10613 # OPTION PSEUDO String-Exp
10614 $token = $self->tokenGroupObj->shiftMatchingToken('pseudo');
10615 if (defined $token) {
10616  
10617 # Get the expression
10618 $expression = Language::Axbasic::Expression::Arithmetic->new(
10619 $self->scriptObj,
10620 $self->tokenGroupObj,
10621 );
10622  
10623 if (! defined $expression) {
10624  
10625 return $self->scriptObj->setError(
10626 'missing_or_illegal_expression',
10627 $self->_objClass . '->parse',
10628 );
10629 }
10630  
10631 # There should be nothing more
10632 if (! $self->tokenGroupObj->testStatementEnd()) {
10633  
10634 return $self->scriptObj->setError(
10635 'unexpected_keywords,_operators_or_expressions',
10636 $self->_objClass . '->parse',
10637 );
10638 }
10639  
10640 # Check that a valid expression has been specified
10641 # Evaluate the expression
10642 $value = $expression->evaluate();
10643 if (
10644 ! defined $value
10645 || (
10646 $value ne 'show_all' && $value ne 'hide_complete' && $value ne 'hide_system'
10647 && $value ne 'win_error' && $value ne 'win_only'
10648 )
10649 ) {
10650 return $self->scriptObj->setError(
10651 'invalid_expression',
10652 $self->_objClass . '->parse',
10653 )
10654 }
10655  
10656 # Set the new pseudo-command mode
10657 $self->scriptObj->add_optionStatement('pseudo', $value);
10658 $self->scriptObj->set_pseudoCmdMode($value);
10659  
10660 return 1;
10661 }
10662  
10663 # OPTION REDIRECT statement
10664 $token = $self->tokenGroupObj->shiftMatchingToken('redirect');
10665 if (defined $token) {
10666  
10667 if (! $self->tokenGroupObj->testStatementEnd()) {
10668  
10669 return $self->scriptObj->setError(
10670 'unexpected_keywords,_operators_or_expressions',
10671 $self->_objClass . '->parse',
10672 );
10673  
10674 } else {
10675  
10676 $self->scriptObj->add_optionStatement('redirect', TRUE);
10677 return 1;
10678 }
10679 }
10680  
10681 # OPTION REQUIRE Arith-Exp statement
10682 $token = $self->tokenGroupObj->shiftMatchingToken('require');
10683 if (defined $token) {
10684  
10685 # Get the expression
10686 $expression = Language::Axbasic::Expression::Arithmetic->new(
10687 $self->scriptObj,
10688 $self->tokenGroupObj,
10689 );
10690  
10691 if (! defined $expression) {
10692  
10693 return $self->scriptObj->setError(
10694 'missing_or_illegal_expression',
10695 $self->_objClass . '->parse',
10696 );
10697 }
10698  
10699 # There should be nothing more
10700 if (! $self->tokenGroupObj->testStatementEnd()) {
10701  
10702 return $self->scriptObj->setError(
10703 'unexpected_keywords,_operators_or_expressions',
10704 $self->_objClass . '->parse',
10705 );
10706 }
10707  
10708 # Check that a valid expression (floating point numbers, 1.0 or above) has been
10709 # specified
10710 # Evaluate the expression
10711 $value = $expression->evaluate();
10712 if (
10713 ! defined $value
10714 || ! ($value =~ /^-?(?:\d+\.?|\.\d)\d*\z/)
10715 ) {
10716 return $self->scriptObj->setError(
10717 'invalid_version',
10718 $self->_objClass . '->parse',
10719 )
10720  
10721 } elsif ($value < 1) {
10722  
10723 return $self->scriptObj->setError(
10724 'version_NUM_out_of_range',
10725 $self->_objClass . '->parse',
10726 'NUM', $value,
10727 )
10728  
10729 } elsif ($value > $axmud::BASIC_VERSION) {
10730  
10731 return $self->scriptObj->setError(
10732 'script_requires_version_NUM',
10733 $self->_objClass . '->parse',
10734 'NUM', $value,
10735 );
10736 }
10737  
10738 # Set the new minimum version
10739 $self->scriptObj->add_optionStatement('require', $value);
10740  
10741 return 1;
10742 }
10743  
10744 # OPTION SILENT statement
10745 $token = $self->tokenGroupObj->shiftMatchingToken('silent');
10746 if (defined $token) {
10747  
10748 if (! $self->tokenGroupObj->testStatementEnd()) {
10749  
10750 return $self->scriptObj->setError(
10751 'unexpected_keywords,_operators_or_expressions',
10752 $self->_objClass . '->parse',
10753 );
10754  
10755 } else {
10756  
10757 $self->scriptObj->add_optionStatement('silent', TRUE);
10758 return 1;
10759 }
10760 }
10761  
10762 # OPTION TYPO statement
10763 $token = $self->tokenGroupObj->shiftMatchingToken('typo');
10764 if (defined $token) {
10765  
10766 if (! $self->tokenGroupObj->testStatementEnd()) {
10767  
10768 return $self->scriptObj->setError(
10769 'unexpected_keywords,_operators_or_expressions',
10770 $self->_objClass . '->parse',
10771 );
10772  
10773 } else {
10774  
10775 $self->scriptObj->add_optionStatement('typo', TRUE);
10776  
10777 return 1;
10778 }
10779 }
10780  
10781 # Default
10782 return $self->scriptObj->setError(
10783 'syntax_error',
10784 $self->_objClass . '->parse',
10785 );
10786  
10787 # Parsing complete
10788 return 1;
10789 }
10790  
10791 # No ->implement function needed
10792 }
10793  
10794 { package Language::Axbasic::Statement::paintwin;
10795  
10796 use strict;
10797 use warnings;
10798 # use diagnostics;
10799  
10800 use Glib qw(TRUE FALSE);
10801  
10802 @Language::Axbasic::Statement::paintwin::ISA = qw(
10803 Language::Axbasic
10804 Language::Axbasic::Statement
10805 );
10806  
10807 # PAINTWIN [ expression ]
10808  
10809 ##################
10810 # Methods
10811  
10812 sub parse {
10813  
10814 # Called by LA::Line->parse directly after a call to LA::Statement->new
10815 #
10816 # Expected arguments
10817 # (none besides $self)
10818 #
10819 # Return values
10820 # 'undef' on improper arguments or if there is an error
10821 # 1 otherwise
10822  
10823 my ($self, $check) = @_;
10824  
10825 # Local variables
10826 my $paintExp;
10827  
10828 # Check for improper arguments
10829 if (defined $check) {
10830  
10831 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10832 }
10833  
10834 if (! $self->tokenGroupObj->testStatementEnd()) {
10835  
10836 # Convert the name string into an expression
10837 $paintExp = Language::Axbasic::Expression::Arithmetic->new(
10838 $self->scriptObj,
10839 $self->tokenGroupObj,
10840 );
10841  
10842 if (! defined $paintExp) {
10843  
10844 return $self->scriptObj->setError(
10845 'missing_or_illegal_expression',
10846 $self->_objClass . '->parse',
10847 );
10848 }
10849 }
10850  
10851 # Check that nothing more remains
10852 if (! $self->tokenGroupObj->testStatementEnd()) {
10853  
10854 return $self->scriptObj->setError(
10855 'unexpected_keywords,_operators_or_expressions',
10856 $self->_objClass . '->parse',
10857 );
10858 }
10859  
10860 if ($paintExp) {
10861  
10862 # Store the expression, so $self->implement can retrieve it
10863 $self->ivAdd('parseDataHash', 'paint_exp', $paintExp);
10864 }
10865  
10866 # Parsing complete
10867 return 1;
10868 }
10869  
10870 sub implement {
10871  
10872 # Called by LA::Line->implement directly after a call to $self->parse
10873 #
10874 # Expected arguments
10875 # (none besides $self)
10876 #
10877 # Return values
10878 # 'undef' on improper arguments or if there is an error
10879 # 1 otherwise
10880  
10881 my ($self, $check) = @_;
10882  
10883 # Local variables
10884 my ($paintExp, $paint, $type, $taskObj);
10885  
10886 # Check for improper arguments
10887 if (defined $check) {
10888  
10889 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
10890 }
10891  
10892 # Retrieve the argument stored by $self->parse
10893 $paintExp = $self->ivShow('parseDataHash', 'paint_exp');
10894  
10895 if (defined $paintExp) {
10896  
10897 # Evaluate the expression
10898 $paint = $paintExp->evaluate();
10899 }
10900  
10901 # Import the parent task (if any)
10902 $taskObj = $self->scriptObj->parentTask;
10903  
10904 # If the Axbasic script is being run from within an Axmud task and the window is open, paint
10905 # it. Otherwise, do nothing
10906 if ($taskObj && $taskObj->taskWinFlag) {
10907  
10908 if (defined $paintExp) {
10909  
10910 # Evaluate the expression
10911 $paint = $paintExp->evaluate();
10912 # Is it a valid Axmud standard colour tag (not xterm or RGB)?
10913 ($type) = $axmud::CLIENT->checkColourTags($paint, 'standard');
10914 if (! $type) {
10915  
10916 return $self->scriptObj->setError(
10917 'invalid_colour_tag_TAG',
10918 $self->_objClass . '->implement',
10919 'TAG',
10920 $paint,
10921 );
10922 }
10923 }
10924  
10925 # Paint the window
10926 $taskObj->paintWin($paint);
10927 }
10928  
10929 # Implementation complete
10930 return 1;
10931 }
10932 }
10933  
10934 { package Language::Axbasic::Statement::pause;
10935  
10936 use strict;
10937 use warnings;
10938 # use diagnostics;
10939  
10940 use Glib qw(TRUE FALSE);
10941  
10942 @Language::Axbasic::Statement::pause::ISA = qw(
10943 Language::Axbasic
10944 Language::Axbasic::Statement
10945 );
10946  
10947 # PAUSE expression
10948 # SLEEP expression
10949  
10950 ##################
10951 # Methods
10952  
10953 sub parse {
10954  
10955 # Called by LA::Line->parse directly after a call to LA::Statement->new
10956 #
10957 # Expected arguments
10958 # (none besides $self)
10959 #
10960 # Return values
10961 # 'undef' on improper arguments or if there is an error
10962 # 1 otherwise
10963  
10964 my ($self, $check) = @_;
10965  
10966 # Local variables
10967 my ($expression);
10968  
10969 # Check for improper arguments
10970 if (defined $check) {
10971  
10972 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
10973 }
10974  
10975 # The rest of the statement is an arithmetic expression which evaluates to a number of
10976 # seconds
10977 $expression = Language::Axbasic::Expression::Arithmetic->new(
10978 $self->scriptObj,
10979 $self->tokenGroupObj,
10980 );
10981  
10982 if (! defined $expression) {
10983  
10984 return $self->scriptObj->setError(
10985 'missing_or_illegal_expression',
10986 $self->_objClass . '->parse',
10987 );
10988 }
10989  
10990 # Check that nothing follows the expression
10991 if (! $self->tokenGroupObj->testStatementEnd()) {
10992  
10993 return $self->scriptObj->setError(
10994 'unexpected_keywords,_operators_or_expressions',
10995 $self->_objClass . '->parse',
10996 );
10997 }
10998  
10999 # Store the arithmetic expression, so $self->implement can retrieve it
11000 $self->ivAdd('parseDataHash', 'expression', $expression);
11001  
11002 # Parsing complete
11003 return 1;
11004 }
11005  
11006 sub implement {
11007  
11008 # Called by LA::Line->implement directly after a call to $self->parse
11009 #
11010 # Expected arguments
11011 # (none besides $self)
11012 #
11013 # Return values
11014 # 'undef' on improper arguments or if there is an error
11015 # 1 otherwise
11016  
11017 my ($self, $check) = @_;
11018  
11019 # Local variables
11020 my ($expression, $seconds);
11021  
11022 # Check for improper arguments
11023 if (defined $check) {
11024  
11025 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11026 }
11027  
11028 # Retrieve the variable stored by ->parse
11029 $expression = $self->ivShow('parseDataHash', 'expression');
11030  
11031 # Evaluate the expression to get a number of seconds (which can be fractional, but must be
11032 # > 0)
11033 $seconds = $expression->evaluate();
11034 if (! ($seconds =~ /^\d+$/)) {
11035  
11036 return $self->scriptObj->setError(
11037 'invalid_integer',
11038 $self->_objClass . '->implement',
11039 );
11040  
11041 } elsif ($seconds < 1) {
11042  
11043 return $self->scriptObj->setError(
11044  
11045 'number_NUM_out_of_range',
11046 $self->_objClass . '->parse',
11047 'NUM', $seconds,
11048 );
11049 }
11050  
11051 # If the Axbasic script is being run from within an Axmud task, pause execution, otherwise
11052 # do nothing
11053 if ($self->scriptObj->parentTask) {
11054  
11055 # Mark this script as paused
11056 $self->scriptObj->set_scriptStatus('paused');
11057 # Reset the number of steps to take, before taking an automatic pause
11058 $self->scriptObj->set_stepCount(0);
11059  
11060 # Also, tell the parent task to pause
11061 $self->scriptObj->parentTask->pauseUntil(
11062 ($self->scriptObj->session->sessionTime + $seconds),
11063 );
11064 }
11065  
11066 # Implementation complete
11067 return 1;
11068 }
11069 }
11070  
11071 { package Language::Axbasic::Statement::peek;
11072  
11073 use strict;
11074 use warnings;
11075 # use diagnostics;
11076  
11077 use Glib qw(TRUE FALSE);
11078  
11079 @Language::Axbasic::Statement::peek::ISA = qw(
11080 Language::Axbasic
11081 Language::Axbasic::Statement
11082 );
11083  
11084 # PEEK variable-name = axmud-object-name
11085 # PEEK variable-name = axmud-object-property
11086 # PEEK ARRAY variable-name = axmud-object-property
11087  
11088 ##################
11089 # Methods
11090  
11091 sub parse {
11092  
11093 # Called by LA::Line->parse directly after a call to LA::Statement->new
11094 #
11095 # Expected arguments
11096 # (none besides $self)
11097 #
11098 # Return values
11099 # 'undef' on improper arguments or if there is an error
11100 # 1 otherwise
11101  
11102 my ($self, $check) = @_;
11103  
11104 # Check for improper arguments
11105 if (defined $check) {
11106  
11107 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11108 }
11109  
11110 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11111 # $self->parseDataHash, ready for $self->implement to access
11112 if (! $self->parsePeek()) {
11113  
11114 # ($self->scriptObj->setError has already been called)
11115 return undef;
11116 }
11117  
11118 # Parsing complete
11119 return 1;
11120 }
11121  
11122 sub implement {
11123  
11124 # Called by LA::Line->implement directly after a call to $self->parse
11125 #
11126 # Expected arguments
11127 # (none besides $self)
11128 #
11129 # Return values
11130 # 'undef' on improper arguments or if there is an error
11131 # 1 otherwise
11132  
11133 my ($self, $check) = @_;
11134  
11135 # Local variables
11136 my (
11137 # Standard
11138 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11139 $var, $objFlag, $privFlag, $scalar, $varObj,
11140 @array,
11141 # Custom (set after $varObj is set)
11142 $impScalarFlag, $impArrayFlag,
11143 );
11144  
11145 # Check for improper arguments
11146 if (defined $check) {
11147  
11148 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11149 }
11150  
11151 # Get the values stored by $self->parse
11152 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11153 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11154 $expression = $self->ivShow('parseDataHash', 'expression');
11155  
11156 # Evaluate the expression to get the Axmud internal variable, e.g. "world.current.name"
11157 $expValue = $expression->evaluate();
11158 # Process the string representing the Axmud internal variable
11159 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11160 = $self->scriptObj->session->parsePeekPoke($expValue);
11161 if (! $successFlag) {
11162  
11163 return $self->scriptObj->setError(
11164 'PEEK_operation_failure',
11165 $self->_objClass . '->implement',
11166 );
11167 }
11168  
11169 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11170 # or @array if $string refers to a list or hash value
11171 if (! $objFlag) {
11172  
11173 if (! defined $var) {
11174  
11175 $scalar = undef;
11176 $impScalarFlag = TRUE;
11177  
11178 } elsif (ref($var) eq 'ARRAY') {
11179  
11180 @array = @$var;
11181 $impArrayFlag = TRUE;
11182  
11183 } elsif (ref($var) eq 'HASH') {
11184  
11185 @array = %$var;
11186 $impArrayFlag = TRUE; # Perl hash gets converted to an Axbasic array
11187  
11188 } else {
11189  
11190 $scalar = $var;
11191 $impScalarFlag = TRUE;
11192 }
11193  
11194 # If this was a PEEK ARRAY statement, but the IV is a scalar, copy it into the first
11195 # cell of the Axbasic array (being an array containing 1 element)
11196 if ($impScalarFlag && $parseArrayFlag) {
11197  
11198 push (@array, $scalar);
11199  
11200 # Don't let the user copy a list/hash IV into an Axbasic scalar variable
11201 } elsif ($impArrayFlag && ! $parseArrayFlag) {
11202  
11203 return $self->scriptObj->setError(
11204 'PEEK_operation_failure',
11205 $self->_objClass . '->implement',
11206 );
11207 }
11208  
11209 } else {
11210  
11211 # Set $scalar to the Perl object
11212 if ($parseArrayFlag) {
11213  
11214 # We'll let the user copy an Axmud scalar IV into an Axbasic array, but we won't let
11215 # them copy a Perl object into an Axbasic array
11216 return $self->scriptObj->setError(
11217 'PEEK_operation_failure',
11218 $self->_objClass . '->implement',
11219 );
11220  
11221 } else {
11222  
11223 $scalar = $blessed;
11224 $impScalarFlag = TRUE;
11225 }
11226 }
11227  
11228 # Look up the LA::Variable
11229 $varObj = $self->fetchVar('PEEK', $basicVarName, $parseArrayFlag);
11230 if (! $varObj) {
11231  
11232 # (self->scriptObj->setError already called)
11233 return undef;
11234 }
11235  
11236 # Now we can set the variable to PEEK's return value
11237 if (! $parseArrayFlag) {
11238  
11239 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11240 # neccesary
11241 $self->importAsScalar($varObj, $scalar);
11242  
11243 } else {
11244  
11245 # Import the list/hash into an Axbasic array, resizing it as necessary
11246 $self->importAsArray($varObj, @array);
11247 }
11248  
11249 # Implementation complete
11250 return 1;
11251 }
11252 }
11253  
11254 { package Language::Axbasic::Statement::peekequals;
11255  
11256 use strict;
11257 use warnings;
11258 # use diagnostics;
11259  
11260 use Glib qw(TRUE FALSE);
11261  
11262 @Language::Axbasic::Statement::peekequals::ISA = qw(
11263 Language::Axbasic
11264 Language::Axbasic::Statement
11265 );
11266  
11267 # PEEKEQUALS variable-name = axmud-object-property, expression
11268 # PEEKEQUALS ARRAY variable-name = axmud-object-property, expression
11269  
11270 ##################
11271 # Methods
11272  
11273 sub parse {
11274  
11275 # Called by LA::Line->parse directly after a call to LA::Statement->new
11276 #
11277 # Expected arguments
11278 # (none besides $self)
11279 #
11280 # Return values
11281 # 'undef' on improper arguments or if there is an error
11282 # 1 otherwise
11283  
11284 my ($self, $check) = @_;
11285  
11286 # Check for improper arguments
11287 if (defined $check) {
11288  
11289 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11290 }
11291  
11292 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11293 # $self->parseDataHash, ready for $self->implement to access
11294 if (! $self->parsePeek(FALSE, TRUE)) {
11295  
11296 # ($self->scriptObj->setError has already been called)
11297 return undef;
11298 }
11299  
11300 # Parsing complete
11301 return 1;
11302 }
11303  
11304 sub implement {
11305  
11306 # Called by LA::Line->implement directly after a call to $self->parse
11307 #
11308 # Expected arguments
11309 # (none besides $self)
11310 #
11311 # Return values
11312 # 'undef' on improper arguments or if there is an error
11313 # 1 otherwise
11314  
11315 my ($self, $check) = @_;
11316  
11317 # Local variables
11318 my (
11319 # Standard
11320 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11321 $var, $objFlag, $privFlag, $scalar, $varObj,
11322 @array,
11323 # Custom (set after $varObj is set)
11324 $matchExp, $match, $matchIndex,
11325 );
11326  
11327 # Check for improper arguments
11328 if (defined $check) {
11329  
11330 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11331 }
11332  
11333 # Get the values stored by $self->parse
11334 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11335 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11336 $expression = $self->ivShow('parseDataHash', 'expression');
11337 $matchExp = $self->ivShow('parseDataHash', 'extra_exp');
11338  
11339 # Evaluate the first expression to get the Axmud internal variable, e.g.
11340 # "current.world.name"
11341 $expValue = $expression->evaluate();
11342 # Evaluate the second expression to get a numeric value
11343 $match = $matchExp->evaluate();
11344 if (! defined $match || ! ($match =~ /^\d+$/)) {
11345  
11346 return $self->scriptObj->setError(
11347 'invalid_matching_expression',
11348 $self->_objClass . '->implement',
11349 );
11350 }
11351  
11352 # Process the string representing the Axmud internal variable
11353 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11354 = $self->scriptObj->session->parsePeekPoke($expValue);
11355 if (! $successFlag) {
11356  
11357 return $self->scriptObj->setError(
11358 'PEEKEQUALS_operation_failure',
11359 $self->_objClass . '->implement',
11360 );
11361 }
11362  
11363 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11364 # or @array if $string refers to a list or hash value
11365 if (! $objFlag) {
11366  
11367 # This statement only accepts Perl scalars
11368 if (defined $var && ref($var) eq 'ARRAY') {
11369  
11370 @array = @$var;
11371  
11372 } else {
11373  
11374 return $self->scriptObj->setError(
11375 'PEEKEQUALS_operation_expects_list',
11376 $self->_objClass . '->implement',
11377 );
11378 }
11379  
11380 } else {
11381  
11382 return $self->scriptObj->setError(
11383 'PEEKEQUALS_cannot_import_object',
11384 $self->_objClass . '->implement',
11385 );
11386 }
11387  
11388 # Look up the LA::Variable
11389 $varObj = $self->fetchVar('PEEKEQUALS', $basicVarName, $parseArrayFlag);
11390 if (! $varObj) {
11391  
11392 # (self->scriptObj->setError already called)
11393 return undef;
11394 }
11395  
11396 # Now we can set the variable to PEEKEQUALS's return value
11397 # Assuming the array is not empty, walk the array looking for a value which is the same as
11398 # $match
11399 if (@array) {
11400  
11401 OUTER: for (my $count = 0; $count < scalar @array; $count++) {
11402  
11403 my $number;
11404  
11405 if (defined $array[$count]) {
11406  
11407 $number = $array[$count];
11408 if (
11409 $number =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/
11410 && $number == $match
11411 ) {
11412  
11413 # Matching value found at index $count
11414 $matchIndex = $count;
11415 last OUTER;
11416 }
11417 }
11418 }
11419 }
11420  
11421 if (! defined $matchIndex) {
11422  
11423 # List is empty, or a matching value was not found
11424 $matchIndex = -1;
11425 }
11426  
11427 if (! $parseArrayFlag) {
11428  
11429 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11430 # necessary
11431 $self->importAsScalar($varObj, $matchIndex);
11432  
11433 } else {
11434  
11435 # Import the list/hash into an Axbasic array, resizing it as necessary
11436 $self->importAsArray($varObj, $matchIndex);
11437 }
11438  
11439 # Implementation complete
11440 return 1;
11441 }
11442 }
11443  
11444 { package Language::Axbasic::Statement::peekexists;
11445  
11446 use strict;
11447 use warnings;
11448 # use diagnostics;
11449  
11450 use Glib qw(TRUE FALSE);
11451  
11452 @Language::Axbasic::Statement::peekexists::ISA = qw(
11453 Language::Axbasic
11454 Language::Axbasic::Statement
11455 );
11456  
11457 # PEEKEXISTS variable-name = axmud-object-property, expression
11458 # PEEKEXISTS ARRAY variable-name = axmud-object-property, expression
11459  
11460 ##################
11461 # Methods
11462  
11463 sub parse {
11464  
11465 # Called by LA::Line->parse directly after a call to LA::Statement->new
11466 #
11467 # Expected arguments
11468 # (none besides $self)
11469 #
11470 # Return values
11471 # 'undef' on improper arguments or if there is an error
11472 # 1 otherwise
11473  
11474 my ($self, $check) = @_;
11475  
11476 # Check for improper arguments
11477 if (defined $check) {
11478  
11479 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11480 }
11481  
11482 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11483 # $self->parseDataHash, ready for $self->implement to access
11484 if (! $self->parsePeek(FALSE, TRUE)) {
11485  
11486 # ($self->scriptObj->setError has already been called)
11487 return undef;
11488 }
11489  
11490 # Parsing complete
11491 return 1;
11492 }
11493  
11494 sub implement {
11495  
11496 # Called by LA::Line->implement directly after a call to $self->parse
11497 #
11498 # Expected arguments
11499 # (none besides $self)
11500 #
11501 # Return values
11502 # 'undef' on improper arguments or if there is an error
11503 # 1 otherwise
11504  
11505 my ($self, $check) = @_;
11506  
11507 # Local variables
11508 my (
11509 # Standard
11510 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11511 $var, $objFlag, $privFlag, $scalar, $varObj,
11512 @array,
11513 # Custom (set after $varObj is set)
11514 $keyExp, $hashKey, $flagValue,
11515 %hash,
11516 );
11517  
11518 # Check for improper arguments
11519 if (defined $check) {
11520  
11521 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11522 }
11523  
11524 # Get the values stored by $self->parse
11525 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11526 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11527 $expression = $self->ivShow('parseDataHash', 'expression');
11528 $keyExp = $self->ivShow('parseDataHash', 'extra_exp');
11529  
11530 # Evaluate the first expression to get the Axmud internal variable, e.g.
11531 # "current.world.name"
11532 $expValue = $expression->evaluate();
11533 # Process the string representing the Axmud internal variable
11534 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11535 = $self->scriptObj->session->parsePeekPoke($expValue);
11536 if (! $successFlag) {
11537  
11538 return $self->scriptObj->setError(
11539 'PEEKEXISTS_operation_failure',
11540 $self->_objClass . '->implement',
11541 );
11542 }
11543  
11544 # Evaluate the second expression to get a hash key, e.g. 'gold'
11545 $hashKey = $keyExp->evaluate();
11546  
11547 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11548 # or @array if $string refers to a list or hash value
11549 if (! $objFlag) {
11550  
11551 # This statement only accepts Perl hashes
11552 if (defined $var && ref($var) eq 'HASH') {
11553  
11554 %hash = %$var;
11555  
11556 } else {
11557  
11558 return $self->scriptObj->setError(
11559 'PEEKEXISTS_operation_expects_hash',
11560 $self->_objClass . '->implement',
11561 );
11562 }
11563  
11564 } else {
11565  
11566 return $self->scriptObj->setError(
11567 'PEEKEXISTS_cannot_import_object',
11568 $self->_objClass . '->implement',
11569 );
11570 }
11571  
11572 # Look up the LA::Variable
11573 $varObj = $self->fetchVar('PEEKEXISTS', $basicVarName, $parseArrayFlag);
11574 if (! $varObj) {
11575  
11576 # (self->scriptObj->setError already called)
11577 return undef;
11578 }
11579  
11580 # Now we can set the variable to PEEKEXISTS's return value
11581 if (! exists $hash{$hashKey}) {
11582  
11583 # $hashKey doesn't exist in the hash
11584 if (ref($varObj) =~ m/Numeric/) {
11585 $flagValue = 0;
11586 } else {
11587 $flagValue = 'false';
11588 }
11589  
11590 } else {
11591  
11592 # $hashKey does exist in the hash
11593 if (ref($varObj) =~ m/Numeric/) {
11594 $flagValue = 1;
11595 } else {
11596 $flagValue = 'true';
11597 }
11598 }
11599  
11600 if (! $parseArrayFlag) {
11601  
11602 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11603 # necessary
11604 $self->importAsScalar($varObj, $flagValue);
11605  
11606 } else {
11607  
11608 # Import the list/hash into an Axbasic array, resizing it as necessary
11609 $self->importAsArray($varObj, $flagValue);
11610 }
11611  
11612 # Implementation complete
11613 return 1;
11614 }
11615 }
11616  
11617 { package Language::Axbasic::Statement::peekfind;
11618  
11619 use strict;
11620 use warnings;
11621 # use diagnostics;
11622  
11623 use Glib qw(TRUE FALSE);
11624  
11625 @Language::Axbasic::Statement::peekfind::ISA = qw(
11626 Language::Axbasic
11627 Language::Axbasic::Statement
11628 );
11629  
11630 # PEEKFIND variable-name = axmud-object-property, expression
11631 # PEEKFIND ARRAY variable-name = axmud-object-property, expression
11632  
11633 ##################
11634 # Methods
11635  
11636 sub parse {
11637  
11638 # Called by LA::Line->parse directly after a call to LA::Statement->new
11639 #
11640 # Expected arguments
11641 # (none besides $self)
11642 #
11643 # Return values
11644 # 'undef' on improper arguments or if there is an error
11645 # 1 otherwise
11646  
11647 my ($self, $check) = @_;
11648  
11649 # Check for improper arguments
11650 if (defined $check) {
11651  
11652 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11653 }
11654  
11655 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11656 # $self->parseDataHash, ready for $self->implement to access
11657 if (! $self->parsePeek(FALSE, TRUE)) {
11658  
11659 # ($self->scriptObj->setError has already been called)
11660 return undef;
11661 }
11662  
11663 # Parsing complete
11664 return 1;
11665 }
11666  
11667 sub implement {
11668  
11669 # Called by LA::Line->implement directly after a call to $self->parse
11670 #
11671 # Expected arguments
11672 # (none besides $self)
11673 #
11674 # Return values
11675 # 'undef' on improper arguments or if there is an error
11676 # 1 otherwise
11677  
11678 my ($self, $check) = @_;
11679  
11680 # Local variables
11681 my (
11682 # Standard
11683 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11684 $var, $objFlag, $privFlag, $scalar, $varObj,
11685 @array,
11686 # Custom (set after $varObj is set)
11687 $matchExp, $match, $matchIndex,
11688 );
11689  
11690 # Check for improper arguments
11691 if (defined $check) {
11692  
11693 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11694 }
11695  
11696 # Get the values stored by $self->parse
11697 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11698 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11699 $expression = $self->ivShow('parseDataHash', 'expression');
11700 $matchExp = $self->ivShow('parseDataHash', 'extra_exp');
11701  
11702 # Evaluate the first expression to get the Axmud internal variable, e.g.
11703 # "current.world.name"
11704 $expValue = $expression->evaluate();
11705 # Evaluate the second expression to get a numeric/string value (allow 0, but not empty
11706 # strings)
11707 $match = $matchExp->evaluate();
11708 if (! defined $match || length($match) == 0) {
11709  
11710 return $self->scriptObj->setError(
11711 'invalid_matching_expression',
11712 $self->_objClass . '->implement',
11713 );
11714 }
11715  
11716 # Process the string representing the Axmud internal variable
11717 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11718 = $self->scriptObj->session->parsePeekPoke($expValue);
11719 if (! $successFlag) {
11720  
11721 return $self->scriptObj->setError(
11722 'PEEKFIND_operation_failure',
11723 $self->_objClass . '->implement',
11724 );
11725 }
11726  
11727 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11728 # or @array if $string refers to a list or hash value
11729 if (! $objFlag) {
11730  
11731 # This statement only accepts Perl scalars
11732 if (defined $var && ref($var) eq 'ARRAY') {
11733  
11734 @array = @$var;
11735  
11736 } else {
11737  
11738 return $self->scriptObj->setError(
11739 'PEEKFIND_operation_expects_list',
11740 $self->_objClass . '->implement',
11741 );
11742 }
11743  
11744 } else {
11745  
11746 return $self->scriptObj->setError(
11747 'PEEKFIND_cannot_import_object',
11748 $self->_objClass . '->implement',
11749 );
11750 }
11751  
11752 # Look up the LA::Variable
11753 $varObj = $self->fetchVar('PEEKFIND', $basicVarName, $parseArrayFlag);
11754 if (! $varObj) {
11755  
11756 # (self->scriptObj->setError already called)
11757 return undef;
11758 }
11759  
11760 # Now we can set the variable to PEEKFIND's return value
11761 # Assuming the array is not empty, walk the array looking for a value which is the same as
11762 # $match
11763 if (@array) {
11764  
11765 OUTER: for (my $count = 0; $count < scalar @array; $count++) {
11766  
11767 if (defined $array[$count] && $array[$count] eq $match) {
11768  
11769 # Matching value found at index $count
11770 $matchIndex = $count;
11771 last OUTER;
11772 }
11773 }
11774 }
11775  
11776 if (! defined $matchIndex) {
11777  
11778 # List is empty, or a matching value was not found
11779 $matchIndex = -1;
11780 }
11781  
11782 if (! $parseArrayFlag) {
11783  
11784 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11785 # necessary
11786 $self->importAsScalar($varObj, $matchIndex);
11787  
11788 } else {
11789  
11790 # Import the list/hash into an Axbasic array, resizing it as necessary
11791 $self->importAsArray($varObj, $matchIndex);
11792 }
11793  
11794 # Implementation complete
11795 return 1;
11796 }
11797 }
11798  
11799 { package Language::Axbasic::Statement::peekfirst;
11800  
11801 use strict;
11802 use warnings;
11803 # use diagnostics;
11804  
11805 use Glib qw(TRUE FALSE);
11806  
11807 @Language::Axbasic::Statement::peekfirst::ISA = qw(
11808 Language::Axbasic
11809 Language::Axbasic::Statement
11810 );
11811  
11812 # PEEKFIRST variable-name = axmud-object-property
11813 # PEEKFIRST ARRAY variable-name = axmud-object-property
11814  
11815 ##################
11816 # Methods
11817  
11818 sub parse {
11819  
11820 # Called by LA::Line->parse directly after a call to LA::Statement->new
11821 #
11822 # Expected arguments
11823 # (none besides $self)
11824 #
11825 # Return values
11826 # 'undef' on improper arguments or if there is an error
11827 # 1 otherwise
11828  
11829 my ($self, $check) = @_;
11830  
11831 # Check for improper arguments
11832 if (defined $check) {
11833  
11834 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
11835 }
11836  
11837 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
11838 # $self->parseDataHash, ready for $self->implement to access
11839 if (! $self->parsePeek()) {
11840  
11841 # ($self->scriptObj->setError has already been called)
11842 return undef;
11843 }
11844  
11845 # Parsing complete
11846 return 1;
11847 }
11848  
11849 sub implement {
11850  
11851 # Called by LA::Line->implement directly after a call to $self->parse
11852 #
11853 # Expected arguments
11854 # (none besides $self)
11855 #
11856 # Return values
11857 # 'undef' on improper arguments or if there is an error
11858 # 1 otherwise
11859  
11860 my ($self, $check) = @_;
11861  
11862 # Local variables
11863 my (
11864 # Standard
11865 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
11866 $var, $objFlag, $privFlag, $scalar, $varObj,
11867 @array,
11868 # Custom (set after $varObj is set)
11869 $elementValue,
11870 );
11871  
11872 # Check for improper arguments
11873 if (defined $check) {
11874  
11875 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
11876 }
11877  
11878 # Get the values stored by $self->parse
11879 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
11880 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
11881 $expression = $self->ivShow('parseDataHash', 'expression');
11882  
11883 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
11884 $expValue = $expression->evaluate();
11885 # Process the string representing the Axmud internal variable
11886 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
11887 = $self->scriptObj->session->parsePeekPoke($expValue);
11888 if (! $successFlag) {
11889  
11890 return $self->scriptObj->setError(
11891 'PEEKFIRST_operation_failure',
11892 $self->_objClass . '->implement',
11893 );
11894 }
11895  
11896 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
11897 # or @array if $string refers to a list or hash value
11898 if (! $objFlag) {
11899  
11900 # This statement only accepts Perl lists
11901 if (defined $var && ref($var) eq 'ARRAY') {
11902  
11903 @array = @$var;
11904  
11905 } else {
11906  
11907 return $self->scriptObj->setError(
11908 'PEEKFIRST_operation_expects_list',
11909 $self->_objClass . '->implement',
11910 );
11911 }
11912  
11913 } else {
11914  
11915 return $self->scriptObj->setError(
11916 'PEEKFIRST_cannot_import_object',
11917 $self->_objClass . '->implement',
11918 );
11919 }
11920  
11921 # Look up the LA::Variable
11922 $varObj = $self->fetchVar('PEEKFIRST', $basicVarName, $parseArrayFlag);
11923 if (! $varObj) {
11924  
11925 # (self->scriptObj->setError already called)
11926 return undef;
11927 }
11928  
11929 # Now we can set the variable to PEEKFIRST's return value
11930 if (! @array) {
11931  
11932 # If the array is empty, then PEEKFIRST's return value is 0 or an empty string
11933 if (ref($varObj) =~ m/Numeric/) {
11934 $elementValue = 0;
11935 } else {
11936 $elementValue = '';
11937 }
11938  
11939 } else {
11940  
11941 $elementValue = $array[0];
11942  
11943 # If the corresponding value is actually 'undef', PEEKFIRST's return value is 0 or the
11944 # string "<<undef>>"
11945 if (! defined $elementValue) {
11946  
11947 if (ref($varObj) =~ m/Numeric/) {
11948 $elementValue = 0;
11949 } else {
11950 $elementValue = '<<undef>>';
11951 }
11952 }
11953 }
11954  
11955 if (! $parseArrayFlag) {
11956  
11957 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
11958 # necessary
11959 $self->importAsScalar($varObj, $elementValue);
11960  
11961 } else {
11962  
11963 # Import the list/hash into an Axbasic array, resizing it as necessary
11964 $self->importAsArray($varObj, $elementValue);
11965 }
11966  
11967 # Implementation complete
11968 return 1;
11969 }
11970 }
11971  
11972 { package Language::Axbasic::Statement::peekget;
11973  
11974 use strict;
11975 use warnings;
11976 # use diagnostics;
11977  
11978 use Glib qw(TRUE FALSE);
11979  
11980 @Language::Axbasic::Statement::peekget::ISA = qw(
11981 Language::Axbasic
11982 Language::Axbasic::Statement
11983 );
11984  
11985 # PEEKGET variable-name = axmud-object-property
11986 # PEEKGET ARRAY variable-name = axmud-object-property
11987  
11988 ##################
11989 # Methods
11990  
11991 sub parse {
11992  
11993 # Called by LA::Line->parse directly after a call to LA::Statement->new
11994 #
11995 # Expected arguments
11996 # (none besides $self)
11997 #
11998 # Return values
11999 # 'undef' on improper arguments or if there is an error
12000 # 1 otherwise
12001  
12002 my ($self, $check) = @_;
12003  
12004 # Check for improper arguments
12005 if (defined $check) {
12006  
12007 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12008 }
12009  
12010 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12011 # $self->parseDataHash, ready for $self->implement to access
12012 if (! $self->parsePeek()) {
12013  
12014 # ($self->scriptObj->setError has already been called)
12015 return undef;
12016 }
12017  
12018 # Parsing complete
12019 return 1;
12020 }
12021  
12022 sub implement {
12023  
12024 # Called by LA::Line->implement directly after a call to $self->parse
12025 #
12026 # Expected arguments
12027 # (none besides $self)
12028 #
12029 # Return values
12030 # 'undef' on improper arguments or if there is an error
12031 # 1 otherwise
12032  
12033 my ($self, $check) = @_;
12034  
12035 # Local variables
12036 my (
12037 # Standard
12038 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12039 $var, $objFlag, $privFlag, $scalar, $varObj,
12040 @array,
12041 # Custom (set after $varObj is set)
12042 );
12043  
12044 # Check for improper arguments
12045 if (defined $check) {
12046  
12047 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12048 }
12049  
12050 # Get the values stored by $self->parse
12051 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12052 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12053 $expression = $self->ivShow('parseDataHash', 'expression');
12054  
12055 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12056 $expValue = $expression->evaluate();
12057 # Process the string representing the Axmud internal variable
12058 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12059 = $self->scriptObj->session->parsePeekPoke($expValue);
12060 if (! $successFlag) {
12061  
12062 return $self->scriptObj->setError(
12063 'PEEKGET_operation_failure',
12064 $self->_objClass . '->implement',
12065 );
12066 }
12067  
12068 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12069 # or @array if $string refers to a list or hash value
12070 if (! $objFlag) {
12071  
12072 # This statement only accepts Perl scalars
12073 if (! defined $var || (ref($var) ne 'ARRAY' && ref($var) ne 'HASH')) {
12074  
12075 $scalar = $var;
12076  
12077 # If this was a PEEKGET ARRAY statement, but the IV is a scalar, copy it into the
12078 # first cell of the Axbasic array (being an array containing 1 element)
12079 if ($parseArrayFlag) {
12080  
12081 push (@array, $scalar);
12082 }
12083  
12084 } else {
12085  
12086 return $self->scriptObj->setError(
12087 'PEEKGET_operation_expects_scalar',
12088 $self->_objClass . '->implement',
12089 );
12090 }
12091  
12092 } else {
12093  
12094 return $self->scriptObj->setError(
12095 'PEEKGET_cannot_import_object',
12096 $self->_objClass . '->implement',
12097 );
12098 }
12099  
12100 # Look up the LA::Variable
12101 $varObj = $self->fetchVar('PEEKGET', $basicVarName, $parseArrayFlag);
12102 if (! $varObj) {
12103  
12104 # (self->scriptObj->setError already called)
12105 return undef;
12106 }
12107  
12108 # Now we can set the variable to PEEKGET's return value
12109 if (! $parseArrayFlag) {
12110  
12111 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12112 # necessary
12113 $self->importAsScalar($varObj, $scalar);
12114  
12115 } else {
12116  
12117 # Import the list/hash into an Axbasic array, resizing it as necessary
12118 $self->importAsArray($varObj, @array);
12119 }
12120  
12121 # Implementation complete
12122 return 1;
12123 }
12124 }
12125  
12126 { package Language::Axbasic::Statement::peekindex;
12127  
12128 use strict;
12129 use warnings;
12130 # use diagnostics;
12131  
12132 use Glib qw(TRUE FALSE);
12133  
12134 @Language::Axbasic::Statement::peekindex::ISA = qw(
12135 Language::Axbasic
12136 Language::Axbasic::Statement
12137 );
12138  
12139 # PEEKINDEX variable-name = axmud-object-property, expression
12140 # PEEKINDEX ARRAY variable-name = axmud-object-property, expression
12141  
12142 ##################
12143 # Methods
12144  
12145 sub parse {
12146  
12147 # Called by LA::Line->parse directly after a call to LA::Statement->new
12148 #
12149 # Expected arguments
12150 # (none besides $self)
12151 #
12152 # Return values
12153 # 'undef' on improper arguments or if there is an error
12154 # 1 otherwise
12155  
12156 my ($self, $check) = @_;
12157  
12158 # Check for improper arguments
12159 if (defined $check) {
12160  
12161 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12162 }
12163  
12164 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12165 # $self->parseDataHash, ready for $self->implement to access
12166 if (! $self->parsePeek(FALSE, TRUE)) {
12167  
12168 # ($self->scriptObj->setError has already been called)
12169 return undef;
12170 }
12171  
12172 # Parsing complete
12173 return 1;
12174 }
12175  
12176 sub implement {
12177  
12178 # Called by LA::Line->implement directly after a call to $self->parse
12179 #
12180 # Expected arguments
12181 # (none besides $self)
12182 #
12183 # Return values
12184 # 'undef' on improper arguments or if there is an error
12185 # 1 otherwise
12186  
12187 my ($self, $check) = @_;
12188  
12189 # Local variables
12190 my (
12191 # Standard
12192 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12193 $var, $objFlag, $privFlag, $scalar, $varObj,
12194 @array,
12195 # Custom (set after $varObj is set)
12196 $indexExp, $index, $indexValue,
12197 );
12198  
12199 # Check for improper arguments
12200 if (defined $check) {
12201  
12202 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12203 }
12204  
12205 # Get the values stored by $self->parse
12206 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12207 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12208 $expression = $self->ivShow('parseDataHash', 'expression');
12209 $indexExp = $self->ivShow('parseDataHash', 'extra_exp');
12210  
12211 # Evaluate the first expression to get the Axmud internal variable, e.g.
12212 # "current.world.name"
12213 $expValue = $expression->evaluate();
12214 # Evaluate the second expression to get an index
12215 $index = $indexExp->evaluate();
12216 if (! defined $index || ! ($index =~ /^\d+$/) || $index < 0) {
12217  
12218 return $self->scriptObj->setError(
12219 'invalid_index_NUM',
12220 $self->_objClass . '->implement',
12221 'NUM', $index,
12222 );
12223 }
12224  
12225 # Process the string representing the Axmud internal variable
12226 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12227 = $self->scriptObj->session->parsePeekPoke($expValue);
12228 if (! $successFlag) {
12229  
12230 return $self->scriptObj->setError(
12231 'PEEKINDEX_operation_failure',
12232 $self->_objClass . '->implement',
12233 );
12234 }
12235  
12236 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12237 # or @array if $string refers to a list or hash value
12238 if (! $objFlag) {
12239  
12240 # This statement only accepts Perl scalars
12241 if (defined $var && ref($var) eq 'ARRAY') {
12242  
12243 @array = @$var;
12244  
12245 } else {
12246  
12247 return $self->scriptObj->setError(
12248 'PEEKINDEX_operation_expects_list',
12249 $self->_objClass . '->implement',
12250 );
12251 }
12252  
12253 } else {
12254  
12255 return $self->scriptObj->setError(
12256 'PEEKINDEX_cannot_import_object',
12257 $self->_objClass . '->implement',
12258 );
12259 }
12260  
12261 # Look up the LA::Variable
12262 $varObj = $self->fetchVar('PEEKINDEX', $basicVarName, $parseArrayFlag);
12263 if (! $varObj) {
12264  
12265 # (self->scriptObj->setError already called)
12266 return undef;
12267 }
12268  
12269 # Now we can set the variable to PEEKINDEX's return value.
12270 if ($index >= scalar @array) {
12271  
12272 # If $index is bigger than the array itself, then PEEKINDEX's return value is 0 or an
12273 # empty string
12274 if (ref($varObj) =~ m/Numeric/) {
12275 $indexValue = 0;
12276 } else {
12277 $indexValue = '';
12278 }
12279  
12280 } else {
12281  
12282 $indexValue = $array[$index];
12283  
12284 # If the corresponding value is actually 'undef', PEEKINDEX's return value is 0 or the
12285 # string "<<undef>>"
12286 if (! defined $indexValue) {
12287  
12288 if (ref($varObj) =~ m/Numeric/) {
12289 $indexValue = 0;
12290 } else {
12291 $indexValue = '<<undef>>';
12292 }
12293 }
12294 }
12295  
12296 if (! $parseArrayFlag) {
12297  
12298 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12299 # necessary
12300 $self->importAsScalar($varObj, $indexValue);
12301  
12302 } else {
12303  
12304 # Import the list/hash into an Axbasic array, resizing it as necessary
12305 $self->importAsArray($varObj, $indexValue);
12306 }
12307  
12308 # Implementation complete
12309 return 1;
12310 }
12311 }
12312  
12313 { package Language::Axbasic::Statement::peekkeys;
12314  
12315 use strict;
12316 use warnings;
12317 # use diagnostics;
12318  
12319 use Glib qw(TRUE FALSE);
12320  
12321 @Language::Axbasic::Statement::peekkeys::ISA = qw(
12322 Language::Axbasic
12323 Language::Axbasic::Statement
12324 );
12325  
12326 # PEEKKEYS variable-name = axmud-object-property
12327 # PEEKKEYS ARRAY variable-name = axmud-object-property
12328  
12329 ##################
12330 # Methods
12331  
12332 sub parse {
12333  
12334 # Called by LA::Line->parse directly after a call to LA::Statement->new
12335 #
12336 # Expected arguments
12337 # (none besides $self)
12338 #
12339 # Return values
12340 # 'undef' on improper arguments or if there is an error
12341 # 1 otherwise
12342  
12343 my ($self, $check) = @_;
12344  
12345 # Check for improper arguments
12346 if (defined $check) {
12347  
12348 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12349 }
12350  
12351 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12352 # $self->parseDataHash, ready for $self->implement to access
12353 if (! $self->parsePeek(TRUE, FALSE)) {
12354  
12355 # ($self->scriptObj->setError has already been called)
12356 return undef;
12357 }
12358  
12359 # Parsing complete
12360 return 1;
12361 }
12362  
12363 sub implement {
12364  
12365 # Called by LA::Line->implement directly after a call to $self->parse
12366 #
12367 # Expected arguments
12368 # (none besides $self)
12369 #
12370 # Return values
12371 # 'undef' on improper arguments or if there is an error
12372 # 1 otherwise
12373  
12374 my ($self, $check) = @_;
12375  
12376 # Local variables
12377 my (
12378 # Standard
12379 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12380 $var, $objFlag, $privFlag, $scalar, $varObj,
12381 @array,
12382 # Custom (set after $varObj is set)
12383 );
12384  
12385 # Check for improper arguments
12386 if (defined $check) {
12387  
12388 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12389 }
12390  
12391 # Get the values stored by $self->parse
12392 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12393 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12394 $expression = $self->ivShow('parseDataHash', 'expression');
12395  
12396 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12397 $expValue = $expression->evaluate();
12398 # Process the string representing the Axmud internal variable
12399 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12400 = $self->scriptObj->session->parsePeekPoke($expValue);
12401 if (! $successFlag) {
12402  
12403 return $self->scriptObj->setError(
12404 'PEEKKEYS_operation_failure',
12405 $self->_objClass . '->implement',
12406 );
12407 }
12408  
12409 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12410 # or @array if $string refers to a list or hash value
12411 if (! $objFlag) {
12412  
12413 # This statement only accepts Perl hashes
12414 if (defined $var && ref($var) eq 'HASH') {
12415  
12416 @array = keys %$var;
12417  
12418 } else {
12419  
12420 return $self->scriptObj->setError(
12421 'PEEKKEYS_operation_expects_hash',
12422 $self->_objClass . '->implement',
12423 );
12424 }
12425  
12426 } else {
12427  
12428 return $self->scriptObj->setError(
12429 'PEEKKEYS_cannot_import_object',
12430 $self->_objClass . '->implement',
12431 );
12432 }
12433  
12434 # Look up the LA::Variable
12435 $varObj = $self->fetchVar('PEEKKEYS', $basicVarName, TRUE);
12436 if (! $varObj) {
12437  
12438 # (self->scriptObj->setError already called)
12439 return undef;
12440 }
12441  
12442 # Now we can set the variable to PEEKKEYS's return values ($parseArrayFlag is definitely
12443 # TRUE)
12444 # Import the list/hash into an Axbasic array, resizing it as necessary
12445 $self->importAsArray($varObj, @array);
12446  
12447 # Implementation complete
12448 return 1;
12449 }
12450 }
12451  
12452 { package Language::Axbasic::Statement::peeklast;
12453  
12454 use strict;
12455 use warnings;
12456 # use diagnostics;
12457  
12458 use Glib qw(TRUE FALSE);
12459  
12460 @Language::Axbasic::Statement::peeklast::ISA = qw(
12461 Language::Axbasic
12462 Language::Axbasic::Statement
12463 );
12464  
12465 # PEEKLAST variable-name = axmud-object-property
12466 # PEEKLAST ARRAY variable-name = axmud-object-property
12467  
12468 ##################
12469 # Methods
12470  
12471 sub parse {
12472  
12473 # Called by LA::Line->parse directly after a call to LA::Statement->new
12474 #
12475 # Expected arguments
12476 # (none besides $self)
12477 #
12478 # Return values
12479 # 'undef' on improper arguments or if there is an error
12480 # 1 otherwise
12481  
12482 my ($self, $check) = @_;
12483  
12484 # Check for improper arguments
12485 if (defined $check) {
12486  
12487 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12488 }
12489  
12490 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12491 # $self->parseDataHash, ready for $self->implement to access
12492 if (! $self->parsePeek()) {
12493  
12494 # ($self->scriptObj->setError has already been called)
12495 return undef;
12496 }
12497  
12498 # Parsing complete
12499 return 1;
12500 }
12501  
12502 sub implement {
12503  
12504 # Called by LA::Line->implement directly after a call to $self->parse
12505 #
12506 # Expected arguments
12507 # (none besides $self)
12508 #
12509 # Return values
12510 # 'undef' on improper arguments or if there is an error
12511 # 1 otherwise
12512  
12513 my ($self, $check) = @_;
12514  
12515 # Local variables
12516 my (
12517 # Standard
12518 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12519 $var, $objFlag, $privFlag, $scalar, $varObj,
12520 @array,
12521 # Custom (set after $varObj is set)
12522 $lastIndex,
12523 );
12524  
12525 # Check for improper arguments
12526 if (defined $check) {
12527  
12528 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12529 }
12530  
12531 # Get the values stored by $self->parse
12532 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12533 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12534 $expression = $self->ivShow('parseDataHash', 'expression');
12535  
12536 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12537 $expValue = $expression->evaluate();
12538 # Process the string representing the Axmud internal variable
12539 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12540 = $self->scriptObj->session->parsePeekPoke($expValue);
12541 if (! $successFlag) {
12542  
12543 return $self->scriptObj->setError(
12544 'PEEKLAST_operation_failure',
12545 $self->_objClass . '->implement',
12546 );
12547 }
12548  
12549 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12550 # or @array if $string refers to a list or hash value
12551 if (! $objFlag) {
12552  
12553 # This statement only accepts Perl lists
12554 if (defined $var && ref($var) eq 'ARRAY') {
12555  
12556 @array = @$var;
12557  
12558 } else {
12559  
12560 return $self->scriptObj->setError(
12561 'PEEKLAST_operation_expects_list',
12562 $self->_objClass . '->implement',
12563 );
12564 }
12565  
12566 } else {
12567  
12568 return $self->scriptObj->setError(
12569 'PEEKLAST_cannot_import_object',
12570 $self->_objClass . '->implement',
12571 );
12572 }
12573  
12574 # Look up the LA::Variable
12575 $varObj = $self->fetchVar('PEEKLAST', $basicVarName, $parseArrayFlag);
12576 if (! $varObj) {
12577  
12578 # (self->scriptObj->setError already called)
12579 return undef;
12580 }
12581  
12582 # Now we can set the variable to PEEKLAST's return value. If the list is empty, we use the
12583 # value -1
12584 if (! @array) {
12585 $lastIndex = -1;
12586 } else {
12587 $lastIndex = (scalar @array) - 1;
12588 }
12589  
12590 if (! $parseArrayFlag) {
12591  
12592 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12593 # necessary
12594 $self->importAsScalar($varObj, $lastIndex);
12595  
12596 } else {
12597  
12598 # Import the list/hash into an Axbasic array, resizing it as necessary
12599 $self->importAsArray($varObj, $lastIndex);
12600 }
12601  
12602 # Implementation complete
12603 return 1;
12604 }
12605 }
12606  
12607 { package Language::Axbasic::Statement::peekmatch;
12608  
12609 use strict;
12610 use warnings;
12611 # use diagnostics;
12612  
12613 use Glib qw(TRUE FALSE);
12614  
12615 @Language::Axbasic::Statement::peekmatch::ISA = qw(
12616 Language::Axbasic
12617 Language::Axbasic::Statement
12618 );
12619  
12620 # PEEKMATCH variable-name = axmud-object-property, expression
12621 # PEEKMATCH ARRAY variable-name = axmud-object-property, expression
12622  
12623 ##################
12624 # Methods
12625  
12626 sub parse {
12627  
12628 # Called by LA::Line->parse directly after a call to LA::Statement->new
12629 #
12630 # Expected arguments
12631 # (none besides $self)
12632 #
12633 # Return values
12634 # 'undef' on improper arguments or if there is an error
12635 # 1 otherwise
12636  
12637 my ($self, $check) = @_;
12638  
12639 # Check for improper arguments
12640 if (defined $check) {
12641  
12642 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12643 }
12644  
12645 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12646 # $self->parseDataHash, ready for $self->implement to access
12647 if (! $self->parsePeek(FALSE, TRUE)) {
12648  
12649 # ($self->scriptObj->setError has already been called)
12650 return undef;
12651 }
12652  
12653 # Parsing complete
12654 return 1;
12655 }
12656  
12657 sub implement {
12658  
12659 # Called by LA::Line->implement directly after a call to $self->parse
12660 #
12661 # Expected arguments
12662 # (none besides $self)
12663 #
12664 # Return values
12665 # 'undef' on improper arguments or if there is an error
12666 # 1 otherwise
12667  
12668 my ($self, $check) = @_;
12669  
12670 # Local variables
12671 my (
12672 # Standard
12673 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12674 $var, $objFlag, $privFlag, $scalar, $varObj,
12675 @array,
12676 # Custom (set after $varObj is set)
12677 $regexExp, $regex, $matchIndex,
12678 );
12679  
12680 # Check for improper arguments
12681 if (defined $check) {
12682  
12683 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12684 }
12685  
12686 # Get the values stored by $self->parse
12687 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12688 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12689 $expression = $self->ivShow('parseDataHash', 'expression');
12690 $regexExp = $self->ivShow('parseDataHash', 'extra_exp');
12691  
12692 # Evaluate the first expression to get the Axmud internal variable, e.g.
12693 # "current.world.name"
12694 $expValue = $expression->evaluate();
12695 # Evaluate the second expression to get a regex
12696 $regex = $regexExp->evaluate();
12697 if (! $regex) {
12698  
12699 return $self->scriptObj->setError(
12700 'invalid_matching_expression',
12701 $self->_objClass . '->implement',
12702 );
12703 }
12704  
12705 # Process the string representing the Axmud internal variable
12706 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12707 = $self->scriptObj->session->parsePeekPoke($expValue);
12708 if (! $successFlag) {
12709  
12710 return $self->scriptObj->setError(
12711 'PEEKMATCH_operation_failure',
12712 $self->_objClass . '->implement',
12713 );
12714 }
12715  
12716 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12717 # or @array if $string refers to a list or hash value
12718 if (! $objFlag) {
12719  
12720 # This statement only accepts Perl scalars
12721 if (defined $var && ref($var) eq 'ARRAY') {
12722  
12723 @array = @$var;
12724  
12725 } else {
12726  
12727 return $self->scriptObj->setError(
12728 'PEEKMATCH_operation_expects_list',
12729 $self->_objClass . '->implement',
12730 );
12731 }
12732  
12733 } else {
12734  
12735 return $self->scriptObj->setError(
12736 'PEEKMATCH_cannot_import_object',
12737 $self->_objClass . '->implement',
12738 );
12739 }
12740  
12741 # Look up the LA::Variable
12742 $varObj = $self->fetchVar('PEEKMATCH', $basicVarName, $parseArrayFlag);
12743 if (! $varObj) {
12744  
12745 # (self->scriptObj->setError already called)
12746 return undef;
12747 }
12748  
12749 # Now we can set the variable to PEEKMATCH's return value
12750 # Assuming the array is not empty, walk the array looking for a value which matches the
12751 # regex
12752 if (@array) {
12753  
12754 OUTER: for (my $count = 0; $count < scalar @array; $count++) {
12755  
12756 if (defined $array[$count] && $array[$count] =~ m/$regex/) {
12757  
12758 # Matching value found at index $count
12759 $matchIndex = $count;
12760 last OUTER;
12761 }
12762 }
12763 }
12764  
12765 if (! defined $matchIndex) {
12766  
12767 # List is empty, or a matching value was not found
12768 $matchIndex = -1;
12769 }
12770  
12771 if (! $parseArrayFlag) {
12772  
12773 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12774 # necessary
12775 $self->importAsScalar($varObj, $matchIndex);
12776  
12777 } else {
12778  
12779 # Import the list/hash into an Axbasic array, resizing it as necessary
12780 $self->importAsArray($varObj, $matchIndex);
12781 }
12782  
12783 # Implementation complete
12784 return 1;
12785 }
12786 }
12787  
12788 { package Language::Axbasic::Statement::peeknumber;
12789  
12790 use strict;
12791 use warnings;
12792 # use diagnostics;
12793  
12794 use Glib qw(TRUE FALSE);
12795  
12796 @Language::Axbasic::Statement::peeknumber::ISA = qw(
12797 Language::Axbasic
12798 Language::Axbasic::Statement
12799 );
12800  
12801 # PEEKNUMBER variable-name = axmud-object-property
12802 # PEEKNUMBER ARRAY variable-name = axmud-object-property
12803  
12804 ##################
12805 # Methods
12806  
12807 sub parse {
12808  
12809 # Called by LA::Line->parse directly after a call to LA::Statement->new
12810 #
12811 # Expected arguments
12812 # (none besides $self)
12813 #
12814 # Return values
12815 # 'undef' on improper arguments or if there is an error
12816 # 1 otherwise
12817  
12818 my ($self, $check) = @_;
12819  
12820 # Check for improper arguments
12821 if (defined $check) {
12822  
12823 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12824 }
12825  
12826 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12827 # $self->parseDataHash, ready for $self->implement to access
12828 if (! $self->parsePeek()) {
12829  
12830 # ($self->scriptObj->setError has already been called)
12831 return undef;
12832 }
12833  
12834 # Parsing complete
12835 return 1;
12836 }
12837  
12838 sub implement {
12839  
12840 # Called by LA::Line->implement directly after a call to $self->parse
12841 #
12842 # Expected arguments
12843 # (none besides $self)
12844 #
12845 # Return values
12846 # 'undef' on improper arguments or if there is an error
12847 # 1 otherwise
12848  
12849 my ($self, $check) = @_;
12850  
12851 # Local variables
12852 my (
12853 # Standard
12854 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
12855 $var, $objFlag, $privFlag, $scalar, $varObj,
12856 @array,
12857 # Custom (set after $varObj is set)
12858 );
12859  
12860 # Check for improper arguments
12861 if (defined $check) {
12862  
12863 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
12864 }
12865  
12866 # Get the values stored by $self->parse
12867 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
12868 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
12869 $expression = $self->ivShow('parseDataHash', 'expression');
12870  
12871 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
12872 $expValue = $expression->evaluate();
12873 # Process the string representing the Axmud internal variable
12874 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
12875 = $self->scriptObj->session->parsePeekPoke($expValue);
12876 if (! $successFlag) {
12877  
12878 return $self->scriptObj->setError(
12879 'PEEKNUMBER_operation_failure',
12880 $self->_objClass . '->implement',
12881 );
12882 }
12883  
12884 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
12885 # or @array if $string refers to a list or hash value
12886 if (! $objFlag) {
12887  
12888 # This statement only accepts Perl lists
12889 if (defined $var && ref($var) eq 'ARRAY') {
12890  
12891 @array = @$var;
12892  
12893 } else {
12894  
12895 return $self->scriptObj->setError(
12896 'PEEKNUMBER_operation_expects_list',
12897 $self->_objClass . '->implement',
12898 );
12899 }
12900  
12901 } else {
12902  
12903 return $self->scriptObj->setError(
12904 'PEEKNUMBER_cannot_import_object',
12905 $self->_objClass . '->implement',
12906 );
12907 }
12908  
12909 # Look up the LA::Variable
12910 $varObj = $self->fetchVar('PEEKNUMBER', $basicVarName, $parseArrayFlag);
12911 if (! $varObj) {
12912  
12913 # (self->scriptObj->setError already called)
12914 return undef;
12915 }
12916  
12917 # Now we can set the variable to PEEKNUMBER's return value
12918 if (! $parseArrayFlag) {
12919  
12920 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
12921 # necessary
12922 $self->importAsScalar($varObj, scalar @array);
12923  
12924 } else {
12925  
12926 # Import the list/hash into an Axbasic array, resizing it as necessary
12927 $self->importAsArray($varObj, scalar @array);
12928 }
12929  
12930 # Implementation complete
12931 return 1;
12932 }
12933 }
12934  
12935 { package Language::Axbasic::Statement::peekpairs;
12936  
12937 use strict;
12938 use warnings;
12939 # use diagnostics;
12940  
12941 use Glib qw(TRUE FALSE);
12942  
12943 @Language::Axbasic::Statement::peekpairs::ISA = qw(
12944 Language::Axbasic
12945 Language::Axbasic::Statement
12946 );
12947  
12948 # PEEKPAIRS variable-name = axmud-object-property
12949 # PEEKPAIRS ARRAY variable-name = axmud-object-property
12950  
12951 ##################
12952 # Methods
12953  
12954 sub parse {
12955  
12956 # Called by LA::Line->parse directly after a call to LA::Statement->new
12957 #
12958 # Expected arguments
12959 # (none besides $self)
12960 #
12961 # Return values
12962 # 'undef' on improper arguments or if there is an error
12963 # 1 otherwise
12964  
12965 my ($self, $check) = @_;
12966  
12967 # Check for improper arguments
12968 if (defined $check) {
12969  
12970 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
12971 }
12972  
12973 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
12974 # $self->parseDataHash, ready for $self->implement to access
12975 if (! $self->parsePeek()) {
12976  
12977 # ($self->scriptObj->setError has already been called)
12978 return undef;
12979 }
12980  
12981 # Parsing complete
12982 return 1;
12983 }
12984  
12985 sub implement {
12986  
12987 # Called by LA::Line->implement directly after a call to $self->parse
12988 #
12989 # Expected arguments
12990 # (none besides $self)
12991 #
12992 # Return values
12993 # 'undef' on improper arguments or if there is an error
12994 # 1 otherwise
12995  
12996 my ($self, $check) = @_;
12997  
12998 # Local variables
12999 my (
13000 # Standard
13001 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
13002 $var, $objFlag, $privFlag, $scalar, $varObj,
13003 @array,
13004 # Custom (set after $varObj is set)
13005 %hash,
13006 );
13007  
13008 # Check for improper arguments
13009 if (defined $check) {
13010  
13011 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13012 }
13013  
13014 # Get the values stored by $self->parse
13015 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13016 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
13017 $expression = $self->ivShow('parseDataHash', 'expression');
13018  
13019 # Evaluate the first expression to get the Axmud internal variable, e.g.
13020 # "current.world.name"
13021 $expValue = $expression->evaluate();
13022 # Process the string representing the Axmud internal variable
13023 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13024 = $self->scriptObj->session->parsePeekPoke($expValue);
13025 if (! $successFlag) {
13026  
13027 return $self->scriptObj->setError(
13028 'PEEKPAIRS_operation_failure',
13029 $self->_objClass . '->implement',
13030 );
13031 }
13032  
13033 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
13034 # or @array if $string refers to a list or hash value
13035 if (! $objFlag) {
13036  
13037 # This statement only accepts Perl hashes
13038 if (defined $var && ref($var) eq 'HASH') {
13039  
13040 %hash = %$var;
13041  
13042 } else {
13043  
13044 return $self->scriptObj->setError(
13045 'PEEKPAIRS_operation_expects_hash',
13046 $self->_objClass . '->implement',
13047 );
13048 }
13049  
13050 } else {
13051  
13052 return $self->scriptObj->setError(
13053 'PEEKPAIRS_cannot_import_object',
13054 $self->_objClass . '->implement',
13055 );
13056 }
13057  
13058 # Look up the LA::Variable
13059 $varObj = $self->fetchVar('PEEKPAIRS', $basicVarName, $parseArrayFlag);
13060 if (! $varObj) {
13061  
13062 # (self->scriptObj->setError already called)
13063 return undef;
13064 }
13065  
13066 # Now we can set the variable to PEEKPAIRS's return value
13067 if (! $parseArrayFlag) {
13068  
13069 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
13070 # necessary
13071 $self->importAsScalar($varObj, scalar(keys %hash));
13072  
13073 } else {
13074  
13075 # Import the list/hash into an Axbasic array, resizing it as necessary
13076 $self->importAsArray($varObj, scalar(keys %hash));
13077 }
13078  
13079 # Implementation complete
13080 return 1;
13081 }
13082 }
13083  
13084 { package Language::Axbasic::Statement::peekshow;
13085  
13086 use strict;
13087 use warnings;
13088 # use diagnostics;
13089  
13090 use Glib qw(TRUE FALSE);
13091  
13092 @Language::Axbasic::Statement::peekshow::ISA = qw(
13093 Language::Axbasic
13094 Language::Axbasic::Statement
13095 );
13096  
13097 # PEEKSHOW variable-name = axmud-object-property, expression
13098 # PEEKSHOW ARRAY variable-name = axmud-object-property, expression
13099  
13100 ##################
13101 # Methods
13102  
13103 sub parse {
13104  
13105 # Called by LA::Line->parse directly after a call to LA::Statement->new
13106 #
13107 # Expected arguments
13108 # (none besides $self)
13109 #
13110 # Return values
13111 # 'undef' on improper arguments or if there is an error
13112 # 1 otherwise
13113  
13114 my ($self, $check) = @_;
13115  
13116 # Check for improper arguments
13117 if (defined $check) {
13118  
13119 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13120 }
13121  
13122 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
13123 # $self->parseDataHash, ready for $self->implement to access
13124 if (! $self->parsePeek(FALSE, TRUE)) {
13125  
13126 # ($self->scriptObj->setError has already been called)
13127 return undef;
13128 }
13129  
13130 # Parsing complete
13131 return 1;
13132 }
13133  
13134 sub implement {
13135  
13136 # Called by LA::Line->implement directly after a call to $self->parse
13137 #
13138 # Expected arguments
13139 # (none besides $self)
13140 #
13141 # Return values
13142 # 'undef' on improper arguments or if there is an error
13143 # 1 otherwise
13144  
13145 my ($self, $check) = @_;
13146  
13147 # Local variables
13148 my (
13149 # Standard
13150 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
13151 $var, $objFlag, $privFlag, $scalar, $varObj,
13152 @array,
13153 # Custom (set after $varObj is set)
13154 $keyExp, $hashKey, $hashValue,
13155 %hash,
13156 );
13157  
13158 # Check for improper arguments
13159 if (defined $check) {
13160  
13161 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13162 }
13163  
13164 # Get the values stored by $self->parse
13165 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13166 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
13167 $expression = $self->ivShow('parseDataHash', 'expression');
13168 $keyExp = $self->ivShow('parseDataHash', 'extra_exp');
13169  
13170 # Evaluate the first expression to get the Axmud internal variable, e.g.
13171 # "current.world.name"
13172 $expValue = $expression->evaluate();
13173 # Process the string representing the Axmud internal variable
13174 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13175 = $self->scriptObj->session->parsePeekPoke($expValue);
13176 if (! $successFlag) {
13177  
13178 return $self->scriptObj->setError(
13179 'PEEKSHOW_operation_failure',
13180 $self->_objClass . '->implement',
13181 );
13182 }
13183  
13184 # Evaluate the second expression to get a hash key, e.g. 'gold'
13185 $hashKey = $keyExp->evaluate();
13186  
13187 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
13188 # or @array if $string refers to a list or hash value
13189 if (! $objFlag) {
13190  
13191 # This statement only accepts Perl hashes
13192 if (defined $var && ref($var) eq 'HASH') {
13193  
13194 %hash = %$var;
13195  
13196 } else {
13197  
13198 return $self->scriptObj->setError(
13199 'PEEKSHOW_operation_expects_hash',
13200 $self->_objClass . '->implement',
13201 );
13202 }
13203  
13204 } else {
13205  
13206 return $self->scriptObj->setError(
13207 'PEEKSHOW_cannot_import_object',
13208 $self->_objClass . '->implement',
13209 );
13210 }
13211  
13212 # Look up the LA::Variable
13213 $varObj = $self->fetchVar('PEEKSHOW', $basicVarName, $parseArrayFlag);
13214 if (! $varObj) {
13215  
13216 # (self->scriptObj->setError already called)
13217 return undef;
13218 }
13219  
13220 # Now we can set the variable to PEEKSHOW's return values
13221 if (! exists $hash{$hashKey}) {
13222  
13223 # If $hashKey doesn't exist in the hash, then PEEKSHOW's return value is 0 or an empty
13224 # string
13225 if (ref($varObj) =~ m/Numeric/) {
13226 $hashValue = 0;
13227 } else {
13228 $hashValue = '';
13229 }
13230  
13231 } else {
13232  
13233 $hashValue = $hash{$hashKey};
13234  
13235 # If the corresponding value is actually 'undef', PEEKSHOW's return value is 0 or the
13236 # string "<<undef>>"
13237 if (! defined $hashValue) {
13238  
13239 # $hashKey's corresponding value might be 'undef', or the key might not exist in the
13240 # hash property at all. In both cases, PEEKSHOW's return value is 0 or an empty
13241 # string
13242 if (ref($varObj) =~ m/Numeric/) {
13243 $hashValue = 0;
13244 } else {
13245 $hashValue = '<<undef>>';
13246 }
13247 }
13248 }
13249  
13250 if (! $parseArrayFlag) {
13251  
13252 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
13253 # necessary
13254 $self->importAsScalar($varObj, $hashValue);
13255  
13256 } else {
13257  
13258 # Import the list/hash into an Axbasic array, resizing it as necessary
13259 $self->importAsArray($varObj, $hashValue);
13260 }
13261  
13262 # Implementation complete
13263 return 1;
13264 }
13265 }
13266  
13267 { package Language::Axbasic::Statement::peekvalues;
13268  
13269 use strict;
13270 use warnings;
13271 # use diagnostics;
13272  
13273 use Glib qw(TRUE FALSE);
13274  
13275 @Language::Axbasic::Statement::peekvalues::ISA = qw(
13276 Language::Axbasic
13277 Language::Axbasic::Statement
13278 );
13279  
13280 # PEEKVALUES variable-name = axmud-object-property
13281 # PEEKVALUES ARRAY variable-name = axmud-object-property
13282  
13283 ##################
13284 # Methods
13285  
13286 sub parse {
13287  
13288 # Called by LA::Line->parse directly after a call to LA::Statement->new
13289 #
13290 # Expected arguments
13291 # (none besides $self)
13292 #
13293 # Return values
13294 # 'undef' on improper arguments or if there is an error
13295 # 1 otherwise
13296  
13297 my ($self, $check) = @_;
13298  
13299 # Check for improper arguments
13300 if (defined $check) {
13301  
13302 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13303 }
13304  
13305 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
13306 # $self->parseDataHash, ready for $self->implement to access
13307 if (! $self->parsePeek(TRUE, FALSE)) {
13308  
13309 # ($self->scriptObj->setError has already been called)
13310 return undef;
13311 }
13312  
13313 # Parsing complete
13314 return 1;
13315 }
13316  
13317 sub implement {
13318  
13319 # Called by LA::Line->implement directly after a call to $self->parse
13320 #
13321 # Expected arguments
13322 # (none besides $self)
13323 #
13324 # Return values
13325 # 'undef' on improper arguments or if there is an error
13326 # 1 otherwise
13327  
13328 my ($self, $check) = @_;
13329  
13330 # Local variables
13331 my (
13332 # Standard
13333 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
13334 $var, $objFlag, $privFlag, $scalar, $varObj,
13335 @array,
13336 # Custom (set after $varObj is set)
13337 );
13338  
13339 # Check for improper arguments
13340 if (defined $check) {
13341  
13342 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13343 }
13344  
13345 # Get the values stored by $self->parse
13346 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13347 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
13348 $expression = $self->ivShow('parseDataHash', 'expression');
13349  
13350 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
13351 $expValue = $expression->evaluate();
13352 # Process the string representing the Axmud internal variable
13353 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13354 = $self->scriptObj->session->parsePeekPoke($expValue);
13355 if (! $successFlag) {
13356  
13357 return $self->scriptObj->setError(
13358 'PEEKVALUES_operation_failure',
13359 $self->_objClass . '->implement',
13360 );
13361 }
13362  
13363 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
13364 # or @array if $string refers to a list or hash value
13365 if (! $objFlag) {
13366  
13367 # This statement only accepts Perl hashes
13368 if (defined $var && ref($var) eq 'HASH') {
13369  
13370 @array = values %$var;
13371  
13372 } else {
13373  
13374 return $self->scriptObj->setError(
13375 'PEEKVALUES_operation_expects_hash',
13376 $self->_objClass . '->implement',
13377 );
13378 }
13379  
13380 } else {
13381  
13382 return $self->scriptObj->setError(
13383 'PEEKVALUES_cannot_import_object',
13384 $self->_objClass . '->implement',
13385 );
13386 }
13387  
13388 # Look up the LA::Variable
13389 $varObj = $self->fetchVar('PEEKVALUES', $basicVarName, TRUE);
13390 if (! $varObj) {
13391  
13392 # (self->scriptObj->setError already called)
13393 return undef;
13394 }
13395  
13396 # Now we can set the variable to PEEKVALUES's return values ($parseArrayFlag is definitely
13397 # TRUE)
13398 # Import the list/hash into an Axbasic array, resizing it as necessary
13399 $self->importAsArray($varObj, @array);
13400  
13401 # Implementation complete
13402 return 1;
13403 }
13404 }
13405  
13406 { package Language::Axbasic::Statement::perl;
13407  
13408 use strict;
13409 use warnings;
13410 # use diagnostics;
13411  
13412 use Glib qw(TRUE FALSE);
13413  
13414 @Language::Axbasic::Statement::perl::ISA = qw(
13415 Language::Axbasic
13416 Language::Axbasic::Statement
13417 );
13418  
13419 # PERL expression
13420  
13421 ##################
13422 # Methods
13423  
13424 sub parse {
13425  
13426 # Called by LA::Line->parse directly after a call to LA::Statement->new
13427 #
13428 # Expected arguments
13429 # (none besides $self)
13430 #
13431 # Return values
13432 # 'undef' on improper arguments or if there is an error
13433 # 1 otherwise
13434  
13435 my ($self, $check) = @_;
13436  
13437 # Local variables
13438 my $expression;
13439  
13440 # Check for improper arguments
13441 if (defined $check) {
13442  
13443 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13444 }
13445  
13446 # Get the expression and store it for ->implement to use
13447 $expression = Language::Axbasic::Expression::Arithmetic->new(
13448 $self->scriptObj,
13449 $self->tokenGroupObj,
13450 );
13451  
13452 if (! defined $expression) {
13453  
13454 return $self->scriptObj->setError(
13455 'missing_or_illegal_expression',
13456 $self->_objClass . '->parse',
13457 );
13458  
13459 } else {
13460  
13461 $self->ivAdd('parseDataHash', 'expression', $expression);
13462 }
13463  
13464 # There should be nothing after the expression
13465 if (! $self->tokenGroupObj->testStatementEnd()) {
13466  
13467 return $self->scriptObj->setError(
13468 'unexpected_keywords,_operators_or_expressions',
13469 $self->_objClass . '->parse',
13470 );
13471 }
13472  
13473 # Parsing complete
13474 return 1;
13475 }
13476  
13477 sub implement {
13478  
13479 # Called by LA::Line->implement directly after a call to $self->parse
13480 #
13481 # Expected arguments
13482 # (none besides $self)
13483 #
13484 # Return values
13485 # 'undef' on improper arguments or if there is an error
13486 # 1 otherwise
13487  
13488 my ($self, $check) = @_;
13489  
13490 # Local variables
13491 my ($expression, $string);
13492  
13493 # Check for improper arguments
13494 if (defined $check) {
13495  
13496 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13497 }
13498  
13499 # Retrieve the expression to be written
13500 $expression = $self->ivShow('parseDataHash', 'expression');
13501 # Evaluate the expression to get a scalar value
13502 $string = $expression->evaluate();
13503  
13504 # Run the expression as a Perl programme (using the Safe module)
13505 $self->scriptObj->session->perlCmd($string);
13506  
13507 # Implementation complete
13508 return 1;
13509 }
13510 }
13511  
13512 { package Language::Axbasic::Statement::play;
13513  
13514 use strict;
13515 use warnings;
13516 # use diagnostics;
13517  
13518 use Glib qw(TRUE FALSE);
13519  
13520 @Language::Axbasic::Statement::play::ISA = qw(
13521 Language::Axbasic
13522 Language::Axbasic::Statement
13523 );
13524  
13525 # PLAY expression
13526  
13527 ##################
13528 # Methods
13529  
13530 sub parse {
13531  
13532 # Called by LA::Line->parse directly after a call to LA::Statement->new
13533 #
13534 # Expected arguments
13535 # (none besides $self)
13536 #
13537 # Return values
13538 # 'undef' on improper arguments or if there is an error
13539 # 1 otherwise
13540  
13541 my ($self, $check) = @_;
13542  
13543 # Local variables
13544 my $expression;
13545  
13546 # Check for improper arguments
13547 if (defined $check) {
13548  
13549 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13550 }
13551  
13552 # Get the expression and store it for ->implement to use
13553 $expression = Language::Axbasic::Expression::Arithmetic->new(
13554 $self->scriptObj,
13555 $self->tokenGroupObj,
13556 );
13557  
13558 if (! defined $expression) {
13559  
13560 return $self->scriptObj->setError(
13561 'missing_or_illegal_expression',
13562 $self->_objClass . '->parse',
13563 );
13564  
13565 } else {
13566  
13567 $self->ivAdd('parseDataHash', 'expression', $expression);
13568 }
13569  
13570 # There should be nothing after the expression
13571 if (! $self->tokenGroupObj->testStatementEnd()) {
13572  
13573 return $self->scriptObj->setError(
13574 'unexpected_keywords,_operators_or_expressions',
13575 $self->_objClass . '->parse',
13576 );
13577 }
13578  
13579 # Parsing complete
13580 return 1;
13581 }
13582  
13583 sub implement {
13584  
13585 # Called by LA::Line->implement directly after a call to $self->parse
13586 #
13587 # Expected arguments
13588 # (none besides $self)
13589 #
13590 # Return values
13591 # 'undef' on improper arguments or if there is an error
13592 # 1 otherwise
13593  
13594 my ($self, $check) = @_;
13595  
13596 # Local variables
13597 my ($expression, $effect);
13598  
13599 # Check for improper arguments
13600 if (defined $check) {
13601  
13602 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13603 }
13604  
13605 # Retrieve the expression to be played
13606 $expression = $self->ivShow('parseDataHash', 'expression');
13607 # Evaluate the expression to get an Axmud sound effect
13608 $effect = $expression->evaluate();
13609  
13610 # Check that the sound effect exists
13611 if (
13612 ! $effect
13613 || ! $axmud::CLIENT->ivExists('customSoundHash', $effect)
13614 || ! $axmud::CLIENT->ivShow('customSoundHash', $effect)
13615 ) {
13616 return $self->scriptObj->setError(
13617 'sound_not_available',
13618 $self->_objClass . '->implement',
13619 );
13620  
13621 } else {
13622  
13623 # Play the sound effect (if allowed)
13624 $axmud::CLIENT->playSound($effect);
13625 }
13626  
13627 # Implementation complete
13628 return 1;
13629 }
13630 }
13631  
13632 { package Language::Axbasic::Statement::poke;
13633  
13634 use strict;
13635 use warnings;
13636 # use diagnostics;
13637  
13638 use Glib qw(TRUE FALSE);
13639  
13640 @Language::Axbasic::Statement::poke::ISA = qw(
13641 Language::Axbasic
13642 Language::Axbasic::Statement
13643 );
13644  
13645 # POKE axmud-object-property, expression
13646 # POKE axmud-object-property, variable-name
13647 # POKE ARRAY axmud-object-property, variable-name
13648  
13649 ##################
13650 # Methods
13651  
13652 sub parse {
13653  
13654 # Called by LA::Line->parse directly after a call to LA::Statement->new
13655 #
13656 # Expected arguments
13657 # (none besides $self)
13658 #
13659 # Return values
13660 # 'undef' on improper arguments or if there is an error
13661 # 1 otherwise
13662  
13663 my ($self, $check) = @_;
13664  
13665 # Local variables
13666 my ($token, $arrayFlag, $propExp, $varName, $varObj, $arithExp);
13667  
13668 # Check for improper arguments
13669 if (defined $check) {
13670  
13671 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13672 }
13673  
13674 # Extract the optional ARRAY keyword
13675 $token = $self->tokenGroupObj->shiftMatchingToken('array');
13676 if ($token) {
13677 $arrayFlag = TRUE;
13678 } else {
13679 $arrayFlag = FALSE;
13680 }
13681  
13682 # The first (compulsory) token is either an expression representing an Axmud internal
13683 # variable (a scalar, e.g. "current.world.name"; an array,
13684 # e.g. "current.world.statusFormatList"; or a hash, e.g. "current.world.currencyHash")
13685 $token = $self->tokenGroupObj->lookAhead();
13686 if (! defined $token) {
13687  
13688 return $self->scriptObj->setError(
13689 'syntax_error',
13690 $self->_objClass . '->parse',
13691 );
13692  
13693 } else {
13694  
13695 $propExp = Language::Axbasic::Expression::Arithmetic->new(
13696 $self->scriptObj,
13697 $self->tokenGroupObj,
13698 );
13699  
13700 if (! defined $propExp) {
13701  
13702 return $self->scriptObj->setError(
13703 'missing_or_illegal_expression',
13704 $self->_objClass . '->parse',
13705 );
13706 }
13707 }
13708  
13709 # Extract the comma
13710 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
13711  
13712 return $self->scriptObj->setError(
13713 'syntax_error',
13714 $self->_objClass . '->parse',
13715 );
13716 }
13717  
13718 # The second expression can be either a scalar variable, array or just a normal expression
13719 # Extract a token comprising a whole variable identifier (e.g. A, a$, array), if present
13720 $token = $self->tokenGroupObj->shiftTokenIfCategory('identifier');
13721 if ($token) {
13722  
13723 $varName = $token->tokenText;
13724  
13725 # Look up the LA::Variable. Use the local variable, if it exists. Otherwise use the
13726 # global variable, if it exists
13727 if (! $arrayFlag) {
13728  
13729 $varObj = Language::Axbasic::Variable->lookup($self->scriptObj, $varName);
13730  
13731 } else {
13732  
13733 # If it's an array, ->lookup expects a LA::Expression::Arglist; but we only need to
13734 # supply it with a defined value
13735 $varObj = Language::Axbasic::Variable->lookup(
13736 $self->scriptObj,
13737 $varName,
13738 'fake_arg_list'
13739 );
13740 }
13741  
13742 if (! $varObj) {
13743  
13744 # This shouldn't happen...
13745 return $self->scriptObj->setError(
13746 'syntax_error',
13747 $self->_objClass . '->parse',
13748 );
13749 }
13750  
13751 # Identifier not present, so extract a normal expression instead (but not in POKE ARRAY
13752 # statements)
13753 } elsif (! $arrayFlag) {
13754  
13755 $token = $self->tokenGroupObj->lookAhead();
13756 if (! defined $token) {
13757  
13758 return $self->scriptObj->setError(
13759 'syntax_error',
13760 $self->_objClass . '->parse',
13761 );
13762  
13763 } else {
13764  
13765 $arithExp = Language::Axbasic::Expression::Arithmetic->new(
13766 $self->scriptObj,
13767 $self->tokenGroupObj,
13768 );
13769  
13770 if (! defined $arithExp) {
13771  
13772 return $self->scriptObj->setError(
13773 'missing_or_illegal_expression',
13774 $self->_objClass . '->parse',
13775 );
13776 }
13777 }
13778  
13779 } else {
13780  
13781 return $self->scriptObj->setError(
13782 'syntax_error',
13783 $self->_objClass . '->parse',
13784 );
13785 }
13786  
13787 # There are no further expressions to extract
13788 if (! $self->tokenGroupObj->testStatementEnd()) {
13789  
13790 return $self->scriptObj->setError(
13791 'unexpected_keywords,_operators_or_expressions',
13792 $self->_objClass . '->parse',
13793 );
13794 }
13795  
13796 # Save the expressions so $self->implement can use them, if it is called
13797 $self->ivAdd('parseDataHash', 'array_flag', $arrayFlag);
13798 $self->ivAdd('parseDataHash', 'prop_exp', $propExp);
13799 $self->ivAdd('parseDataHash', 'var_name', $varName);
13800 $self->ivAdd('parseDataHash', 'var_obj', $varObj);
13801 $self->ivAdd('parseDataHash', 'arith_exp', $arithExp);
13802  
13803 # Parsing complete
13804 return 1;
13805 }
13806  
13807 sub implement {
13808  
13809 # Called by LA::Line->implement directly after a call to $self->parse
13810 #
13811 # Expected arguments
13812 # (none besides $self)
13813 #
13814 # Return values
13815 # 'undef' on improper arguments or if there is an error
13816 # 1 otherwise
13817  
13818 my ($self, $check) = @_;
13819  
13820 # Local variables
13821 my (
13822 $parseArrayFlag, $propExp, $internalVar, $varName, $varObj, $arithExp, $arithValue,
13823 $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
13824 @cellList, @valueList,
13825 );
13826  
13827 # Check for improper arguments
13828 if (defined $check) {
13829  
13830 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13831 }
13832  
13833 # Get the values stored by $self->parse
13834 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
13835 $propExp = $self->ivShow('parseDataHash', 'prop_exp');
13836 $varName = $self->ivShow('parseDataHash', 'var_name');
13837 $varObj = $self->ivShow('parseDataHash', 'var_obj');
13838 $arithExp = $self->ivShow('parseDataHash', 'arith_exp');
13839  
13840 # Evaluate the first expression to get the Axmud internal variable, e.g.
13841 # "current.world.name"
13842 $internalVar = $propExp->evaluate();
13843 # Evaluate the optional arithmetic expression, if set
13844 if (defined $arithExp) {
13845  
13846 $arithValue = $arithExp->evaluate();
13847 }
13848  
13849 # Process the string representing the Axmud internal variable
13850 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
13851 = $self->scriptObj->session->parsePeekPoke($internalVar);
13852 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
13853  
13854 return $self->scriptObj->setError(
13855 'POKE_operation_failure',
13856 $self->_objClass . '->implement',
13857 );
13858  
13859 } elsif ($objFlag) {
13860  
13861 return $self->scriptObj->setError(
13862 'POKE_cannot_export_to_object',
13863 $self->_objClass . '->implement',
13864 );
13865 }
13866  
13867 # POKE ARRAY statements require an Axmud list or hash property
13868 if (
13869 $parseArrayFlag
13870 && (! defined $var || (ref($var) ne 'ARRAY' && ref($var) eq 'HASH'))
13871 ) {
13872 return $self->scriptObj->setError(
13873 'POKE_ARRAY_operation_expects_list_or_hash', # Yes, POKE_ARRAY not POKE
13874 $self->_objClass . '->implement',
13875 );
13876 }
13877  
13878 # Perform the POKE operation
13879 # If the user specified an arithmetic expression, use it
13880 if (defined $arithExp) {
13881  
13882 $blessed->ivPoke($ivName, $arithValue);
13883  
13884 # Otherwise, use the specified variable
13885 } else {
13886  
13887 if (! $parseArrayFlag) {
13888  
13889 $blessed->ivPoke($ivName, $varObj->value);
13890  
13891 } else {
13892  
13893 @cellList = $varObj->cellList;
13894 # Take account of the first item in ->cellList, which is the lower bound
13895 shift @cellList;
13896  
13897 foreach my $arrayVar (@cellList) {
13898  
13899 push (@valueList, $arrayVar->value());
13900 }
13901  
13902 $blessed->ivPoke($ivName, @valueList);
13903 }
13904 }
13905  
13906 # Implementation complete
13907 return 1;
13908 }
13909 }
13910  
13911 { package Language::Axbasic::Statement::pokeadd;
13912  
13913 use strict;
13914 use warnings;
13915 # use diagnostics;
13916  
13917 use Glib qw(TRUE FALSE);
13918  
13919 @Language::Axbasic::Statement::pokeadd::ISA = qw(
13920 Language::Axbasic
13921 Language::Axbasic::Statement
13922 );
13923  
13924 # POKEADD axmud-object-property, expression, expression
13925 # POKEADD axmud-object-property, expression
13926  
13927 ##################
13928 # Methods
13929  
13930 sub parse {
13931  
13932 # Called by LA::Line->parse directly after a call to LA::Statement->new
13933 #
13934 # Expected arguments
13935 # (none besides $self)
13936 #
13937 # Return values
13938 # 'undef' on improper arguments or if there is an error
13939 # 1 otherwise
13940  
13941 my ($self, $check) = @_;
13942  
13943 # Check for improper arguments
13944 if (defined $check) {
13945  
13946 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
13947 }
13948  
13949 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
13950 # ready for $self->implement to access
13951 if (! $self->parsePoke(1, 2)) {
13952  
13953 # ($self->scriptObj->setError has already been called)
13954 return undef;
13955 }
13956  
13957 # Parsing complete
13958 return 1;
13959 }
13960  
13961 sub implement {
13962  
13963 # Called by LA::Line->implement directly after a call to $self->parse
13964 #
13965 # Expected arguments
13966 # (none besides $self)
13967 #
13968 # Return values
13969 # 'undef' on improper arguments or if there is an error
13970 # 1 otherwise
13971  
13972 my ($self, $check) = @_;
13973  
13974 # Local variables
13975 my (
13976 # Standard
13977 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
13978 # Custom
13979 $keyExp, $key, $valueExp, $value,
13980 );
13981  
13982 # Check for improper arguments
13983 if (defined $check) {
13984  
13985 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
13986 }
13987  
13988 # Get the values stored by $self->parse
13989 $varExp = $self->ivShow('parseDataHash', 'var_exp');
13990 $keyExp = $self->ivShift('parseDataList');
13991 $valueExp = $self->ivShift('parseDataList');
13992  
13993 # Evaluate the first expression to get the Axmud internal variable, e.g.
13994 # "current.world.name"
13995 $internalVar = $varExp->evaluate();
13996 # Evaluate the other expressions
13997 $key = $keyExp->evaluate();
13998 if (defined $valueExp) {
13999  
14000 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
14001 $value = $valueExp->evaluate();
14002 }
14003  
14004 # Process the string representing the Axmud internal variable
14005 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14006 = $self->scriptObj->session->parsePeekPoke($internalVar);
14007 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14008  
14009 return $self->scriptObj->setError(
14010 'POKEADD_operation_failure',
14011 $self->_objClass . '->implement',
14012 );
14013  
14014 } elsif ($objFlag) {
14015  
14016 return $self->scriptObj->setError(
14017 'POKEADD_cannot_export_to_object',
14018 $self->_objClass . '->implement',
14019 );
14020 }
14021  
14022 # This statement only accepts Perl hashes
14023 if (! defined $var || ref($var) ne 'HASH') {
14024  
14025 return $self->scriptObj->setError(
14026 'POKEADD_operation_expects_hash',
14027 $self->_objClass . '->implement',
14028 );
14029 }
14030  
14031 # Perform the POKEADD operation. If the minimum number of expressions was specified, $value
14032 # is 'undef'
14033 $blessed->ivAdd($ivName, $key, $value);
14034  
14035 # Implementation complete
14036 return 1;
14037 }
14038 }
14039  
14040 { package Language::Axbasic::Statement::pokedec;
14041  
14042 use strict;
14043 use warnings;
14044 # use diagnostics;
14045  
14046 use Glib qw(TRUE FALSE);
14047  
14048 @Language::Axbasic::Statement::pokedec::ISA = qw(
14049 Language::Axbasic
14050 Language::Axbasic::Statement
14051 );
14052  
14053 # POKEDEC axmud-object-property
14054  
14055 ##################
14056 # Methods
14057  
14058 sub parse {
14059  
14060 # Called by LA::Line->parse directly after a call to LA::Statement->new
14061 #
14062 # Expected arguments
14063 # (none besides $self)
14064 #
14065 # Return values
14066 # 'undef' on improper arguments or if there is an error
14067 # 1 otherwise
14068  
14069 my ($self, $check) = @_;
14070  
14071 # Check for improper arguments
14072 if (defined $check) {
14073  
14074 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14075 }
14076  
14077 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14078 # ready for $self->implement to access
14079 if (! $self->parsePoke(0)) {
14080  
14081 # ($self->scriptObj->setError has already been called)
14082 return undef;
14083 }
14084  
14085 # Parsing complete
14086 return 1;
14087 }
14088  
14089 sub implement {
14090  
14091 # Called by LA::Line->implement directly after a call to $self->parse
14092 #
14093 # Expected arguments
14094 # (none besides $self)
14095 #
14096 # Return values
14097 # 'undef' on improper arguments or if there is an error
14098 # 1 otherwise
14099  
14100 my ($self, $check) = @_;
14101  
14102 # Local variables
14103 my (
14104 # Standard
14105 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14106 # Custom
14107 );
14108  
14109 # Check for improper arguments
14110 if (defined $check) {
14111  
14112 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14113 }
14114  
14115 # Get the values stored by $self->parse
14116 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14117  
14118 # Evaluate the first expression to get the Axmud internal variable, e.g.
14119 # "current.world.name"
14120 $internalVar = $varExp->evaluate();
14121  
14122 # Process the string representing the Axmud internal variable
14123 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14124 = $self->scriptObj->session->parsePeekPoke($internalVar);
14125 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14126  
14127 return $self->scriptObj->setError(
14128 'POKEDEC_operation_failure',
14129 $self->_objClass . '->implement',
14130 );
14131  
14132 } elsif ($objFlag) {
14133  
14134 return $self->scriptObj->setError(
14135 'POKEDEC_cannot_export_to_object',
14136 $self->_objClass . '->implement',
14137 );
14138 }
14139  
14140 # This statement only accepts Perl scalars whose values are integers
14141 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14142  
14143 return $self->scriptObj->setError(
14144 'POKEDEC_operation_expects_scalar',
14145 $self->_objClass . '->implement',
14146 );
14147 }
14148  
14149 if (! defined $blessed->$ivName || $blessed->$ivName =~ m/\D/) {
14150  
14151 return $self->scriptObj->setError(
14152 'POKEDEC_operation_expects_integer',
14153 $self->_objClass . '->implement',
14154 );
14155 }
14156  
14157 # Perform the POKEDEC operation
14158 $blessed->ivDecrement($ivName);
14159  
14160 # Implementation complete
14161 return 1;
14162 }
14163 }
14164  
14165 { package Language::Axbasic::Statement::pokedechash;
14166  
14167 use strict;
14168 use warnings;
14169 # use diagnostics;
14170  
14171 use Glib qw(TRUE FALSE);
14172  
14173 @Language::Axbasic::Statement::pokedechash::ISA = qw(
14174 Language::Axbasic
14175 Language::Axbasic::Statement
14176 );
14177  
14178 # POKEDECHASH axmud-object-property, expression
14179  
14180 ##################
14181 # Methods
14182  
14183 sub parse {
14184  
14185 # Called by LA::Line->parse directly after a call to LA::Statement->new
14186 #
14187 # Expected arguments
14188 # (none besides $self)
14189 #
14190 # Return values
14191 # 'undef' on improper arguments or if there is an error
14192 # 1 otherwise
14193  
14194 my ($self, $check) = @_;
14195  
14196 # Check for improper arguments
14197 if (defined $check) {
14198  
14199 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14200 }
14201  
14202 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14203 # ready for $self->implement to access
14204 if (! $self->parsePoke(1)) {
14205  
14206 # ($self->scriptObj->setError has already been called)
14207 return undef;
14208 }
14209  
14210 # Parsing complete
14211 return 1;
14212 }
14213  
14214 sub implement {
14215  
14216 # Called by LA::Line->implement directly after a call to $self->parse
14217 #
14218 # Expected arguments
14219 # (none besides $self)
14220 #
14221 # Return values
14222 # 'undef' on improper arguments or if there is an error
14223 # 1 otherwise
14224  
14225 my ($self, $check) = @_;
14226  
14227 # Local variables
14228 my (
14229 # Standard
14230 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14231 # Custom
14232 $keyExp, $key, $keyValue,
14233 );
14234  
14235 # Check for improper arguments
14236 if (defined $check) {
14237  
14238 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14239 }
14240  
14241 # Get the values stored by $self->parse
14242 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14243 $keyExp = $self->ivShift('parseDataList');
14244  
14245 # Evaluate the first expression to get the Axmud internal variable, e.g.
14246 # "current.world.name"
14247 $internalVar = $varExp->evaluate();
14248 # Evaluate the other expressions
14249 $key = $keyExp->evaluate();
14250  
14251 # Process the string representing the Axmud internal variable
14252 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14253 = $self->scriptObj->session->parsePeekPoke($internalVar);
14254 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14255  
14256 return $self->scriptObj->setError(
14257 'POKEDECHASH_operation_failure',
14258 $self->_objClass . '->implement',
14259 );
14260  
14261 } elsif ($objFlag) {
14262  
14263 return $self->scriptObj->setError(
14264 'POKEDECHASH_cannot_export_to_object',
14265 $self->_objClass . '->implement',
14266 );
14267 }
14268  
14269 # This statement only accepts Perl hashes
14270 if (! defined $var || ref($var) ne 'HASH') {
14271  
14272 return $self->scriptObj->setError(
14273 'POKEDECHASH_operation_expects_hash',
14274 $self->_objClass . '->implement',
14275 );
14276 }
14277  
14278 # The key must exist in the hash, and its corresponding value must be an integer
14279 if (! $blessed->ivExists($ivName, $key)) {
14280  
14281 return $self->scriptObj->setError(
14282 'POKEDECHASH_key_not_found',
14283 $self->_objClass . '->implement',
14284 );
14285 }
14286  
14287 $keyValue = $blessed->ivShow($ivName, $key);
14288 if (! defined $keyValue || $keyValue =~ m/\D/) {
14289  
14290 return $self->scriptObj->setError(
14291 'POKEDECHASH_operation_expects_integer',
14292 $self->_objClass . '->implement',
14293 );
14294 }
14295  
14296 # Perform the POKEDECHASH operation
14297 $blessed->ivDecHash($ivName, $key);
14298  
14299 # Implementation complete
14300 return 1;
14301 }
14302 }
14303  
14304 { package Language::Axbasic::Statement::pokedelete;
14305  
14306 use strict;
14307 use warnings;
14308 # use diagnostics;
14309  
14310 use Glib qw(TRUE FALSE);
14311  
14312 @Language::Axbasic::Statement::pokedelete::ISA = qw(
14313 Language::Axbasic
14314 Language::Axbasic::Statement
14315 );
14316  
14317 # POKEDELETE axmud-object-property, expression
14318  
14319 ##################
14320 # Methods
14321  
14322 sub parse {
14323  
14324 # Called by LA::Line->parse directly after a call to LA::Statement->new
14325 #
14326 # Expected arguments
14327 # (none besides $self)
14328 #
14329 # Return values
14330 # 'undef' on improper arguments or if there is an error
14331 # 1 otherwise
14332  
14333 my ($self, $check) = @_;
14334  
14335 # Check for improper arguments
14336 if (defined $check) {
14337  
14338 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14339 }
14340  
14341 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14342 # ready for $self->implement to access
14343 if (! $self->parsePoke(1)) {
14344  
14345 # ($self->scriptObj->setError has already been called)
14346 return undef;
14347 }
14348  
14349 # Parsing complete
14350 return 1;
14351 }
14352  
14353 sub implement {
14354  
14355 # Called by LA::Line->implement directly after a call to $self->parse
14356 #
14357 # Expected arguments
14358 # (none besides $self)
14359 #
14360 # Return values
14361 # 'undef' on improper arguments or if there is an error
14362 # 1 otherwise
14363  
14364 my ($self, $check) = @_;
14365  
14366 # Local variables
14367 my (
14368 # Standard
14369 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14370 # Custom
14371 $keyExp, $key,
14372 );
14373  
14374 # Check for improper arguments
14375 if (defined $check) {
14376  
14377 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14378 }
14379  
14380 # Get the values stored by $self->parse
14381 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14382 $keyExp = $self->ivShift('parseDataList');
14383  
14384 # Evaluate the first expression to get the Axmud internal variable, e.g.
14385 # "current.world.name"
14386 $internalVar = $varExp->evaluate();
14387 # Evaluate the other expressions
14388 $key = $keyExp->evaluate();
14389  
14390 # Process the string representing the Axmud internal variable
14391 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14392 = $self->scriptObj->session->parsePeekPoke($internalVar);
14393 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14394  
14395 return $self->scriptObj->setError(
14396 'POKEDELETE_operation_failure',
14397 $self->_objClass . '->implement',
14398 );
14399  
14400 } elsif ($objFlag) {
14401  
14402 return $self->scriptObj->setError(
14403 'POKEDELETE_cannot_export_to_object',
14404 $self->_objClass . '->implement',
14405 );
14406 }
14407  
14408 # This statement only accepts Perl hashes
14409 if (! defined $var || ref($var) ne 'HASH') {
14410  
14411 return $self->scriptObj->setError(
14412 'POKEDELETE_operation_expects_hash',
14413 $self->_objClass . '->implement',
14414 );
14415 }
14416  
14417 # The key must exist in the hash
14418 if (! $blessed->ivExists($ivName, $key)) {
14419  
14420 return $self->scriptObj->setError(
14421 'POKEDELETE_key_not_found',
14422 $self->_objClass . '->implement',
14423 );
14424 }
14425  
14426 # Perform the POKEDELETE operation
14427 $blessed->ivDelete($ivName, $key);
14428  
14429 # Implementation complete
14430 return 1;
14431 }
14432 }
14433  
14434 { package Language::Axbasic::Statement::pokedivide;
14435  
14436 use strict;
14437 use warnings;
14438 # use diagnostics;
14439  
14440 use Glib qw(TRUE FALSE);
14441  
14442 @Language::Axbasic::Statement::pokedivide::ISA = qw(
14443 Language::Axbasic
14444 Language::Axbasic::Statement
14445 );
14446  
14447 # POKEDIVIDE axmud-object-property, expression
14448  
14449 ##################
14450 # Methods
14451  
14452 sub parse {
14453  
14454 # Called by LA::Line->parse directly after a call to LA::Statement->new
14455 #
14456 # Expected arguments
14457 # (none besides $self)
14458 #
14459 # Return values
14460 # 'undef' on improper arguments or if there is an error
14461 # 1 otherwise
14462  
14463 my ($self, $check) = @_;
14464  
14465 # Check for improper arguments
14466 if (defined $check) {
14467  
14468 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14469 }
14470  
14471 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14472 # ready for $self->implement to access
14473 if (! $self->parsePoke(1)) {
14474  
14475 # ($self->scriptObj->setError has already been called)
14476 return undef;
14477 }
14478  
14479 # Parsing complete
14480 return 1;
14481 }
14482  
14483 sub implement {
14484  
14485 # Called by LA::Line->implement directly after a call to $self->parse
14486 #
14487 # Expected arguments
14488 # (none besides $self)
14489 #
14490 # Return values
14491 # 'undef' on improper arguments or if there is an error
14492 # 1 otherwise
14493  
14494 my ($self, $check) = @_;
14495  
14496 # Local variables
14497 my (
14498 # Standard
14499 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14500 # Custom
14501 $valueExp, $value,
14502 );
14503  
14504 # Check for improper arguments
14505 if (defined $check) {
14506  
14507 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14508 }
14509  
14510 # Get the values stored by $self->parse
14511 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14512 $valueExp = $self->ivShift('parseDataList');
14513  
14514 # Evaluate the first expression to get the Axmud internal variable, e.g.
14515 # "current.world.name"
14516 $internalVar = $varExp->evaluate();
14517 # Evaluate the other expressions
14518 $value = $valueExp->evaluate();
14519 # The value of the expression must be a non-zero number
14520 if (
14521 ! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
14522 || $value == 0
14523 ) {
14524 return $self->scriptObj->setError(
14525 'invalid_expression_in_POKEDIVIDE_statement',
14526 $self->_objClass . '->implement',
14527 );
14528 }
14529  
14530 # Process the string representing the Axmud internal variable
14531 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14532 = $self->scriptObj->session->parsePeekPoke($internalVar);
14533 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14534  
14535 return $self->scriptObj->setError(
14536 'POKEDIVIDE_operation_failure',
14537 $self->_objClass . '->implement',
14538 );
14539  
14540 } elsif ($objFlag) {
14541  
14542 return $self->scriptObj->setError(
14543 'POKEDIVIDE_cannot_export_to_object',
14544 $self->_objClass . '->implement',
14545 );
14546 }
14547  
14548 # This statement only accepts Perl scalars whose values are numbers
14549 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14550  
14551 return $self->scriptObj->setError(
14552 'POKEDIVIDE_operation_expects_scalar',
14553 $self->_objClass . '->implement',
14554 );
14555 }
14556  
14557 if (
14558 ! defined $blessed->$ivName
14559 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
14560 ) {
14561 return $self->scriptObj->setError(
14562 'POKEDIVIDE_operation_expects_numeric',
14563 $self->_objClass . '->implement',
14564 );
14565 }
14566  
14567 # Perform the POKEDIVIDE operation
14568 $blessed->ivDivide($ivName, $value);
14569  
14570 # Implementation complete
14571 return 1;
14572 }
14573 }
14574  
14575 { package Language::Axbasic::Statement::pokeempty;
14576  
14577 use strict;
14578 use warnings;
14579 # use diagnostics;
14580  
14581 use Glib qw(TRUE FALSE);
14582  
14583 @Language::Axbasic::Statement::pokeempty::ISA = qw(
14584 Language::Axbasic
14585 Language::Axbasic::Statement
14586 );
14587  
14588 # POKEEMPTY axmud-object-property
14589  
14590 ##################
14591 # Methods
14592  
14593 sub parse {
14594  
14595 # Called by LA::Line->parse directly after a call to LA::Statement->new
14596 #
14597 # Expected arguments
14598 # (none besides $self)
14599 #
14600 # Return values
14601 # 'undef' on improper arguments or if there is an error
14602 # 1 otherwise
14603  
14604 my ($self, $check) = @_;
14605  
14606 # Check for improper arguments
14607 if (defined $check) {
14608  
14609 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14610 }
14611  
14612 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14613 # ready for $self->implement to access
14614 if (! $self->parsePoke(0)) {
14615  
14616 # ($self->scriptObj->setError has already been called)
14617 return undef;
14618 }
14619  
14620 # Parsing complete
14621 return 1;
14622 }
14623  
14624 sub implement {
14625  
14626 # Called by LA::Line->implement directly after a call to $self->parse
14627 #
14628 # Expected arguments
14629 # (none besides $self)
14630 #
14631 # Return values
14632 # 'undef' on improper arguments or if there is an error
14633 # 1 otherwise
14634  
14635 my ($self, $check) = @_;
14636  
14637 # Local variables
14638 my (
14639 # Standard
14640 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14641 # Custom
14642 );
14643  
14644 # Check for improper arguments
14645 if (defined $check) {
14646  
14647 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14648 }
14649  
14650 # Get the values stored by $self->parse
14651 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14652  
14653 # Evaluate the first expression to get the Axmud internal variable, e.g.
14654 # "current.world.name"
14655 $internalVar = $varExp->evaluate();
14656  
14657 # Process the string representing the Axmud internal variable
14658 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14659 = $self->scriptObj->session->parsePeekPoke($internalVar);
14660 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14661  
14662 return $self->scriptObj->setError(
14663 'POKEEMPTY_operation_failure',
14664 $self->_objClass . '->implement',
14665 );
14666  
14667 } elsif ($objFlag) {
14668  
14669 return $self->scriptObj->setError(
14670 'POKEEMPTY_cannot_export_to_object',
14671 $self->_objClass . '->implement',
14672 );
14673 }
14674  
14675 # (This statement accepts Perl scalars, arrays and hashes)
14676  
14677 # Perform the POKEEMPTY operation
14678 $blessed->ivEmpty($ivName);
14679  
14680 # Implementation complete
14681 return 1;
14682 }
14683 }
14684  
14685 { package Language::Axbasic::Statement::pokefalse;
14686  
14687 use strict;
14688 use warnings;
14689 # use diagnostics;
14690  
14691 use Glib qw(TRUE FALSE);
14692  
14693 @Language::Axbasic::Statement::pokefalse::ISA = qw(
14694 Language::Axbasic
14695 Language::Axbasic::Statement
14696 );
14697  
14698 # POKEFALSE axmud-object-property
14699  
14700 ##################
14701 # Methods
14702  
14703 sub parse {
14704  
14705 # Called by LA::Line->parse directly after a call to LA::Statement->new
14706 #
14707 # Expected arguments
14708 # (none besides $self)
14709 #
14710 # Return values
14711 # 'undef' on improper arguments or if there is an error
14712 # 1 otherwise
14713  
14714 my ($self, $check) = @_;
14715  
14716 # Check for improper arguments
14717 if (defined $check) {
14718  
14719 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14720 }
14721  
14722 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14723 # ready for $self->implement to access
14724 if (! $self->parsePoke(0)) {
14725  
14726 # ($self->scriptObj->setError has already been called)
14727 return undef;
14728 }
14729  
14730 # Parsing complete
14731 return 1;
14732 }
14733  
14734 sub implement {
14735  
14736 # Called by LA::Line->implement directly after a call to $self->parse
14737 #
14738 # Expected arguments
14739 # (none besides $self)
14740 #
14741 # Return values
14742 # 'undef' on improper arguments or if there is an error
14743 # 1 otherwise
14744  
14745 my ($self, $check) = @_;
14746  
14747 # Local variables
14748 my (
14749 # Standard
14750 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14751 # Custom
14752 );
14753  
14754 # Check for improper arguments
14755 if (defined $check) {
14756  
14757 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14758 }
14759  
14760 # Get the values stored by $self->parse
14761 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14762  
14763 # Evaluate the first expression to get the Axmud internal variable, e.g.
14764 # "current.world.name"
14765 $internalVar = $varExp->evaluate();
14766  
14767 # Process the string representing the Axmud internal variable
14768 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14769 = $self->scriptObj->session->parsePeekPoke($internalVar);
14770 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14771  
14772 return $self->scriptObj->setError(
14773 'POKEFALSE_operation_failure',
14774 $self->_objClass . '->implement',
14775 );
14776  
14777 } elsif ($objFlag) {
14778  
14779 return $self->scriptObj->setError(
14780 'POKEFALSE_cannot_export_to_object',
14781 $self->_objClass . '->implement',
14782 );
14783 }
14784  
14785 # This statement only accepts Perl scalars
14786 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14787  
14788 return $self->scriptObj->setError(
14789 'POKEFALSE_operation_expects_scalar',
14790 $self->_objClass . '->implement',
14791 );
14792 }
14793  
14794 # Perform the POKEFALSE operation
14795 $blessed->ivFalse($ivName);
14796  
14797 # Implementation complete
14798 return 1;
14799 }
14800 }
14801  
14802 { package Language::Axbasic::Statement::pokeinc;
14803  
14804 use strict;
14805 use warnings;
14806 # use diagnostics;
14807  
14808 use Glib qw(TRUE FALSE);
14809  
14810 @Language::Axbasic::Statement::pokeinc::ISA = qw(
14811 Language::Axbasic
14812 Language::Axbasic::Statement
14813 );
14814  
14815 # POKEINC axmud-object-property
14816  
14817 ##################
14818 # Methods
14819  
14820 sub parse {
14821  
14822 # Called by LA::Line->parse directly after a call to LA::Statement->new
14823 #
14824 # Expected arguments
14825 # (none besides $self)
14826 #
14827 # Return values
14828 # 'undef' on improper arguments or if there is an error
14829 # 1 otherwise
14830  
14831 my ($self, $check) = @_;
14832  
14833 # Check for improper arguments
14834 if (defined $check) {
14835  
14836 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14837 }
14838  
14839 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14840 # ready for $self->implement to access
14841 if (! $self->parsePoke(0)) {
14842  
14843 # ($self->scriptObj->setError has already been called)
14844 return undef;
14845 }
14846  
14847 # Parsing complete
14848 return 1;
14849 }
14850  
14851 sub implement {
14852  
14853 # Called by LA::Line->implement directly after a call to $self->parse
14854 #
14855 # Expected arguments
14856 # (none besides $self)
14857 #
14858 # Return values
14859 # 'undef' on improper arguments or if there is an error
14860 # 1 otherwise
14861  
14862 my ($self, $check) = @_;
14863  
14864 # Local variables
14865 my (
14866 # Standard
14867 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14868 # Custom
14869 );
14870  
14871 # Check for improper arguments
14872 if (defined $check) {
14873  
14874 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
14875 }
14876  
14877 # Get the values stored by $self->parse
14878 $varExp = $self->ivShow('parseDataHash', 'var_exp');
14879  
14880 # Evaluate the first expression to get the Axmud internal variable, e.g.
14881 # "current.world.name"
14882 $internalVar = $varExp->evaluate();
14883  
14884 # Process the string representing the Axmud internal variable
14885 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
14886 = $self->scriptObj->session->parsePeekPoke($internalVar);
14887 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
14888  
14889 return $self->scriptObj->setError(
14890 'POKEINC_operation_failure',
14891 $self->_objClass . '->implement',
14892 );
14893  
14894 } elsif ($objFlag) {
14895  
14896 return $self->scriptObj->setError(
14897 'POKEINC_cannot_export_to_object',
14898 $self->_objClass . '->implement',
14899 );
14900 }
14901  
14902 # This statement only accepts Perl scalars whose values are integers
14903 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
14904  
14905 return $self->scriptObj->setError(
14906 'POKEINC_operation_expects_scalar',
14907 $self->_objClass . '->implement',
14908 );
14909 }
14910  
14911 if (! defined $blessed->$ivName || $blessed->$ivName =~ m/\D/) {
14912  
14913 return $self->scriptObj->setError(
14914 'POKEINC_operation_expects_integer',
14915 $self->_objClass . '->implement',
14916 );
14917 }
14918  
14919 # Perform the POKEINC operation
14920 $blessed->ivIncrement($ivName);
14921  
14922 # Implementation complete
14923 return 1;
14924 }
14925 }
14926  
14927 { package Language::Axbasic::Statement::pokeinchash;
14928  
14929 use strict;
14930 use warnings;
14931 # use diagnostics;
14932  
14933 use Glib qw(TRUE FALSE);
14934  
14935 @Language::Axbasic::Statement::pokeinchash::ISA = qw(
14936 Language::Axbasic
14937 Language::Axbasic::Statement
14938 );
14939  
14940 # POKEINCHASH axmud-object-property, expression
14941  
14942 ##################
14943 # Methods
14944  
14945 sub parse {
14946  
14947 # Called by LA::Line->parse directly after a call to LA::Statement->new
14948 #
14949 # Expected arguments
14950 # (none besides $self)
14951 #
14952 # Return values
14953 # 'undef' on improper arguments or if there is an error
14954 # 1 otherwise
14955  
14956 my ($self, $check) = @_;
14957  
14958 # Check for improper arguments
14959 if (defined $check) {
14960  
14961 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
14962 }
14963  
14964 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
14965 # ready for $self->implement to access
14966 if (! $self->parsePoke(1)) {
14967  
14968 # ($self->scriptObj->setError has already been called)
14969 return undef;
14970 }
14971  
14972 # Parsing complete
14973 return 1;
14974 }
14975  
14976 sub implement {
14977  
14978 # Called by LA::Line->implement directly after a call to $self->parse
14979 #
14980 # Expected arguments
14981 # (none besides $self)
14982 #
14983 # Return values
14984 # 'undef' on improper arguments or if there is an error
14985 # 1 otherwise
14986  
14987 my ($self, $check) = @_;
14988  
14989 # Local variables
14990 my (
14991 # Standard
14992 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
14993 # Custom
14994 $keyExp, $key, $keyValue,
14995 );
14996  
14997 # Check for improper arguments
14998 if (defined $check) {
14999  
15000 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15001 }
15002  
15003 # Get the values stored by $self->parse
15004 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15005 $keyExp = $self->ivShift('parseDataList');
15006  
15007 # Evaluate the first expression to get the Axmud internal variable, e.g.
15008 # "current.world.name"
15009 $internalVar = $varExp->evaluate();
15010 # Evaluate the other expressions
15011 $key = $keyExp->evaluate();
15012  
15013 # Process the string representing the Axmud internal variable
15014 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15015 = $self->scriptObj->session->parsePeekPoke($internalVar);
15016 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15017  
15018 return $self->scriptObj->setError(
15019 'POKEINCHASH_operation_failure',
15020 $self->_objClass . '->implement',
15021 );
15022  
15023 } elsif ($objFlag) {
15024  
15025 return $self->scriptObj->setError(
15026 'POKEINCHASH_cannot_export_to_object',
15027 $self->_objClass . '->implement',
15028 );
15029 }
15030  
15031 # This statement only accepts Perl hashes
15032 if (! defined $var || ref($var) ne 'HASH') {
15033  
15034 return $self->scriptObj->setError(
15035 'POKEINCHASH_operation_expects_hash',
15036 $self->_objClass . '->implement',
15037 );
15038 }
15039  
15040 # The key must exist in the hash, and its corresponding value must be an integer
15041 if (! $blessed->ivExists($ivName, $key)) {
15042  
15043 return $self->scriptObj->setError(
15044 'POKEINCHASH_key_not_found',
15045 $self->_objClass . '->implement',
15046 );
15047 }
15048  
15049 $keyValue = $blessed->ivShow($ivName, $key);
15050 if (! defined $keyValue || $keyValue =~ m/\D/) {
15051  
15052 return $self->scriptObj->setError(
15053 'POKEINCHASH_operation_expects_integer',
15054 $self->_objClass . '->implement',
15055 );
15056 }
15057  
15058 # Perform the POKEINCHASH operation
15059 $blessed->ivIncHash($ivName, $key);
15060  
15061 # Implementation complete
15062 return 1;
15063 }
15064 }
15065  
15066 { package Language::Axbasic::Statement::pokeint;
15067  
15068 use strict;
15069 use warnings;
15070 # use diagnostics;
15071  
15072 use Glib qw(TRUE FALSE);
15073  
15074 @Language::Axbasic::Statement::pokeint::ISA = qw(
15075 Language::Axbasic
15076 Language::Axbasic::Statement
15077 );
15078  
15079 # POKEINT axmud-object-property
15080  
15081 ##################
15082 # Methods
15083  
15084 sub parse {
15085  
15086 # Called by LA::Line->parse directly after a call to LA::Statement->new
15087 #
15088 # Expected arguments
15089 # (none besides $self)
15090 #
15091 # Return values
15092 # 'undef' on improper arguments or if there is an error
15093 # 1 otherwise
15094  
15095 my ($self, $check) = @_;
15096  
15097 # Check for improper arguments
15098 if (defined $check) {
15099  
15100 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15101 }
15102  
15103 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15104 # ready for $self->implement to access
15105 if (! $self->parsePoke(0)) {
15106  
15107 # ($self->scriptObj->setError has already been called)
15108 return undef;
15109 }
15110  
15111 # Parsing complete
15112 return 1;
15113 }
15114  
15115 sub implement {
15116  
15117 # Called by LA::Line->implement directly after a call to $self->parse
15118 #
15119 # Expected arguments
15120 # (none besides $self)
15121 #
15122 # Return values
15123 # 'undef' on improper arguments or if there is an error
15124 # 1 otherwise
15125  
15126 my ($self, $check) = @_;
15127  
15128 # Local variables
15129 my (
15130 # Standard
15131 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15132 # Custom
15133 );
15134  
15135 # Check for improper arguments
15136 if (defined $check) {
15137  
15138 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15139 }
15140  
15141 # Get the values stored by $self->parse
15142 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15143  
15144 # Evaluate the first expression to get the Axmud internal variable, e.g.
15145 # "current.world.name"
15146 $internalVar = $varExp->evaluate();
15147  
15148 # Process the string representing the Axmud internal variable
15149 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15150 = $self->scriptObj->session->parsePeekPoke($internalVar);
15151 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15152  
15153 return $self->scriptObj->setError(
15154 'POKEINT_operation_failure',
15155 $self->_objClass . '->implement',
15156 );
15157  
15158 } elsif ($objFlag) {
15159  
15160 return $self->scriptObj->setError(
15161 'POKEINT_cannot_export_to_object',
15162 $self->_objClass . '->implement',
15163 );
15164 }
15165  
15166 # This statement only accepts Perl scalars whose values are numbers
15167 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15168  
15169 return $self->scriptObj->setError(
15170 'POKEINT_operation_expects_scalar',
15171 $self->_objClass . '->implement',
15172 );
15173 }
15174  
15175 if (
15176 ! defined $blessed->$ivName
15177 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15178 ) {
15179 return $self->scriptObj->setError(
15180 'POKEINT_operation_expects_numeric',
15181 $self->_objClass . '->implement',
15182 );
15183 }
15184  
15185 # Perform the POKEINT operation
15186 $blessed->ivInt($ivName);
15187  
15188 # Implementation complete
15189 return 1;
15190 }
15191 }
15192  
15193 { package Language::Axbasic::Statement::pokeminus;
15194  
15195 use strict;
15196 use warnings;
15197 # use diagnostics;
15198  
15199 use Glib qw(TRUE FALSE);
15200  
15201 @Language::Axbasic::Statement::pokeminus::ISA = qw(
15202 Language::Axbasic
15203 Language::Axbasic::Statement
15204 );
15205  
15206 # POKEMINUS axmud-object-property, expression
15207  
15208 ##################
15209 # Methods
15210  
15211 sub parse {
15212  
15213 # Called by LA::Line->parse directly after a call to LA::Statement->new
15214 #
15215 # Expected arguments
15216 # (none besides $self)
15217 #
15218 # Return values
15219 # 'undef' on improper arguments or if there is an error
15220 # 1 otherwise
15221  
15222 my ($self, $check) = @_;
15223  
15224 # Check for improper arguments
15225 if (defined $check) {
15226  
15227 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15228 }
15229  
15230 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15231 # ready for $self->implement to access
15232 if (! $self->parsePoke(1)) {
15233  
15234 # ($self->scriptObj->setError has already been called)
15235 return undef;
15236 }
15237  
15238 # Parsing complete
15239 return 1;
15240 }
15241  
15242 sub implement {
15243  
15244 # Called by LA::Line->implement directly after a call to $self->parse
15245 #
15246 # Expected arguments
15247 # (none besides $self)
15248 #
15249 # Return values
15250 # 'undef' on improper arguments or if there is an error
15251 # 1 otherwise
15252  
15253 my ($self, $check) = @_;
15254  
15255 # Local variables
15256 my (
15257 # Standard
15258 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15259 # Custom
15260 $valueExp, $value,
15261 );
15262  
15263 # Check for improper arguments
15264 if (defined $check) {
15265  
15266 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15267 }
15268  
15269 # Get the values stored by $self->parse
15270 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15271 $valueExp = $self->ivShift('parseDataList');
15272  
15273 # Evaluate the first expression to get the Axmud internal variable, e.g.
15274 # "current.world.name"
15275 $internalVar = $varExp->evaluate();
15276 # Evaluate the other expressions
15277 $value = $valueExp->evaluate();
15278 # The value of the expression must be a number
15279 if (! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)) {
15280  
15281 return $self->scriptObj->setError(
15282 'invalid_expression_in_POKEMINUS_statement',
15283 $self->_objClass . '->implement',
15284 );
15285 }
15286  
15287 # Process the string representing the Axmud internal variable
15288 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15289 = $self->scriptObj->session->parsePeekPoke($internalVar);
15290 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15291  
15292 return $self->scriptObj->setError(
15293 'POKEMINUS_operation_failure',
15294 $self->_objClass . '->implement',
15295 );
15296  
15297 } elsif ($objFlag) {
15298  
15299 return $self->scriptObj->setError(
15300 'POKEMINUS_cannot_export_to_object',
15301 $self->_objClass . '->implement',
15302 );
15303 }
15304  
15305 # This statement only accepts Perl scalars whose values are numbers
15306 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15307  
15308 return $self->scriptObj->setError(
15309 'POKEMINUS_operation_expects_scalar',
15310 $self->_objClass . '->implement',
15311 );
15312 }
15313  
15314 if (
15315 ! defined $blessed->$ivName
15316 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15317 ) {
15318 return $self->scriptObj->setError(
15319 'POKEMINUS_operation_expects_numeric',
15320 $self->_objClass . '->implement',
15321 );
15322 }
15323  
15324 # Perform the POKEMINUS operation
15325 $blessed->ivMinus($ivName, $value);
15326  
15327 # Implementation complete
15328 return 1;
15329 }
15330 }
15331  
15332 { package Language::Axbasic::Statement::pokemultiply;
15333  
15334 use strict;
15335 use warnings;
15336 # use diagnostics;
15337  
15338 use Glib qw(TRUE FALSE);
15339  
15340 @Language::Axbasic::Statement::pokemultiply::ISA = qw(
15341 Language::Axbasic
15342 Language::Axbasic::Statement
15343 );
15344  
15345 # POKEMULTIPLY axmud-object-property, expression
15346  
15347 ##################
15348 # Methods
15349  
15350 sub parse {
15351  
15352 # Called by LA::Line->parse directly after a call to LA::Statement->new
15353 #
15354 # Expected arguments
15355 # (none besides $self)
15356 #
15357 # Return values
15358 # 'undef' on improper arguments or if there is an error
15359 # 1 otherwise
15360  
15361 my ($self, $check) = @_;
15362  
15363 # Check for improper arguments
15364 if (defined $check) {
15365  
15366 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15367 }
15368  
15369 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15370 # ready for $self->implement to access
15371 if (! $self->parsePoke(1)) {
15372  
15373 # ($self->scriptObj->setError has already been called)
15374 return undef;
15375 }
15376  
15377 # Parsing complete
15378 return 1;
15379 }
15380  
15381 sub implement {
15382  
15383 # Called by LA::Line->implement directly after a call to $self->parse
15384 #
15385 # Expected arguments
15386 # (none besides $self)
15387 #
15388 # Return values
15389 # 'undef' on improper arguments or if there is an error
15390 # 1 otherwise
15391  
15392 my ($self, $check) = @_;
15393  
15394 # Local variables
15395 my (
15396 # Standard
15397 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15398 # Custom
15399 $valueExp, $value,
15400 );
15401  
15402 # Check for improper arguments
15403 if (defined $check) {
15404  
15405 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15406 }
15407  
15408 # Get the values stored by $self->parse
15409 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15410 $valueExp = $self->ivShift('parseDataList');
15411  
15412 # Evaluate the first expression to get the Axmud internal variable, e.g.
15413 # "current.world.name"
15414 $internalVar = $varExp->evaluate();
15415 # Evaluate the other expressions
15416 $value = $valueExp->evaluate();
15417 # The value of the expression must be a number
15418 if (! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)) {
15419  
15420 return $self->scriptObj->setError(
15421 'invalid_expression_in_POKEMULTIPLY_statement',
15422 $self->_objClass . '->implement',
15423 );
15424 }
15425  
15426 # Process the string representing the Axmud internal variable
15427 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15428 = $self->scriptObj->session->parsePeekPoke($internalVar);
15429 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15430  
15431 return $self->scriptObj->setError(
15432 'POKEMULTIPLY_operation_failure',
15433 $self->_objClass . '->implement',
15434 );
15435  
15436 } elsif ($objFlag) {
15437  
15438 return $self->scriptObj->setError(
15439 'POKEMULTIPLY_cannot_export_to_object',
15440 $self->_objClass . '->implement',
15441 );
15442 }
15443  
15444 # This statement only accepts Perl scalars whose values are numbers
15445 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15446  
15447 return $self->scriptObj->setError(
15448 'POKEMULTIPLY_operation_expects_scalar',
15449 $self->_objClass . '->implement',
15450 );
15451 }
15452  
15453 if (
15454 ! defined $blessed->$ivName
15455 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15456 ) {
15457 return $self->scriptObj->setError(
15458 'POKEMULTIPLY_operation_expects_numeric',
15459 $self->_objClass . '->implement',
15460 );
15461 }
15462  
15463 # Perform the POKEMULTIPLY operation
15464 $blessed->ivMultiply($ivName, $value);
15465  
15466 # Implementation complete
15467 return 1;
15468 }
15469 }
15470  
15471 { package Language::Axbasic::Statement::pokeplus;
15472  
15473 use strict;
15474 use warnings;
15475 # use diagnostics;
15476  
15477 use Glib qw(TRUE FALSE);
15478  
15479 @Language::Axbasic::Statement::pokeplus::ISA = qw(
15480 Language::Axbasic
15481 Language::Axbasic::Statement
15482 );
15483  
15484 # POKEPLUS axmud-object-property, expression
15485  
15486 ##################
15487 # Methods
15488  
15489 sub parse {
15490  
15491 # Called by LA::Line->parse directly after a call to LA::Statement->new
15492 #
15493 # Expected arguments
15494 # (none besides $self)
15495 #
15496 # Return values
15497 # 'undef' on improper arguments or if there is an error
15498 # 1 otherwise
15499  
15500 my ($self, $check) = @_;
15501  
15502 # Check for improper arguments
15503 if (defined $check) {
15504  
15505 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15506 }
15507  
15508 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15509 # ready for $self->implement to access
15510 if (! $self->parsePoke(1)) {
15511  
15512 # ($self->scriptObj->setError has already been called)
15513 return undef;
15514 }
15515  
15516 # Parsing complete
15517 return 1;
15518 }
15519  
15520 sub implement {
15521  
15522 # Called by LA::Line->implement directly after a call to $self->parse
15523 #
15524 # Expected arguments
15525 # (none besides $self)
15526 #
15527 # Return values
15528 # 'undef' on improper arguments or if there is an error
15529 # 1 otherwise
15530  
15531 my ($self, $check) = @_;
15532  
15533 # Local variables
15534 my (
15535 # Standard
15536 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15537 # Custom
15538 $valueExp, $value,
15539 );
15540  
15541 # Check for improper arguments
15542 if (defined $check) {
15543  
15544 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15545 }
15546  
15547 # Get the values stored by $self->parse
15548 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15549 $valueExp = $self->ivShift('parseDataList');
15550  
15551 # Evaluate the first expression to get the Axmud internal variable, e.g.
15552 # "current.world.name"
15553 $internalVar = $varExp->evaluate();
15554 # Evaluate the other expressions
15555 $value = $valueExp->evaluate();
15556 # The value of the expression must be a number
15557 if (! ($value =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)) {
15558  
15559 return $self->scriptObj->setError(
15560 'invalid_expression_in_POKEPLUS_statement',
15561 $self->_objClass . '->implement',
15562 );
15563 }
15564  
15565 # Process the string representing the Axmud internal variable
15566 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15567 = $self->scriptObj->session->parsePeekPoke($internalVar);
15568 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15569  
15570 return $self->scriptObj->setError(
15571 'POKEPLUS_operation_failure',
15572 $self->_objClass . '->implement',
15573 );
15574  
15575 } elsif ($objFlag) {
15576  
15577 return $self->scriptObj->setError(
15578 'POKEPLUS_cannot_export_to_object',
15579 $self->_objClass . '->implement',
15580 );
15581 }
15582  
15583 # This statement only accepts Perl scalars whose values are numbers
15584 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
15585  
15586 return $self->scriptObj->setError(
15587 'POKEPLUS_operation_expects_scalar',
15588 $self->_objClass . '->implement',
15589 );
15590 }
15591  
15592 if (
15593 ! defined $blessed->$ivName
15594 || ! ($blessed->$ivName =~ m/([-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+))/)
15595 ) {
15596 return $self->scriptObj->setError(
15597 'POKEPLUS_operation_expects_numeric',
15598 $self->_objClass . '->implement',
15599 );
15600 }
15601  
15602 # Perform the POKEPLUS operation
15603 $blessed->ivPlus($ivName, $value);
15604  
15605 # Implementation complete
15606 return 1;
15607 }
15608 }
15609  
15610 { package Language::Axbasic::Statement::pokepop;
15611  
15612 use strict;
15613 use warnings;
15614 # use diagnostics;
15615  
15616 use Glib qw(TRUE FALSE);
15617  
15618 @Language::Axbasic::Statement::pokepop::ISA = qw(
15619 Language::Axbasic
15620 Language::Axbasic::Statement
15621 );
15622  
15623 # POKEPOP variable-name = axmud-object-property
15624 # POKEPOP ARRAY variable-name = axmud-object-property
15625  
15626 ##################
15627 # Methods
15628  
15629 sub parse {
15630  
15631 # Called by LA::Line->parse directly after a call to LA::Statement->new
15632 #
15633 # Expected arguments
15634 # (none besides $self)
15635 #
15636 # Return values
15637 # 'undef' on improper arguments or if there is an error
15638 # 1 otherwise
15639  
15640 my ($self, $check) = @_;
15641  
15642 # Check for improper arguments
15643 if (defined $check) {
15644  
15645 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15646 }
15647  
15648 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
15649 # $self->parseDataHash, ready for $self->implement to access
15650 # (NB POKEPOP is closer in format to a PEEK... statement, so we don't call ->parsePoke() )
15651 if (! $self->parsePeek()) {
15652  
15653 # ($self->scriptObj->setError has already been called)
15654 return undef;
15655 }
15656  
15657 # Parsing complete
15658 return 1;
15659 }
15660  
15661 sub implement {
15662  
15663 # Called by LA::Line->implement directly after a call to $self->parse
15664 #
15665 # Expected arguments
15666 # (none besides $self)
15667 #
15668 # Return values
15669 # 'undef' on improper arguments or if there is an error
15670 # 1 otherwise
15671  
15672 my ($self, $check) = @_;
15673  
15674 # Local variables
15675 my (
15676 # Standard
15677 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
15678 $var, $objFlag, $privFlag, $scalar, $varObj,
15679 @array,
15680 # Custom (set after $varObj is set)
15681 $popValue,
15682 );
15683  
15684 # Check for improper arguments
15685 if (defined $check) {
15686  
15687 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15688 }
15689  
15690 # Get the values stored by $self->parse
15691 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
15692 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
15693 $expression = $self->ivShow('parseDataHash', 'expression');
15694  
15695 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
15696 $expValue = $expression->evaluate();
15697 # Process the string representing the Axmud internal variable
15698 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15699 = $self->scriptObj->session->parsePeekPoke($expValue);
15700 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15701  
15702 return $self->scriptObj->setError(
15703 'POKEPOP_operation_failure',
15704 $self->_objClass . '->implement',
15705 );
15706 }
15707  
15708 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
15709 # or @array if $string refers to a list or hash value
15710 if (! $objFlag) {
15711  
15712 # This statement only accepts Perl lists
15713 if (defined $var && ref($var) eq 'ARRAY') {
15714  
15715 @array = @$var;
15716  
15717 } else {
15718  
15719 return $self->scriptObj->setError(
15720 'POKEPOP_operation_expects_list',
15721 $self->_objClass . '->implement',
15722 );
15723 }
15724  
15725 } else {
15726  
15727 return $self->scriptObj->setError(
15728 'POKEPOP_cannot_import_object',
15729 $self->_objClass . '->implement',
15730 );
15731 }
15732  
15733 # Look up the LA::Variable
15734 $varObj = $self->fetchVar('POKEPOP', $basicVarName, $parseArrayFlag);
15735 if (! $varObj) {
15736  
15737 # (self->scriptObj->setError already called)
15738 return undef;
15739 }
15740  
15741 # Now we can set the variable to POKEPOP's return value. If the list is empty, we use the
15742 # value 'undef' (which is converted by the call to ->importAsScalar or ->importAsList)
15743 $popValue = $blessed->ivPop($ivName);
15744  
15745 if (! $parseArrayFlag) {
15746  
15747 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
15748 # necessary
15749 $self->importAsScalar($varObj, $popValue);
15750  
15751 } else {
15752  
15753 # Import the list/hash into an Axbasic array, resizing it as necessary
15754 $self->importAsArray($varObj, $popValue);
15755 }
15756  
15757 # Implementation complete
15758 return 1;
15759 }
15760 }
15761  
15762 { package Language::Axbasic::Statement::pokepush;
15763  
15764 use strict;
15765 use warnings;
15766 # use diagnostics;
15767  
15768 use Glib qw(TRUE FALSE);
15769  
15770 @Language::Axbasic::Statement::pokepush::ISA = qw(
15771 Language::Axbasic
15772 Language::Axbasic::Statement
15773 );
15774  
15775 # POKEPUSH axmud-object-property, expression
15776 # POKEPUSH axmud-object-property
15777  
15778 ##################
15779 # Methods
15780  
15781 sub parse {
15782  
15783 # Called by LA::Line->parse directly after a call to LA::Statement->new
15784 #
15785 # Expected arguments
15786 # (none besides $self)
15787 #
15788 # Return values
15789 # 'undef' on improper arguments or if there is an error
15790 # 1 otherwise
15791  
15792 my ($self, $check) = @_;
15793  
15794 # Check for improper arguments
15795 if (defined $check) {
15796  
15797 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15798 }
15799  
15800 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15801 # ready for $self->implement to access
15802 if (! $self->parsePoke(0, 1)) {
15803  
15804 # ($self->scriptObj->setError has already been called)
15805 return undef;
15806 }
15807  
15808 # Parsing complete
15809 return 1;
15810 }
15811  
15812 sub implement {
15813  
15814 # Called by LA::Line->implement directly after a call to $self->parse
15815 #
15816 # Expected arguments
15817 # (none besides $self)
15818 #
15819 # Return values
15820 # 'undef' on improper arguments or if there is an error
15821 # 1 otherwise
15822  
15823 my ($self, $check) = @_;
15824  
15825 # Local variables
15826 my (
15827 # Standard
15828 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15829 # Custom
15830 $valueExp, $value,
15831 );
15832  
15833 # Check for improper arguments
15834 if (defined $check) {
15835  
15836 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15837 }
15838  
15839 # Get the values stored by $self->parse
15840 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15841 $valueExp = $self->ivShift('parseDataList');
15842  
15843 # Evaluate the first expression to get the Axmud internal variable, e.g.
15844 # "current.world.name"
15845 $internalVar = $varExp->evaluate();
15846 # Evaluate the other expressions
15847 if (defined $valueExp) {
15848  
15849 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
15850 $value = $valueExp->evaluate();
15851 }
15852  
15853 # Process the string representing the Axmud internal variable
15854 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15855 = $self->scriptObj->session->parsePeekPoke($internalVar);
15856 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15857  
15858 return $self->scriptObj->setError(
15859 'POKEPUSH_operation_failure',
15860 $self->_objClass . '->implement',
15861 );
15862  
15863 } elsif ($objFlag) {
15864  
15865 return $self->scriptObj->setError(
15866 'POKEPUSH_cannot_export_to_object',
15867 $self->_objClass . '->implement',
15868 );
15869 }
15870  
15871 # This statement only accepts Perl lists
15872 if (! defined $var || ref($var) ne 'ARRAY') {
15873  
15874 return $self->scriptObj->setError(
15875 'POKEPUSH_operation_expects_list',
15876 $self->_objClass . '->implement',
15877 );
15878 }
15879  
15880 # Perform the POKEPUSH operation. If the minimum number of expressions was specified, $value
15881 # is 'undef'
15882 $blessed->ivPush($ivName, $value);
15883  
15884 # Implementation complete
15885 return 1;
15886 }
15887 }
15888  
15889 { package Language::Axbasic::Statement::pokereplace;
15890  
15891 use strict;
15892 use warnings;
15893 # use diagnostics;
15894  
15895 use Glib qw(TRUE FALSE);
15896  
15897 @Language::Axbasic::Statement::pokereplace::ISA = qw(
15898 Language::Axbasic
15899 Language::Axbasic::Statement
15900 );
15901  
15902 # POKEREPLACE axmud-object-property, expression, expression
15903 # POKEREPLACE axmud-object-property, expression
15904  
15905 ##################
15906 # Methods
15907  
15908 sub parse {
15909  
15910 # Called by LA::Line->parse directly after a call to LA::Statement->new
15911 #
15912 # Expected arguments
15913 # (none besides $self)
15914 #
15915 # Return values
15916 # 'undef' on improper arguments or if there is an error
15917 # 1 otherwise
15918  
15919 my ($self, $check) = @_;
15920  
15921 # Check for improper arguments
15922 if (defined $check) {
15923  
15924 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
15925 }
15926  
15927 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
15928 # ready for $self->implement to access
15929 if (! $self->parsePoke(1, 2)) {
15930  
15931 # ($self->scriptObj->setError has already been called)
15932 return undef;
15933 }
15934  
15935 # Parsing complete
15936 return 1;
15937 }
15938  
15939 sub implement {
15940  
15941 # Called by LA::Line->implement directly after a call to $self->parse
15942 #
15943 # Expected arguments
15944 # (none besides $self)
15945 #
15946 # Return values
15947 # 'undef' on improper arguments or if there is an error
15948 # 1 otherwise
15949  
15950 my ($self, $check) = @_;
15951  
15952 # Local variables
15953 my (
15954 # Standard
15955 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
15956 # Custom
15957 $indexExp, $index, $valueExp, $value,
15958 );
15959  
15960 # Check for improper arguments
15961 if (defined $check) {
15962  
15963 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
15964 }
15965  
15966 # Get the values stored by $self->parse
15967 $varExp = $self->ivShow('parseDataHash', 'var_exp');
15968 $indexExp = $self->ivShift('parseDataList');
15969 $valueExp = $self->ivShift('parseDataList');
15970  
15971 # Evaluate the first expression to get the Axmud internal variable, e.g.
15972 # "current.world.name"
15973 $internalVar = $varExp->evaluate();
15974 # Evaluate the other expressions
15975 $index = $indexExp->evaluate();
15976 if (defined $valueExp) {
15977  
15978 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
15979 $value = $valueExp->evaluate();
15980 }
15981  
15982 # Process the string representing the Axmud internal variable
15983 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
15984 = $self->scriptObj->session->parsePeekPoke($internalVar);
15985 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
15986  
15987 return $self->scriptObj->setError(
15988 'POKEREPLACE_operation_failure',
15989 $self->_objClass . '->implement',
15990 );
15991  
15992 } elsif ($objFlag) {
15993  
15994 return $self->scriptObj->setError(
15995 'POKEREPLACE_cannot_export_to_object',
15996 $self->_objClass . '->implement',
15997 );
15998 }
15999  
16000 # This statement only accepts Perl lists
16001 if (! defined $var || ref($var) ne 'ARRAY') {
16002  
16003 return $self->scriptObj->setError(
16004 'POKEREPLACE_operation_expects_list',
16005 $self->_objClass . '->implement',
16006 );
16007 }
16008  
16009 # $index must be a valid integer, and exist in the list property
16010 if (
16011 ! defined $index
16012 || $index =~ /\D/
16013 || $index < 0
16014 || $index >= $blessed->ivNumber($ivName)
16015 ) {
16016 return $self->scriptObj->setError(
16017 'invalid_index_NUM',
16018 $self->_objClass . '->implement',
16019 'NUM', $index,
16020 );
16021 }
16022  
16023 # Perform the POKEREPLACE operation. If the minimum number of expressions was specified,
16024 # $value is 'undef'
16025 $blessed->ivReplace($ivName, $index, $value);
16026  
16027 # Implementation complete
16028 return 1;
16029 }
16030 }
16031  
16032 { package Language::Axbasic::Statement::pokeset;
16033  
16034 use strict;
16035 use warnings;
16036 # use diagnostics;
16037  
16038 use Glib qw(TRUE FALSE);
16039  
16040 @Language::Axbasic::Statement::pokeset::ISA = qw(
16041 Language::Axbasic
16042 Language::Axbasic::Statement
16043 );
16044  
16045 # POKESET axmud-object-property, expression
16046 # POKESET axmud-object-property
16047  
16048 ##################
16049 # Methods
16050  
16051 sub parse {
16052  
16053 # Called by LA::Line->parse directly after a call to LA::Statement->new
16054 #
16055 # Expected arguments
16056 # (none besides $self)
16057 #
16058 # Return values
16059 # 'undef' on improper arguments or if there is an error
16060 # 1 otherwise
16061  
16062 my ($self, $check) = @_;
16063  
16064 # Check for improper arguments
16065 if (defined $check) {
16066  
16067 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16068 }
16069  
16070 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16071 # ready for $self->implement to access
16072 if (! $self->parsePoke(0, 1)) {
16073  
16074 # ($self->scriptObj->setError has already been called)
16075 return undef;
16076 }
16077  
16078 # Parsing complete
16079 return 1;
16080 }
16081  
16082 sub implement {
16083  
16084 # Called by LA::Line->implement directly after a call to $self->parse
16085 #
16086 # Expected arguments
16087 # (none besides $self)
16088 #
16089 # Return values
16090 # 'undef' on improper arguments or if there is an error
16091 # 1 otherwise
16092  
16093 my ($self, $check) = @_;
16094  
16095 # Local variables
16096 my (
16097 # Standard
16098 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16099 # Custom
16100 $valueExp, $value,
16101 );
16102  
16103 # Check for improper arguments
16104 if (defined $check) {
16105  
16106 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16107 }
16108  
16109 # Get the values stored by $self->parse
16110 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16111 $valueExp = $self->ivShift('parseDataList');
16112  
16113 # Evaluate the first expression to get the Axmud internal variable, e.g.
16114 # "current.world.name"
16115 $internalVar = $varExp->evaluate();
16116 # Evaluate the other expressions
16117 if (defined $valueExp) {
16118  
16119 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
16120 $value = $valueExp->evaluate();
16121 }
16122  
16123 # Process the string representing the Axmud internal variable
16124 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16125 = $self->scriptObj->session->parsePeekPoke($internalVar);
16126 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16127  
16128 return $self->scriptObj->setError(
16129 'POKESET_operation_failure',
16130 $self->_objClass . '->implement',
16131 );
16132  
16133 } elsif ($objFlag) {
16134  
16135 return $self->scriptObj->setError(
16136 'POKESET_cannot_export_to_object',
16137 $self->_objClass . '->implement',
16138 );
16139 }
16140  
16141 # This statement only accepts Perl scalars
16142 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
16143  
16144 return $self->scriptObj->setError(
16145 'POKESET_operation_expects_scalar',
16146 $self->_objClass . '->implement',
16147 );
16148 }
16149  
16150 # Perform the POKESET operation. If the minimum number of expressions was specified, $value
16151 # is 'undef'
16152 $blessed->ivSet($ivName, $value);
16153  
16154 # Implementation complete
16155 return 1;
16156 }
16157 }
16158  
16159 { package Language::Axbasic::Statement::pokeshift;
16160  
16161 use strict;
16162 use warnings;
16163 # use diagnostics;
16164  
16165 use Glib qw(TRUE FALSE);
16166  
16167 @Language::Axbasic::Statement::pokeshift::ISA = qw(
16168 Language::Axbasic
16169 Language::Axbasic::Statement
16170 );
16171  
16172 # POKESHIFT variable-name = axmud-object-property
16173 # POKESHIFT ARRAY variable-name = axmud-object-property
16174  
16175 ##################
16176 # Methods
16177  
16178 sub parse {
16179  
16180 # Called by LA::Line->parse directly after a call to LA::Statement->new
16181 #
16182 # Expected arguments
16183 # (none besides $self)
16184 #
16185 # Return values
16186 # 'undef' on improper arguments or if there is an error
16187 # 1 otherwise
16188  
16189 my ($self, $check) = @_;
16190  
16191 # Check for improper arguments
16192 if (defined $check) {
16193  
16194 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16195 }
16196  
16197 # Extract the standard PEEK... tokens. If the extraction is successful, they are stored in
16198 # $self->parseDataHash, ready for $self->implement to access
16199 # (NB POKESHIFT is closer in format to a PEEK... statement, so we don't call ->parsePoke() )
16200 if (! $self->parsePeek()) {
16201  
16202 # ($self->scriptObj->setError has already been called)
16203 return undef;
16204 }
16205  
16206 # Parsing complete
16207 return 1;
16208 }
16209  
16210 sub implement {
16211  
16212 # Called by LA::Line->implement directly after a call to $self->parse
16213 #
16214 # Expected arguments
16215 # (none besides $self)
16216 #
16217 # Return values
16218 # 'undef' on improper arguments or if there is an error
16219 # 1 otherwise
16220  
16221 my ($self, $check) = @_;
16222  
16223 # Local variables
16224 my (
16225 # Standard
16226 $parseArrayFlag, $basicVarName, $expression, $expValue, $successFlag, $blessed, $ivName,
16227 $var, $objFlag, $privFlag, $scalar, $varObj,
16228 @array,
16229 # Custom (set after $varObj is set)
16230 $shiftValue,
16231 );
16232  
16233 # Check for improper arguments
16234 if (defined $check) {
16235  
16236 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16237 }
16238  
16239 # Get the values stored by $self->parse
16240 $parseArrayFlag = $self->ivShow('parseDataHash', 'array_flag');
16241 $basicVarName = $self->ivShow('parseDataHash', 'var_name');
16242 $expression = $self->ivShow('parseDataHash', 'expression');
16243  
16244 # Evaluate the expression to get the Axmud internal variable, e.g. "current.world.name"
16245 $expValue = $expression->evaluate();
16246 # Process the string representing the Axmud internal variable
16247 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16248 = $self->scriptObj->session->parsePeekPoke($expValue);
16249 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16250  
16251 return $self->scriptObj->setError(
16252 'POKESHIFT_operation_failure',
16253 $self->_objClass . '->implement',
16254 );
16255 }
16256  
16257 # Import the Axmud internal variable, setting $scalar if $string refers to a scalar value,
16258 # or @array if $string refers to a list or hash value
16259 if (! $objFlag) {
16260  
16261 # This statement only accepts Perl lists
16262 if (defined $var && ref($var) eq 'ARRAY') {
16263  
16264 @array = @$var;
16265  
16266 } else {
16267  
16268 return $self->scriptObj->setError(
16269 'POKESHIFT_operation_expects_list',
16270 $self->_objClass . '->implement',
16271 );
16272 }
16273  
16274 } else {
16275  
16276 return $self->scriptObj->setError(
16277 'POKESHIFT_cannot_import_object',
16278 $self->_objClass . '->implement',
16279 );
16280 }
16281  
16282 # Look up the LA::Variable
16283 $varObj = $self->fetchVar('POKESHIFT', $basicVarName, $parseArrayFlag);
16284 if (! $varObj) {
16285  
16286 # (self->scriptObj->setError already called)
16287 return undef;
16288 }
16289  
16290 # Now we can set the variable to POKESHIFT's return value. If the list is empty, we use the
16291 # value 'undef' (which is converted by the call to ->importAsScalar or ->importAsList)
16292 $shiftValue = $blessed->ivShift($ivName);
16293  
16294 if (! $parseArrayFlag) {
16295  
16296 # Import the scalar into an Axbasic scalar variable, converting Perl 'undef' as
16297 # necessary
16298 $self->importAsScalar($varObj, $shiftValue);
16299  
16300 } else {
16301  
16302 # Import the list/hash into an Axbasic array, resizing it as necessary
16303 $self->importAsArray($varObj, $shiftValue);
16304 }
16305  
16306 # Implementation complete
16307 return 1;
16308 }
16309 }
16310  
16311 { package Language::Axbasic::Statement::poketrue;
16312  
16313 use strict;
16314 use warnings;
16315 # use diagnostics;
16316  
16317 use Glib qw(TRUE FALSE);
16318  
16319 @Language::Axbasic::Statement::poketrue::ISA = qw(
16320 Language::Axbasic
16321 Language::Axbasic::Statement
16322 );
16323  
16324 # POKETRUE axmud-object-property
16325  
16326 ##################
16327 # Methods
16328  
16329 sub parse {
16330  
16331 # Called by LA::Line->parse directly after a call to LA::Statement->new
16332 #
16333 # Expected arguments
16334 # (none besides $self)
16335 #
16336 # Return values
16337 # 'undef' on improper arguments or if there is an error
16338 # 1 otherwise
16339  
16340 my ($self, $check) = @_;
16341  
16342 # Check for improper arguments
16343 if (defined $check) {
16344  
16345 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16346 }
16347  
16348 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16349 # ready for $self->implement to access
16350 if (! $self->parsePoke(0)) {
16351  
16352 # ($self->scriptObj->setError has already been called)
16353 return undef;
16354 }
16355  
16356 # Parsing complete
16357 return 1;
16358 }
16359  
16360 sub implement {
16361  
16362 # Called by LA::Line->implement directly after a call to $self->parse
16363 #
16364 # Expected arguments
16365 # (none besides $self)
16366 #
16367 # Return values
16368 # 'undef' on improper arguments or if there is an error
16369 # 1 otherwise
16370  
16371 my ($self, $check) = @_;
16372  
16373 # Local variables
16374 my (
16375 # Standard
16376 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16377 # Custom
16378 );
16379  
16380 # Check for improper arguments
16381 if (defined $check) {
16382  
16383 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16384 }
16385  
16386 # Get the values stored by $self->parse
16387 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16388  
16389 # Evaluate the first expression to get the Axmud internal variable, e.g.
16390 # "current.world.name"
16391 $internalVar = $varExp->evaluate();
16392  
16393 # Process the string representing the Axmud internal variable
16394 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16395 = $self->scriptObj->session->parsePeekPoke($internalVar);
16396 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16397  
16398 return $self->scriptObj->setError(
16399 'POKETRUE_operation_failure',
16400 $self->_objClass . '->implement',
16401 );
16402  
16403 } elsif ($objFlag) {
16404  
16405 return $self->scriptObj->setError(
16406 'POKETRUE_cannot_export_to_object',
16407 $self->_objClass . '->implement',
16408 );
16409 }
16410  
16411 # This statement only accepts Perl scalars
16412 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
16413  
16414 return $self->scriptObj->setError(
16415 'POKETRUE_operation_expects_scalar',
16416 $self->_objClass . '->implement',
16417 );
16418 }
16419  
16420 # Perform the POKETRUE operation
16421 $blessed->ivTrue($ivName);
16422  
16423 # Implementation complete
16424 return 1;
16425 }
16426 }
16427  
16428 { package Language::Axbasic::Statement::pokeundef;
16429  
16430 use strict;
16431 use warnings;
16432 # use diagnostics;
16433  
16434 use Glib qw(TRUE FALSE);
16435  
16436 @Language::Axbasic::Statement::pokeundef::ISA = qw(
16437 Language::Axbasic
16438 Language::Axbasic::Statement
16439 );
16440  
16441 # POKEUNDEF axmud-object-property
16442  
16443 ##################
16444 # Methods
16445  
16446 sub parse {
16447  
16448 # Called by LA::Line->parse directly after a call to LA::Statement->new
16449 #
16450 # Expected arguments
16451 # (none besides $self)
16452 #
16453 # Return values
16454 # 'undef' on improper arguments or if there is an error
16455 # 1 otherwise
16456  
16457 my ($self, $check) = @_;
16458  
16459 # Check for improper arguments
16460 if (defined $check) {
16461  
16462 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16463 }
16464  
16465 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16466 # ready for $self->implement to access
16467 if (! $self->parsePoke(0)) {
16468  
16469 # ($self->scriptObj->setError has already been called)
16470 return undef;
16471 }
16472  
16473 # Parsing complete
16474 return 1;
16475 }
16476  
16477 sub implement {
16478  
16479 # Called by LA::Line->implement directly after a call to $self->parse
16480 #
16481 # Expected arguments
16482 # (none besides $self)
16483 #
16484 # Return values
16485 # 'undef' on improper arguments or if there is an error
16486 # 1 otherwise
16487  
16488 my ($self, $check) = @_;
16489  
16490 # Local variables
16491 my (
16492 # Standard
16493 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16494 # Custom
16495 );
16496  
16497 # Check for improper arguments
16498 if (defined $check) {
16499  
16500 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16501 }
16502  
16503 # Get the values stored by $self->parse
16504 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16505  
16506 # Evaluate the first expression to get the Axmud internal variable, e.g.
16507 # "current.world.name"
16508 $internalVar = $varExp->evaluate();
16509  
16510 # Process the string representing the Axmud internal variable
16511 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16512 = $self->scriptObj->session->parsePeekPoke($internalVar);
16513 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16514  
16515 return $self->scriptObj->setError(
16516 'POKEUNDEF_operation_failure',
16517 $self->_objClass . '->implement',
16518 );
16519  
16520 } elsif ($objFlag) {
16521  
16522 return $self->scriptObj->setError(
16523 'POKEUNDEF_cannot_export_to_object',
16524 $self->_objClass . '->implement',
16525 );
16526 }
16527  
16528 # This statement only accepts Perl scalars
16529 if (defined $var && (ref($var) eq 'ARRAY' || ref($var) eq 'HASH')) {
16530  
16531 return $self->scriptObj->setError(
16532 'POKEUNDEF_operation_expects_scalar',
16533 $self->_objClass . '->implement',
16534 );
16535 }
16536  
16537 # Perform the POKEUNDEF operation
16538 $blessed->ivUndef($ivName);
16539  
16540 # Implementation complete
16541 return 1;
16542 }
16543 }
16544  
16545 { package Language::Axbasic::Statement::pokeunshift;
16546  
16547 use strict;
16548 use warnings;
16549 # use diagnostics;
16550  
16551 use Glib qw(TRUE FALSE);
16552  
16553 @Language::Axbasic::Statement::pokeunshift::ISA = qw(
16554 Language::Axbasic
16555 Language::Axbasic::Statement
16556 );
16557  
16558 # POKEUNSHIFT axmud-object-property, expression
16559 # POKEUNSHIFT axmud-object-property
16560  
16561 ##################
16562 # Methods
16563  
16564 sub parse {
16565  
16566 # Called by LA::Line->parse directly after a call to LA::Statement->new
16567 #
16568 # Expected arguments
16569 # (none besides $self)
16570 #
16571 # Return values
16572 # 'undef' on improper arguments or if there is an error
16573 # 1 otherwise
16574  
16575 my ($self, $check) = @_;
16576  
16577 # Check for improper arguments
16578 if (defined $check) {
16579  
16580 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16581 }
16582  
16583 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
16584 # ready for $self->implement to access
16585 if (! $self->parsePoke(0, 1)) {
16586  
16587 # ($self->scriptObj->setError has already been called)
16588 return undef;
16589 }
16590  
16591 # Parsing complete
16592 return 1;
16593 }
16594  
16595 sub implement {
16596  
16597 # Called by LA::Line->implement directly after a call to $self->parse
16598 #
16599 # Expected arguments
16600 # (none besides $self)
16601 #
16602 # Return values
16603 # 'undef' on improper arguments or if there is an error
16604 # 1 otherwise
16605  
16606 my ($self, $check) = @_;
16607  
16608 # Local variables
16609 my (
16610 # Standard
16611 $varExp, $internalVar, $successFlag, $blessed, $ivName, $var, $objFlag, $privFlag,
16612 # Custom
16613 $valueExp, $value,
16614 );
16615  
16616 # Check for improper arguments
16617 if (defined $check) {
16618  
16619 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16620 }
16621  
16622 # Get the values stored by $self->parse
16623 $varExp = $self->ivShow('parseDataHash', 'var_exp');
16624 $valueExp = $self->ivShift('parseDataList');
16625  
16626 # Evaluate the first expression to get the Axmud internal variable, e.g.
16627 # "current.world.name"
16628 $internalVar = $varExp->evaluate();
16629 # Evaluate the other expressions
16630 if (defined $valueExp) {
16631  
16632 # $valueExp is optional. If the user didn't specify it, $value remains set to 'undef'
16633 $value = $valueExp->evaluate();
16634 }
16635  
16636 # Process the string representing the Axmud internal variable
16637 ($successFlag, $blessed, $ivName, $var, $objFlag, $privFlag)
16638 = $self->scriptObj->session->parsePeekPoke($internalVar);
16639 if (! $successFlag || ! $blessed || ! $ivName || $privFlag) {
16640  
16641 return $self->scriptObj->setError(
16642 'POKEUNSHIFT_operation_failure',
16643 $self->_objClass . '->implement',
16644 );
16645  
16646 } elsif ($objFlag) {
16647  
16648 return $self->scriptObj->setError(
16649 'POKEUNSHIFT_cannot_export_to_object',
16650 $self->_objClass . '->implement',
16651 );
16652 }
16653  
16654 # This statement only accepts Perl lists
16655 if (! defined $var || ref($var) ne 'ARRAY') {
16656  
16657 return $self->scriptObj->setError(
16658 'POKEUNSHIFT_operation_expects_list',
16659 $self->_objClass . '->implement',
16660 );
16661 }
16662  
16663 # Perform the POKEUNSHIFT operation. If the minimum number of expressions was specified,
16664 # $value is 'undef'
16665 $blessed->ivUnshift($ivName, $value);
16666  
16667 # Implementation complete
16668 return 1;
16669 }
16670 }
16671  
16672 { package Language::Axbasic::Statement::pop;
16673  
16674 use strict;
16675 use warnings;
16676 # use diagnostics;
16677  
16678 use Glib qw(TRUE FALSE);
16679  
16680 @Language::Axbasic::Statement::pop::ISA = qw(
16681 Language::Axbasic
16682 Language::Axbasic::Statement
16683 );
16684  
16685 # POP array-name [ , variable-name ]
16686  
16687 ##################
16688 # Methods
16689  
16690 sub parse {
16691  
16692 # Called by LA::Line->parse directly after a call to LA::Statement->new
16693 #
16694 # Expected arguments
16695 # (none besides $self)
16696 #
16697 # Return values
16698 # 'undef' on improper arguments or if there is an error
16699 # 1 otherwise
16700  
16701 my ($self, $check) = @_;
16702  
16703 # Local variables
16704 my ($arrayExp, $scalarExp);
16705  
16706 # Check for improper arguments
16707 if (defined $check) {
16708  
16709 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16710 }
16711  
16712 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
16713 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
16714 # that created by
16715 # DIM var (10)
16716 # ...by a variable name that looks like a scalar, i.e.
16717 # SORT var
16718 $self->scriptObj->set_declareMode('simple');
16719  
16720 # Get the array variable name
16721 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
16722 $self->scriptObj,
16723 $self->tokenGroupObj,
16724 );
16725  
16726 if (! defined $arrayExp) {
16727  
16728 return $self->scriptObj->setError(
16729 'missing_or_illegal_array_variable',
16730 $self->_objClass . '->parse',
16731 );
16732 }
16733  
16734 # Reset the temporary IV
16735 $self->scriptObj->set_declareMode('default');
16736  
16737 # Extract the optional scalar variable name
16738 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
16739  
16740 $scalarExp = Language::Axbasic::Expression::Lvalue->new(
16741 $self->scriptObj,
16742 $self->tokenGroupObj,
16743 );
16744  
16745 if (! defined $scalarExp) {
16746  
16747 return $self->scriptObj->setError(
16748 'missing_or_illegal_expression',
16749 $self->_objClass . '->parse',
16750 );
16751 }
16752 }
16753  
16754 if (! $self->tokenGroupObj->testStatementEnd()) {
16755  
16756 return $self->scriptObj->setError(
16757 'unexpected_keywords,_operators_or_expressions',
16758 $self->_objClass . '->parse',
16759 );
16760 }
16761  
16762 # Save the expression objects so $self->implement can use them, if it is called
16763 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
16764 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
16765  
16766 # Parsing complete
16767 return 1;
16768 }
16769  
16770 sub implement {
16771  
16772 # Called by LA::Line->implement directly after a call to $self->parse
16773 #
16774 # Expected arguments
16775 # (none besides $self)
16776 #
16777 # Return values
16778 # 'undef' on improper arguments
16779 # 1 otherwise
16780  
16781 my ($self, $check) = @_;
16782  
16783 # Local variables
16784 my ($arrayExp, $scalarExp, $removedVar);
16785  
16786 # Check for improper arguments
16787 if (defined $check) {
16788  
16789 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
16790 }
16791  
16792 # Retrieve the variables stored by ->parse
16793 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
16794 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
16795  
16796 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be popped. Multi-dimensional arrays
16797 # (e.g. DIM var (5, 5, 2) ) can't be popped
16798 if ($arrayExp->varObj->dimCount > 1) {
16799  
16800 return $self->scriptObj->setError(
16801 'POP_statement_cannot_operate_on_multi-dimensional_array',
16802 $self->_objClass . '->implement',
16803 );
16804 }
16805  
16806 # Cannot use a numeric array with a string scalar, and vice-versa
16807 if (
16808 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp->varObj) =~ m/Numeric/))
16809 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp->varObj) =~ m/String/))
16810 ) {
16811 return $self->scriptObj->setError(
16812 'type_mismatch_error',
16813 $self->_objClass . '->implement',
16814 );
16815 }
16816  
16817 # Pop the stack, and use the popped value to set the variable. (If the array is empty, we
16818 # get an empty string or zero, as appropriate)
16819 $removedVar = $arrayExp->varObj->doPop();
16820 if ($removedVar) {
16821  
16822 $scalarExp->varObj->set($removedVar->value);
16823 }
16824  
16825 # Implementation complete
16826 return 1;
16827 }
16828 }
16829  
16830 { package Language::Axbasic::Statement::print;
16831  
16832 use strict;
16833 use warnings;
16834 # use diagnostics;
16835  
16836 use Glib qw(TRUE FALSE);
16837  
16838 @Language::Axbasic::Statement::print::ISA = qw(
16839 Language::Axbasic
16840 Language::Axbasic::Statement
16841 );
16842  
16843 # PRINT [ expression [ separator ] [ expression [ separator ] ... ] ]
16844 # PRINT #channel: expression [ separator ] [ expression [ separator ] ... ]
16845  
16846 ##################
16847 # Methods
16848  
16849 sub parse {
16850  
16851 # Called by LA::Line->parse directly after a call to LA::Statement->new
16852 #
16853 # Expected arguments
16854 # (none besides $self)
16855 #
16856 # Return values
16857 # 'undef' on improper arguments or if there is an error
16858 # 1 otherwise
16859  
16860 my ($self, $check) = @_;
16861  
16862 # Local variables
16863 my ($tokenGroupObj, $token, $channel);
16864  
16865 # Check for improper arguments
16866 if (defined $check) {
16867  
16868 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
16869 }
16870  
16871 # Which token group to use - start with the existing one
16872 $tokenGroupObj = $self->tokenGroupObj;
16873  
16874 # If the first token is a file channel, extract it
16875 $token = $self->tokenGroupObj->lookAhead();
16876 if ($token && $token->category eq 'file_channel') {
16877  
16878 $self->tokenGroupObj->shiftToken();
16879  
16880 # For PRINT statements, the file channel must include a colon at the end (e.g. '#5:' )
16881 if (! ($token->tokenText =~ m/\:$/)) {
16882  
16883 return $self->scriptObj->setError(
16884 'syntax_error',
16885 $self->_objClass . '->parse',
16886 );
16887 }
16888  
16889 # Get the channel number
16890 $token->tokenText =~ m/([0-9]+)/;
16891 $channel = $1;
16892  
16893 # True BASIC specifies that the channel must be in the range 1-999; same range used by
16894 # Axbasic
16895 if ($channel < 1 || $channel > 999) {
16896  
16897 return $self->scriptObj->setError(
16898 'file_channel_NUM_out_of_range',
16899 $self->_objClass . '->parse',
16900 'NUM', $channel,
16901 );
16902  
16903 } else {
16904  
16905 # Store the channel number; this also informs $self->implement that we're reading
16906 # from a file, not the user's keyboard
16907 $self->ivAdd('parseDataHash', 'channel', $channel);
16908 }
16909 }
16910  
16911 # Deal with an empty print statement, i.e. <print> is taken to be <print "">
16912 if (defined $tokenGroupObj->testStatementEnd()) {
16913  
16914 # Create a token group to represent the implied null string
16915 $tokenGroupObj = Language::Axbasic::TokenGroup->new($self->scriptObj, '""');
16916 if (! defined $tokenGroupObj) {
16917  
16918 return $self->scriptObj->setDebug(
16919 'Can\'t create token group',
16920 $self->_objClass . '->parse',
16921 );
16922  
16923 } else {
16924  
16925 if (! $tokenGroupObj->lex()) {
16926  
16927 return undef;
16928 }
16929 }
16930 }
16931  
16932 do {
16933  
16934 my ($argListObj, $expression, $endChar);
16935  
16936 # Handle the pseudo-function TAB (), implemented in Axbasic as a weak keyword
16937 if (defined $tokenGroupObj->shiftMatchingToken('tab')) {
16938  
16939 # Get an argument list, which should contain exactly 1 argument
16940 $argListObj = Language::Axbasic::Expression::ArgList->new(
16941 $self->scriptObj,
16942 $tokenGroupObj,
16943 );
16944  
16945 if (! defined $argListObj || (scalar $argListObj->argList) != 1) {
16946  
16947 return $self->scriptObj->setError(
16948 'missing_or_invalid_argument_list',
16949 $self->_objClass . '->parse',
16950 );
16951 }
16952  
16953 # Otherwise, the next token is an expression
16954 } else {
16955  
16956 # Convert the <print> argument into an expression
16957 $expression = Language::Axbasic::Expression::Arithmetic->new(
16958 $self->scriptObj,
16959 $tokenGroupObj,
16960 );
16961  
16962 if (! defined $expression) {
16963  
16964 return $self->scriptObj->setError(
16965 'missing_or_illegal_expression',
16966 $self->_objClass . '->parse',
16967 );
16968 }
16969 }
16970  
16971 # Look for a comma or semicolon
16972 $token = $tokenGroupObj->shiftTokenIfCategory('separator');
16973 if (defined $token) {
16974  
16975 # It's a comma/semicolon
16976 $endChar = $token->tokenText;
16977  
16978 } elsif (defined $tokenGroupObj->testStatementEnd()) {
16979  
16980 # No comma or semicolon ending the print statement
16981 $endChar = '';
16982  
16983 } else {
16984  
16985 # Something else which shouldn't be there
16986 return $self->scriptObj->setError(
16987 'syntax_error',
16988 $self->_objClass . '->parse',
16989 );
16990 }
16991  
16992 # Save the arglist/expression and the end character (comma or semicolon) so that
16993 # $self->implement can use it, if it is called
16994 if (defined $argListObj) {
16995 $self->ivPush('parseDataList', $argListObj, $endChar);
16996 } else {
16997 $self->ivPush('parseDataList', $expression, $endChar);
16998 }
16999  
17000 } until (defined $tokenGroupObj->testStatementEnd());
17001  
17002 # Parsing complete
17003 return 1;
17004 }
17005  
17006 sub implement {
17007  
17008 # Called by LA::Line->implement directly after a call to $self->parse
17009 #
17010 # Expected arguments
17011 # (none besides $self)
17012 #
17013 # Return values
17014 # 'undef' on improper arguments or if there is an error
17015 # 1 otherwise
17016  
17017 my ($self, $check) = @_;
17018  
17019 # Local variables
17020 my (
17021 $channel, $session, $taskObj, $channelObj, $fileHandle, $line, $newLineCharFlag,
17022 @printList,
17023 );
17024  
17025 # Check for improper arguments
17026 if (defined $check) {
17027  
17028 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17029 }
17030  
17031 # Retrieve the components stored by $self->parse
17032 $channel = $self->ivShow('parseDataHash', 'channel');
17033 @printList = $self->parseDataList;
17034  
17035 # For convenience, import the GA::Session and Script task (if any)
17036 $session = $self->scriptObj->session;
17037 $taskObj = $self->scriptObj->parentTask;
17038  
17039 # Deal with writing to a file, if a file channel was specified
17040 if (defined $channel) {
17041  
17042 # Check that the file channel exists
17043 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
17044  
17045 return $self->scriptObj->setError(
17046 'file_channel_NUM_not_open',
17047 $self->_objClass . '->implement',
17048 'NUM', $channel,
17049 );
17050  
17051 } else {
17052  
17053 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
17054 $fileHandle = $channelObj->fileHandle;
17055 }
17056  
17057 # Check that writing to the file channel is allowed
17058 if ($channelObj->accessType eq 'input') {
17059  
17060 return $self->scriptObj->setError(
17061 'file_channel_NUM_is_read_only',
17062 $self->_objClass . '->implement',
17063 'NUM', $channel,
17064 );
17065 }
17066  
17067 # Prepare the line to write to the file channel
17068 $line = '';
17069 # End the line with a newline char, unless the expressions end with a ';' or ','
17070 $newLineCharFlag = TRUE;
17071  
17072 while (@printList) {
17073  
17074 my ($expression, $endChar, $string, $number);
17075  
17076 $expression = shift @printList;
17077 $endChar = shift @printList;
17078  
17079 # Evaluate the expression. If there's been an error, ->setError should already have
17080 # been called to display the error message (and $string) will be 'undef')
17081 $string = $expression->evaluate();
17082 if (! defined $string) {
17083  
17084 # Implementation complete
17085 return 1;
17086  
17087 } else {
17088  
17089 $line .= $string;
17090 }
17091  
17092 # (No space is added after a number, when writing to a file channel)
17093  
17094 if ($endChar eq ',') {
17095  
17096 $number = 14 - ((length $line) % 14);
17097 $line .= (' ' x $number);
17098 $newLineCharFlag = FALSE;
17099  
17100 } elsif ($endChar eq ';') {
17101  
17102 $newLineCharFlag = FALSE;
17103  
17104 } else {
17105  
17106 $newLineCharFlag = TRUE;
17107 }
17108 }
17109  
17110 # Write the line to the file channel
17111 if ($newLineCharFlag) {
17112  
17113 $line .= "\n";
17114 }
17115  
17116 print $fileHandle $line;
17117  
17118 } else {
17119  
17120 # Otherwise, display the expressions, one after the other
17121 while (@printList) {
17122  
17123 my ($expression, $argListObj, $arg, $columns, $endChar, $string, $before, $after);
17124  
17125 $expression = shift @printList;
17126 $endChar = shift @printList;
17127  
17128 # In the case of TAB (n), the expression could be a LA::Expression::ArgList
17129 if ($expression->isa('Language::Axbasic::Expression::ArgList')) {
17130  
17131 # Evaluate the first item in the arglist, n, which should be an integer
17132 # The documentation is a little inconsistent about what should happen for
17133 # non-integer values, and the authors have tested old BASIC programmes which
17134 # produce them
17135 # For that reason, round down any floating point numbers, and any use column 1
17136 # for any value less than one (the latter suggested by the True BASIC docs)
17137 $arg = $expression->ivIndex('argList', 0);
17138 $columns = $arg->evaluate();
17139  
17140 if (! ($columns =~ m/^[-]?\d+(\.\d*)?$/)) {
17141  
17142 return $self->scriptObj->setError(
17143 'invalid_TAB_column_NUM',
17144 $self->_objClass . '->implement',
17145 'NUM', $columns,
17146 );
17147  
17148 } elsif ($columns < 1) {
17149  
17150 $columns = 1;
17151  
17152 } else {
17153  
17154 $columns = int($columns);
17155 }
17156  
17157 # $columns is a column number. Decrement it so it uses the same column numbering
17158 # system as LA::Script->column
17159 $columns--;
17160 if ($columns > $self->scriptObj->column) {
17161  
17162 # Move the cursor by adding some space characters on the current line
17163 $string = ' ' x ($columns - $self->scriptObj->column);
17164  
17165 } elsif ($columns == $self->scriptObj->column) {
17166  
17167 # Cursor is already at the correct position
17168 $string = '';
17169  
17170 } else {
17171  
17172 # Skip to the next line, and add some space characters there
17173 $string = ' ' x $columns;
17174  
17175 if ($self->scriptObj->forcedWinFlag) {
17176 $taskObj->insertPrint('');
17177 } else {
17178 $session->writeText('');
17179 }
17180 }
17181  
17182 } else {
17183  
17184  
17185 # Evaluate the expression. If there's been an error, ->setError should already
17186 # have been called to display the error message (and $string) will be 'undef')
17187 $string = $expression->evaluate();
17188 if (! defined $string) {
17189  
17190 # Implementation complete
17191 return 1;
17192 }
17193 }
17194  
17195 # In the original BASIC dialects, numerical values are preceded by a minus sign or
17196 # a leading space; and always followed by a trailing space
17197 if (ref($expression) =~ m/Numeric/) {
17198  
17199 if ($string >= 0) {
17200  
17201 $string = ' ' . $string;
17202 }
17203  
17204 $string .= ' ';
17205 }
17206  
17207 # Display the expressions in the 'main' window (unless $self->forcedWinFlag is set,
17208 # in which case the output is redirected to the task window)
17209  
17210 # Handle the end character (comma or semicolon)
17211 if ($endChar eq ',') {
17212  
17213 $after = 14 - (length($string) % 14);
17214 if ($after < 14) {
17215  
17216 $string .= ' ' x $after;
17217 }
17218  
17219 $before = 14 - ($self->scriptObj->column % 14);
17220 if ($before < 14) {
17221  
17222 $string = (' ' x $before) . $string;
17223 }
17224  
17225 # Display the string without a trailing newline character and adjust the column
17226 # accordingly
17227 if ($self->scriptObj->forcedWinFlag) {
17228  
17229 # (If ->column is not 0, the previous PRINT expression must have used a ','
17230 # or ';' character. When writing to the task window, 'echo' means 'no
17231 # newline character after this text')
17232 if ($self->scriptObj->column) {
17233 $taskObj->insertPrint($string, 'echo');
17234 } else {
17235 $taskObj->insertPrint($string);
17236 }
17237  
17238 } else {
17239  
17240 # (When writing to the 'main' window, 'echo' means 'no newline character
17241 # before this text')
17242 $session->writeText($string, 'echo');
17243 }
17244  
17245 $self->scriptObj->set_column($self->scriptObj->column + length($string));
17246  
17247 } elsif ($endChar eq ';') {
17248  
17249 # Display the string without a trailing newline character and adjust the column
17250 # accordingly
17251 if ($self->scriptObj->forcedWinFlag) {
17252  
17253 if ($self->scriptObj->column) {
17254 $taskObj->insertPrint($string, 'echo');
17255 } else {
17256 $taskObj->insertPrint($string);
17257 }
17258  
17259 } else {
17260  
17261 $session->writeText($string, 'echo');
17262 }
17263  
17264 $self->scriptObj->set_column($self->scriptObj->column + length($string));
17265  
17266 } else {
17267  
17268 # Display the string with a trailing newline character
17269 if ($self->scriptObj->forcedWinFlag) {
17270  
17271 if ($self->scriptObj->column) {
17272 $taskObj->insertPrint($string, 'echo');
17273 } else {
17274 $taskObj->insertPrint($string);
17275 }
17276  
17277 } else {
17278  
17279 $session->writeText($string);
17280 }
17281  
17282 $self->scriptObj->set_column(0);
17283 }
17284 }
17285 }
17286  
17287 # Make sure the text is visible immediately
17288 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->implement');
17289  
17290 # Implementation complete
17291 return 1;
17292 }
17293 }
17294  
17295 { package Language::Axbasic::Statement::profile;
17296  
17297 use strict;
17298 use warnings;
17299 # use diagnostics;
17300  
17301 use Glib qw(TRUE FALSE);
17302  
17303 @Language::Axbasic::Statement::profile::ISA = qw(
17304 Language::Axbasic
17305 Language::Axbasic::Statement
17306 );
17307  
17308 # PROFILE [ expression ]
17309  
17310 ##################
17311 # Methods
17312  
17313 sub parse {
17314  
17315 # Called by LA::Line->parse directly after a call to LA::Statement->new
17316 #
17317 # Expected arguments
17318 # (none besides $self)
17319 #
17320 # Return values
17321 # 'undef' on improper arguments or if there is an error
17322 # 1 otherwise
17323  
17324 my ($self, $check) = @_;
17325  
17326 # Local variables
17327 my $nameExp;
17328  
17329 # Check for improper arguments
17330 if (defined $check) {
17331  
17332 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17333 }
17334  
17335 if (! $self->tokenGroupObj->testStatementEnd()) {
17336  
17337 # Convert the name string into an expression
17338 $nameExp = Language::Axbasic::Expression::Arithmetic->new(
17339 $self->scriptObj,
17340 $self->tokenGroupObj,
17341 );
17342  
17343 if (! defined $nameExp) {
17344  
17345 return $self->scriptObj->setError(
17346 'missing_or_illegal_expression',
17347 $self->_objClass . '->parse',
17348 );
17349 }
17350 }
17351  
17352 # Check that nothing more remains
17353 if (! $self->tokenGroupObj->testStatementEnd()) {
17354  
17355 return $self->scriptObj->setError(
17356 'unexpected_keywords,_operators_or_expressions',
17357 $self->_objClass . '->parse',
17358 );
17359 }
17360  
17361 if ($nameExp) {
17362  
17363 # Store the expression, so $self->implement can retrieve it
17364 $self->ivAdd('parseDataHash', 'name', $nameExp);
17365 }
17366  
17367 # Parsing complete
17368 return 1;
17369 }
17370  
17371 sub implement {
17372  
17373 # Called by LA::Line->implement directly after a call to $self->parse
17374 #
17375 # Expected arguments
17376 # (none besides $self)
17377 #
17378 # Return values
17379 # 'undef' on improper arguments or if there is an error
17380 # 1 otherwise
17381  
17382 my ($self, $check) = @_;
17383  
17384 # Local variables
17385 my ($nameExp, $name);
17386  
17387 # Check for improper arguments
17388 if (defined $check) {
17389  
17390 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17391 }
17392  
17393 # Retrieve the argument stored by $self->parse
17394 $nameExp = $self->ivShow('parseDataHash', 'name');
17395  
17396 if (defined $nameExp) {
17397  
17398 # Evaluate the expression
17399 $name = $nameExp->evaluate();
17400  
17401 # Check that the profile actually exists
17402 if (! $self->scriptObj->session->ivExists('profHash', $name)) {
17403  
17404 # It doesn't exist, so resume using the current world
17405 $self->scriptObj->set_useProfile($self->scriptObj->session->currentWorld->name);
17406  
17407 } else {
17408  
17409 # Use the specified profile
17410 $self->scriptObj->set_useProfile($name);
17411 }
17412  
17413 } else {
17414  
17415 # No profile specified, so resume using the current world
17416 $self->scriptObj->set_useProfile($self->scriptObj->session->currentWorld->name);
17417 }
17418  
17419 # Implementation complete
17420 return 1;
17421 }
17422 }
17423  
17424 { package Language::Axbasic::Statement::push;
17425  
17426 use strict;
17427 use warnings;
17428 # use diagnostics;
17429  
17430 use Glib qw(TRUE FALSE);
17431  
17432 @Language::Axbasic::Statement::push::ISA = qw(
17433 Language::Axbasic
17434 Language::Axbasic::Statement
17435 );
17436  
17437 # PUSH array-name , expression
17438  
17439 ##################
17440 # Methods
17441  
17442 sub parse {
17443  
17444 # Called by LA::Line->parse directly after a call to LA::Statement->new
17445 #
17446 # Expected arguments
17447 # (none besides $self)
17448 #
17449 # Return values
17450 # 'undef' on improper arguments or if there is an error
17451 # 1 otherwise
17452  
17453 my ($self, $check) = @_;
17454  
17455 # Local variables
17456 my ($arrayExp, $scalarExp);
17457  
17458 # Check for improper arguments
17459 if (defined $check) {
17460  
17461 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17462 }
17463  
17464 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
17465 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
17466 # that created by
17467 # DIM var (10)
17468 # ...by a variable name that looks like a scalar, i.e.
17469 # SORT var
17470 $self->scriptObj->set_declareMode('simple');
17471  
17472 # Get the array variable name
17473 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
17474 $self->scriptObj,
17475 $self->tokenGroupObj,
17476 );
17477  
17478 if (! defined $arrayExp) {
17479  
17480 return $self->scriptObj->setError(
17481 'missing_or_illegal_array_variable',
17482 $self->_objClass . '->parse',
17483 );
17484 }
17485  
17486 # Reset the temporary IV
17487 $self->scriptObj->set_declareMode('default');
17488  
17489 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
17490  
17491 return $self->scriptObj->setError(
17492 'syntax_error',
17493 $self->_objClass . '->parse',
17494 );
17495 }
17496  
17497 # Extract the non-optional scalar expression
17498 $scalarExp = Language::Axbasic::Expression::Arithmetic->new(
17499 $self->scriptObj,
17500 $self->tokenGroupObj,
17501 );
17502  
17503 if (! defined $scalarExp) {
17504  
17505 return $self->scriptObj->setError(
17506 'missing_or_illegal_expression',
17507 $self->_objClass . '->parse',
17508 );
17509 }
17510  
17511 if (! $self->tokenGroupObj->testStatementEnd()) {
17512  
17513 return $self->scriptObj->setError(
17514 'unexpected_keywords,_operators_or_expressions',
17515 $self->_objClass . '->parse',
17516 );
17517 }
17518  
17519 # Save the expression objects so $self->implement can use them, if it is called
17520 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
17521 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
17522  
17523 # Parsing complete
17524 return 1;
17525 }
17526  
17527 sub implement {
17528  
17529 # Called by LA::Line->implement directly after a call to $self->parse
17530 #
17531 # Expected arguments
17532 # (none besides $self)
17533 #
17534 # Return values
17535 # 'undef' on improper arguments
17536 # 1 otherwise
17537  
17538 my ($self, $check) = @_;
17539  
17540 # Local variables
17541 my ($arrayExp, $scalarExp, $removedVar);
17542  
17543 # Check for improper arguments
17544 if (defined $check) {
17545  
17546 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17547 }
17548  
17549 # Retrieve the variables stored by ->parse
17550 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
17551 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
17552  
17553 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be pushed. Multi-dimensional arrays
17554 # (e.g. DIM var (5, 5, 2) ) can't be pushed
17555 if ($arrayExp->varObj->dimCount > 1) {
17556  
17557 return $self->scriptObj->setError(
17558 'PUSH_statement_cannot_operate_on_multi-dimensional_array',
17559 $self->_objClass . '->implement',
17560 );
17561 }
17562  
17563 # Cannot use a numeric array with a string scalar, and vice-versa
17564 if (
17565 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp) =~ m/Numeric/))
17566 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp) =~ m/String/))
17567 ) {
17568 return $self->scriptObj->setError(
17569 'type_mismatch_error',
17570 $self->_objClass . '->implement',
17571 );
17572 }
17573  
17574 # Evaluate the expression, and push it to the stack
17575 $arrayExp->varObj->doPush($scalarExp->evaluate());
17576  
17577 # Implementation complete
17578 return 1;
17579 }
17580 }
17581  
17582 { package Language::Axbasic::Statement::randomize;
17583  
17584 use strict;
17585 use warnings;
17586 # use diagnostics;
17587  
17588 use Glib qw(TRUE FALSE);
17589  
17590 @Language::Axbasic::Statement::randomize::ISA = qw(
17591 Language::Axbasic
17592 Language::Axbasic::Statement
17593 );
17594  
17595 # RANDOMIZE
17596  
17597 ##################
17598 # Methods
17599  
17600 sub parse {
17601  
17602 # Called by LA::Line->parse directly after a call to LA::Statement->new
17603 #
17604 # Expected arguments
17605 # (none besides $self)
17606 #
17607 # Return values
17608 # 'undef' on improper arguments or if there is an error
17609 # 1 otherwise
17610  
17611 my ($self, $check) = @_;
17612  
17613 # Local variables
17614 my ($expression);
17615  
17616 # Check for improper arguments
17617 if (defined $check) {
17618  
17619 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17620 }
17621  
17622 # RANDOMIZE statements always appear on their own
17623 if (! $self->tokenGroupObj->testStatementEnd()) {
17624  
17625 return $self->scriptObj->setError(
17626 'unexpected_keywords,_operators_or_expressions',
17627 $self->_objClass . '->parse',
17628 );
17629 }
17630  
17631 # Parsing complete
17632 return 1;
17633 }
17634  
17635 # sub implement {} # ->implement method from LA::Statement inherited
17636 }
17637  
17638 { package Language::Axbasic::Statement::read;
17639  
17640 use strict;
17641 use warnings;
17642 # use diagnostics;
17643  
17644 use Glib qw(TRUE FALSE);
17645  
17646 @Language::Axbasic::Statement::read::ISA = qw(
17647 Language::Axbasic
17648 Language::Axbasic::Statement
17649 );
17650  
17651 # READ variable-name [ , variable-name ... ]
17652  
17653 ##################
17654 # Methods
17655  
17656 sub parse {
17657  
17658 # Called by LA::Line->parse directly after a call to LA::Statement->new
17659 #
17660 # Expected arguments
17661 # (none besides $self)
17662 #
17663 # Return values
17664 # 'undef' on improper arguments or if there is an error
17665 # 1 otherwise
17666  
17667 my ($self, $check) = @_;
17668  
17669 # Check for improper arguments
17670 if (defined $check) {
17671  
17672 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17673 }
17674  
17675 # The rest of the statement is a list of lvalues
17676 do {
17677  
17678 my $expression = Language::Axbasic::Expression::Lvalue->new(
17679 $self->scriptObj,
17680 $self->tokenGroupObj,
17681 );
17682  
17683 if (! defined $expression) {
17684  
17685 return $self->scriptObj->setError(
17686 'missing_or_illegal_variable',
17687 $self->_objClass . '->parse',
17688 );
17689  
17690 } else {
17691  
17692 $self->ivPush('parseDataList', $expression);
17693 }
17694  
17695 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
17696  
17697 # Parsing complete
17698 return 1;
17699 }
17700  
17701 sub implement {
17702  
17703 # Called by LA::Line->implement directly after a call to $self->parse
17704 #
17705 # Expected arguments
17706 # (none besides $self)
17707 #
17708 # Return values
17709 # 'undef' on improper arguments or if there is an error
17710 # 1 otherwise
17711  
17712 my ($self, $check) = @_;
17713  
17714 # Local variables
17715 my @lvalueList;
17716  
17717 # Check for improper arguments
17718 if (defined $check) {
17719  
17720 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17721 }
17722  
17723 # Retrieve the list of lvalues stored by $self->parse
17724 @lvalueList = $self->parseDataList;
17725 foreach my $lvalue (@lvalueList) {
17726  
17727 my ($var, $data, $value);
17728  
17729 $var = $lvalue->variable;
17730 if (! $var) {
17731  
17732 # Subscript out of bounds, or similar error, has already been set
17733 return undef;
17734 }
17735  
17736 $data = $self->scriptObj->shift_readDataList();
17737  
17738 if (! defined $data) {
17739  
17740 return $self->scriptObj->setError(
17741 'reading_past_end_of_data',
17742 $self->_objClass . '->implement',
17743 );
17744 }
17745  
17746 # $data is a LA::Expression::Constant, but we still have to evaluate it
17747 $value = $data->evaluate();
17748 $var->set($value);
17749 }
17750  
17751 # Implementation complete
17752 return 1;
17753 }
17754 }
17755  
17756 { package Language::Axbasic::Statement::redim;
17757  
17758 use strict;
17759 use warnings;
17760 # use diagnostics;
17761  
17762 use Glib qw(TRUE FALSE);
17763  
17764 @Language::Axbasic::Statement::redim::ISA = qw(
17765 Language::Axbasic
17766 Language::Axbasic::Statement
17767 );
17768  
17769 # REDIM variable-name [ arg-list ] [ , variable-name [ arg-list ] ... ]
17770  
17771 ##################
17772 # Methods
17773  
17774 sub parse {
17775  
17776 # Called by LA::Line->parse directly after a call to LA::Statement->new
17777 #
17778 # Expected arguments
17779 # (none besides $self)
17780 #
17781 # Return values
17782 # 'undef' on improper arguments or if there is an error
17783 # 1 otherwise
17784  
17785 my ($self, $check) = @_;
17786  
17787 # Local variables
17788 my $specialFlag;
17789  
17790 # Check for improper arguments
17791 if (defined $check) {
17792  
17793 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17794 }
17795  
17796 if ($self->scriptObj->executionMode eq 'line_num') {
17797  
17798 # In programmes with line numbers, we don't allow DIM .. (10 TO 20)
17799 $specialFlag = FALSE;
17800  
17801 } else {
17802  
17803 # A TRUE argument tells LA::Expression::Lvalue->new to attempt to extract an
17804 # LA::Expression::SpecialArgList, rather than an an LA::Expression::ArgList
17805 $specialFlag = TRUE;
17806 }
17807  
17808 # Process each array in turn (if several appear on the same line, they are separated by
17809 # commas)
17810 do {
17811  
17812 my $expression = Language::Axbasic::Expression::Lvalue->new(
17813 $self->scriptObj,
17814 $self->tokenGroupObj,
17815 $specialFlag,
17816 );
17817  
17818 if (! defined $expression) {
17819  
17820 return $self->scriptObj->setError(
17821 'missing_or_illegal_expression',
17822 $self->_objClass . '->parse',
17823 );
17824  
17825 } else {
17826  
17827 # Save the expression object so $self->implement can use it, if it is called
17828 $self->ivPush('parseDataList', $expression);
17829 }
17830  
17831 } while (defined $self->tokenGroupObj->shiftMatchingToken(','));
17832  
17833 # Parsing complete
17834 return 1;
17835 }
17836  
17837 sub implement {
17838  
17839 # Called by LA::Line->implement directly after a call to $self->parse
17840 #
17841 # Expected arguments
17842 # (none besides $self)
17843 #
17844 # Return values
17845 # 'undef' on improper arguments or if there is an error
17846 # 1 otherwise
17847  
17848 my ($self, $check) = @_;
17849  
17850 # Local variables
17851 my @expList;
17852  
17853 # Check for improper arguments
17854 if (defined $check) {
17855  
17856 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
17857 }
17858  
17859 # Import the list of expressions saved by $self->parse
17860 @expList = $self->parseDataList;
17861  
17862 # Redimension each array in turn
17863 foreach my $expression (@expList) {
17864  
17865 my (@upperList, @boundList, @flatList);
17866  
17867 # If the $expression appeared in a line like REDIM var, rather than the correct REDIM
17868 # var(10), then ->argListObj won't be defined
17869 if (! defined $expression->argListObj) {
17870  
17871 return $self->scriptObj->setError(
17872 'invalid_expression_in_REDIM_statement',
17873 $self->_objClass . '->implement',
17874 );
17875 }
17876  
17877 if ($self->scriptObj->executionMode eq 'line_num') {
17878  
17879 # Set up the array. ->evaluate returns a list of upper bounds
17880 @upperList = $expression->argListObj->evaluate();
17881  
17882 # Convert that to a flat list in groups of two, in the form
17883 # (lower, upper, lower, upper...)
17884 # For programmes with line numbers, the lower bound is always 0 (see the explanatory
17885 # comments in LA::Variable::Array->new)
17886 # For any expression that could not be evaluated, an 'undef' value was placed in
17887 # @boundList, so we need to check for that too
17888 foreach my $value (@upperList) {
17889  
17890 if (! defined $value || $value =~ m/\D/) {
17891  
17892 return $self->scriptObj->setError(
17893 'invalid_bound_for_array_dimension',
17894 $self->_objClass . '->implement',
17895 );
17896  
17897 } else {
17898  
17899 push (@flatList, 0, $value);
17900 }
17901 }
17902  
17903 } else {
17904  
17905 # Set up the array. ->evaluate returns a list of list references. Each list
17906 # reference represents a dimension and specifies the bounds of that dimension;
17907 # either in the form (upper) or (lower, upper)
17908 @boundList = $expression->argListObj->evaluate();
17909  
17910 # Convert that to a flat list in groups of two, in the form
17911 # (lower, upper, lower, upper...)
17912 # For programmes without line numbers, we use 1 as the lower bound, if not
17913 # specified
17914 # For any expression that could not be evaluated, an 'undef' value was placed in
17915 # @boundList, so we need to check for that too
17916 foreach my $listRef (@boundList) {
17917  
17918 foreach my $value (@$listRef) {
17919  
17920 if (! defined $value || ! ($value =~ m/^[-]?\d+$/)) {
17921  
17922 return $self->scriptObj->setError(
17923 'invalid_bound_for_array_dimension',
17924 $self->_objClass . '->implement',
17925 );
17926 }
17927 }
17928  
17929 if (scalar (@$listRef) == 1) {
17930  
17931 # If the lower bound is not specified, it is 1; therefore in that case, the
17932 # upper bound cannot be less than 1)
17933 if ($$listRef[0] < 1) {
17934  
17935 return $self->scriptObj->setError(
17936 'invalid_bound_for_array_dimension',
17937 $self->_objClass . '->implement',
17938 );
17939  
17940 } else {
17941  
17942 push (@flatList, 1);
17943 }
17944 }
17945  
17946 push (@flatList, @$listRef);
17947 }
17948 }
17949  
17950 # Redimension the array
17951 $expression->varObj->dimension(@flatList);
17952 }
17953  
17954 # Implementation complete
17955 return 1;
17956 }
17957 }
17958  
17959 { package Language::Axbasic::Statement::relay;
17960  
17961 use strict;
17962 use warnings;
17963 # use diagnostics;
17964  
17965 use Glib qw(TRUE FALSE);
17966  
17967 @Language::Axbasic::Statement::relay::ISA = qw(
17968 Language::Axbasic
17969 Language::Axbasic::Statement
17970 );
17971  
17972 # RELAY expression [ , expression ]
17973  
17974 ##################
17975 # Methods
17976  
17977 sub parse {
17978  
17979 # Called by LA::Line->parse directly after a call to LA::Statement->new
17980 #
17981 # Expected arguments
17982 # (none besides $self)
17983 #
17984 # Return values
17985 # 'undef' on improper arguments or if there is an error
17986 # 1 otherwise
17987  
17988 my ($self, $check) = @_;
17989  
17990 # Local variables
17991 my ($cmdExp, $token, $obscureExp);
17992  
17993 # Check for improper arguments
17994 if (defined $check) {
17995  
17996 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
17997 }
17998  
17999 # Get the expression and store it for ->implement to use
18000 $cmdExp = Language::Axbasic::Expression::Arithmetic->new(
18001 $self->scriptObj,
18002 $self->tokenGroupObj,
18003 );
18004  
18005 if (! defined $cmdExp) {
18006  
18007 return $self->scriptObj->setError(
18008 'missing_or_illegal_expression',
18009 $self->_objClass . '->parse',
18010 );
18011 }
18012  
18013 # Get the second expression, if specified
18014 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
18015  
18016 $token = $self->tokenGroupObj->lookAhead();
18017 if (defined $token) {
18018  
18019 $obscureExp = Language::Axbasic::Expression::Arithmetic->new(
18020 $self->scriptObj,
18021 $self->tokenGroupObj,
18022 );
18023  
18024 if (! defined $obscureExp) {
18025  
18026 return $self->scriptObj->setError(
18027 'missing_or_illegal_expression',
18028 $self->_objClass . '->parse',
18029 );
18030 }
18031 }
18032 }
18033  
18034 # There should be nothing after the expression
18035 if (! $self->tokenGroupObj->testStatementEnd()) {
18036  
18037 return $self->scriptObj->setError(
18038 'unexpected_keywords,_operators_or_expressions',
18039 $self->_objClass . '->parse',
18040 );
18041 }
18042  
18043 # Store the expressions, so $self->implement can retrieve them
18044 $self->ivAdd('parseDataHash', 'cmd_exp', $cmdExp);
18045 $self->ivAdd('parseDataHash', 'obscure_exp', $obscureExp); # May be 'undef'
18046  
18047 # Parsing complete
18048 return 1;
18049 }
18050  
18051 sub implement {
18052  
18053 # Called by LA::Line->implement directly after a call to $self->parse
18054 #
18055 # Expected arguments
18056 # (none besides $self)
18057 #
18058 # Return values
18059 # 'undef' on improper arguments or if there is an error
18060 # 1 otherwise
18061  
18062 my ($self, $check) = @_;
18063  
18064 # Local variables
18065 my ($cmdExp, $obscureExp, $cmd, $obscure);
18066  
18067 # Check for improper arguments
18068 if (defined $check) {
18069  
18070 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18071 }
18072  
18073 # Retrieve the arguments stored by $self->parse
18074 $cmdExp = $self->ivShow('parseDataHash', 'cmd_exp');
18075 $obscureExp = $self->ivShow('parseDataHash', 'obscure_exp');
18076  
18077 # Evaluate the expression to get a world command
18078 $cmd = $cmdExp->evaluate();
18079 if ($obscureExp) {
18080  
18081 $obscure = $obscureExp->evaluate();
18082 }
18083  
18084 # Send the command to the world
18085 if ($obscureExp) {
18086  
18087 # If some part of the command has to be obscured in the 'main' window, we don't have to
18088 # worry about classifying it as a non-movement command; the GA::Session doesn't store
18089 # it anywhere
18090 $self->scriptObj->session->worldCmd($cmd, $obscure);
18091  
18092 } else {
18093  
18094 # It's an ordinary relay command
18095 $self->scriptObj->session->relayCmd($cmd);
18096 }
18097  
18098 # Implementation complete
18099 return 1;
18100 }
18101 }
18102  
18103 { package Language::Axbasic::Statement::rem;
18104  
18105 use strict;
18106 use warnings;
18107 # use diagnostics;
18108  
18109 use Glib qw(TRUE FALSE);
18110  
18111 @Language::Axbasic::Statement::rem::ISA = qw(
18112 Language::Axbasic
18113 Language::Axbasic::Statement
18114 );
18115  
18116 # REM [ ... ]
18117  
18118 ##################
18119 # Methods
18120  
18121 sub parse {
18122  
18123 # Called by LA::Line->parse directly after a call to LA::Statement->new
18124 #
18125 # Expected arguments
18126 # (none besides $self)
18127 #
18128 # Return values
18129 # 'undef' on improper arguments or if there is an error
18130 # 1 otherwise
18131  
18132 my ($self, $check) = @_;
18133  
18134 # Local variables
18135 my $token;
18136  
18137 # Check for improper arguments
18138 if (defined $check) {
18139  
18140 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18141 }
18142  
18143 # Every token on a line after a 'rem' statement is part of the remark, and must be ignored
18144 $self->tokenGroupObj->set_tokenList();
18145  
18146 return 1;
18147 }
18148  
18149 # sub implement {} # ->implement method from LA::Statement inherited
18150 }
18151  
18152 { package Language::Axbasic::Statement::reset;
18153  
18154 use strict;
18155 use warnings;
18156 # use diagnostics;
18157  
18158 use Glib qw(TRUE FALSE);
18159  
18160 @Language::Axbasic::Statement::reset::ISA = qw(
18161 Language::Axbasic
18162 Language::Axbasic::Statement
18163 );
18164  
18165 # RESET #channel: BEGIN
18166 # RESET #channel: END
18167  
18168 ##################
18169 # Methods
18170  
18171 sub parse {
18172  
18173 # Called by LA::Line->parse directly after a call to LA::Statement->new
18174 #
18175 # Expected arguments
18176 # (none besides $self)
18177 #
18178 # Return values
18179 # 'undef' on improper arguments or if there is an error
18180 # 1 otherwise
18181  
18182 my ($self, $check) = @_;
18183  
18184 # Local variables
18185 my ($channelToken, $channel, $nextToken);
18186  
18187 # Check for improper arguments
18188 if (defined $check) {
18189  
18190 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18191 }
18192  
18193 # Get the channel token. For RESET statements, it must include a colon at the end
18194 # (e.g. '#5:' )
18195 $channelToken = $self->tokenGroupObj->shiftTokenIfCategory('file_channel');
18196 if (! defined $channelToken || ! ($channelToken->tokenText =~ m/\:$/)) {
18197  
18198 return $self->scriptObj->setError(
18199 'syntax_error',
18200 $self->_objClass . '->parse',
18201 );
18202  
18203 } else {
18204  
18205 # Store the channel number
18206 $channelToken->tokenText =~ m/([0-9]+)/;
18207 $channel = $1;
18208  
18209 # True BASIC specifies that the channel must be in the range 1-999; same range used by
18210 # Axbasic
18211 if ($channel < 1 || $channel > 999) {
18212  
18213 return $self->scriptObj->setError(
18214 'file_channel_NUM_out_of_range',
18215 $self->_objClass . '->parse',
18216 'NUM', $channel,
18217 );
18218  
18219 } else {
18220  
18221 $self->ivAdd('parseDataHash', 'channel', $channel);
18222 }
18223 }
18224  
18225 # The next token must be one of the keywords BEGIN or END
18226 $nextToken = $self->tokenGroupObj->shiftTokenIfCategory('keyword');
18227 if (
18228 ! $nextToken
18229 || ($nextToken->tokenText ne 'begin' && $nextToken->tokenText ne 'end')
18230 ) {
18231 return $self->scriptObj->setError(
18232 'syntax_error',
18233 $self->_objClass . '->parse',
18234 );
18235  
18236 } else {
18237  
18238 $self->ivAdd('parseDataHash', 'type', $nextToken->tokenText);
18239 }
18240  
18241 # Check that nothing follows the BEGIN/END keywords
18242 if (! $self->tokenGroupObj->testStatementEnd()) {
18243  
18244 return $self->scriptObj->setError(
18245 'unexpected_keywords,_operators_or_expressions',
18246 $self->_objClass . '->parse',
18247 );
18248 }
18249  
18250 # Parsing complete
18251 return 1;
18252 }
18253  
18254 sub implement {
18255  
18256 # Called by LA::Line->implement directly after a call to $self->parse
18257 #
18258 # Expected arguments
18259 # (none besides $self)
18260 #
18261 # Return values
18262 # 'undef' on improper arguments or if there is an error
18263 # 1 otherwise
18264  
18265 my ($self, $check) = @_;
18266  
18267 # Local variables
18268 my ($channel, $type, $channelObj);
18269  
18270 # Check for improper arguments
18271 if (defined $check) {
18272  
18273 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18274 }
18275  
18276 # Retrieve the variables stored by ->parse
18277 $channel = $self->ivShow('parseDataHash', 'channel');
18278 $type = $self->ivShow('parseDataHash', 'type');
18279  
18280 # Check that the file channel is open
18281 if (! $self->scriptObj->ivExists('fileChannelHash', $channel)) {
18282  
18283 return $self->scriptObj->setError(
18284 'file_channel_NUM_not_open',
18285 $self->_objClass . '->implement',
18286 'NUM', $channel,
18287 );
18288  
18289 } else {
18290  
18291 $channelObj = $self->scriptObj->ivShow('fileChannelHash', $channel);
18292 }
18293  
18294 # Move the pointer
18295 if ($type eq 'begin') {
18296 seek($channelObj->fileHandle, 0, Fcntl::SEEK_SET);
18297 } elsif ($type eq 'end') {
18298 seek($channelObj->fileHandle, 0, Fcntl::SEEK_END);
18299 }
18300  
18301 # Implementation complete
18302 return 1;
18303 }
18304 }
18305  
18306 { package Language::Axbasic::Statement::restore;
18307  
18308 use strict;
18309 use warnings;
18310 # use diagnostics;
18311  
18312 use Glib qw(TRUE FALSE);
18313  
18314 @Language::Axbasic::Statement::restore::ISA = qw(
18315 Language::Axbasic
18316 Language::Axbasic::Statement
18317 );
18318  
18319 # RESTORE
18320  
18321 ##################
18322 # Methods
18323  
18324 sub parse {
18325  
18326 # Called by LA::Line->parse directly after a call to LA::Statement->new
18327 #
18328 # Expected arguments
18329 # (none besides $self)
18330 #
18331 # Return values
18332 # 'undef' on improper arguments or if there is an error
18333 # 1 otherwise
18334  
18335 my ($self, $check) = @_;
18336  
18337 # Check for improper arguments
18338 if (defined $check) {
18339  
18340 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18341 }
18342  
18343 # RESTORE statements always appear on their own
18344 if (! $self->tokenGroupObj->testStatementEnd()) {
18345  
18346 return $self->scriptObj->setError(
18347 'unexpected_keywords,_operators_or_expressions',
18348 $self->_objClass . '->parse',
18349 );
18350 }
18351  
18352 # Parsing complete
18353 return 1;
18354 }
18355  
18356 sub implement {
18357  
18358 # Called by LA::Line->implement directly after a call to $self->parse
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 # Check for improper arguments
18370 if (defined $check) {
18371  
18372 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18373 }
18374  
18375 # Reset the global data list
18376 $self->scriptObj->set_readDataList($self->scriptObj->globalDataList);
18377  
18378 # Implementation complete
18379 return 1;
18380 }
18381 }
18382  
18383 { package Language::Axbasic::Statement::return;
18384  
18385 use strict;
18386 use warnings;
18387 # use diagnostics;
18388  
18389 use Glib qw(TRUE FALSE);
18390  
18391 @Language::Axbasic::Statement::return::ISA = qw(
18392 Language::Axbasic
18393 Language::Axbasic::Statement
18394 );
18395  
18396 # RETURN expression
18397 # RETURN
18398  
18399 ##################
18400 # Methods
18401  
18402 sub parse {
18403  
18404 # Called by LA::Line->parse directly after a call to LA::Statement->new
18405 #
18406 # Expected arguments
18407 # (none besides $self)
18408 #
18409 # Return values
18410 # 'undef' on improper arguments or if there is an error
18411 # 1 otherwise
18412  
18413 my ($self, $check) = @_;
18414  
18415 # Local variables
18416 my $expression;
18417  
18418 # Check for improper arguments
18419 if (defined $check) {
18420  
18421 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18422 }
18423  
18424 # No line numbers
18425 if ($self->scriptObj->executionMode eq 'no_line_num') {
18426  
18427 # Check that we're inside a subroutine declaration
18428 if (! $self->scriptObj->currentParseSub) {
18429  
18430 return $self->scriptObj->setError(
18431 'RETURN_statement_used_outside_subroutine',
18432 $self->_objClass . '->parse',
18433 );
18434 }
18435  
18436 # The rest of the statement is an expression to return
18437 $expression = Language::Axbasic::Expression::Arithmetic->new(
18438 $self->scriptObj,
18439 $self->tokenGroupObj,
18440 );
18441  
18442 if (! defined $expression) {
18443  
18444 return $self->scriptObj->setError(
18445 'missing_or_illegal_expression',
18446 $self->_objClass . '->parse',
18447 );
18448 }
18449  
18450 # Check that nothing follows the expression
18451 if (! $self->tokenGroupObj->testStatementEnd()) {
18452  
18453 return $self->scriptObj->setError(
18454 'unexpected_keywords,_operators_or_expressions',
18455 $self->_objClass . '->parse',
18456 );
18457 }
18458  
18459 # Store the GOSUB expression, so $self->implement can retrieve it
18460 $self->ivAdd('parseDataHash', 'expression', $expression);
18461  
18462 # Line numbers
18463 } else {
18464  
18465 # We only need to check that the 'return' keyword isn't followed by anything
18466 if (! $self->tokenGroupObj->testStatementEnd()) {
18467  
18468 return $self->scriptObj->setError(
18469 'unexpected_keywords,_operators_or_expressions',
18470 $self->_objClass . '->parse',
18471 );
18472 }
18473 }
18474  
18475 # Parsing complete
18476 return 1;
18477 }
18478  
18479 sub implement {
18480  
18481 # Called by LA::Line->implement directly after a call to $self->parse
18482 #
18483 # Expected arguments
18484 # (none besides $self)
18485 #
18486 # Return values
18487 # 'undef' on improper arguments
18488 # 1 otherwise
18489  
18490 my ($self, $check) = @_;
18491  
18492 # Local variables
18493 my ($subObj, $statementObj, $callStatement, $expression, $lineNumber);
18494  
18495 # Check for improper arguments
18496 if (defined $check) {
18497  
18498 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18499 }
18500  
18501 # No line numbers
18502 if ($self->scriptObj->executionMode eq 'no_line_num') {
18503  
18504 $subObj = $self->scriptObj->popSubStack();
18505 if (! defined $subObj) {
18506  
18507 return $self->scriptObj->setDebug(
18508 'Sub/func stack seems to be empty',
18509 $self->_objClass . '->implement',
18510 );
18511 }
18512  
18513 # Execution resumes at the first statement after the one that called the subroutine
18514 $callStatement = $subObj->callStatement;
18515  
18516 # The next statement to execute is the statement after that
18517 if (defined $callStatement->nextStatement) {
18518  
18519 # LA::Script->nextStatement is currently set to this statement; continue execution
18520 # as if this were the GOSUB statement
18521 $self->scriptObj->set_nextStatement($statementObj);
18522  
18523 } else {
18524  
18525 $self->scriptObj->set_nextStatement(undef);
18526 $self->scriptObj->set_nextLine($callStatement->lineObj->procLineNum + 1);
18527 }
18528  
18529 # If a return variable was specified (because the subroutine was called in a statement
18530 # like 'LET a$ = CALL mysub (args)' ), set its value
18531 if (defined $subObj->returnVar) {
18532  
18533 $expression = $self->ivShow('parseDataHash', 'expression');
18534 $subObj->returnVar->set($expression->evaluate());
18535 }
18536  
18537 # Line numbers
18538 } else {
18539  
18540 # Get the LA::Statement::gosub statement from the script's subroutine/function stack
18541 $statementObj = $self->scriptObj->pop_gosubStackList();
18542 if (! defined $statementObj) {
18543  
18544 return $self->scriptObj->setError(
18545 'RETURN_statement_without_matching_GOSUB',
18546 $self->_objClass . '->implement',
18547 );
18548 }
18549  
18550 # The next statement (or line) to be executed is the one after the gosub statement
18551 if (defined $statementObj->nextStatement) {
18552  
18553 $self->scriptObj->set_nextStatement($statementObj);
18554  
18555 } else {
18556  
18557 $self->scriptObj->set_nextStatement(undef);
18558 $self->scriptObj->set_nextLine($statementObj->lineObj->procLineNum + 1);
18559 }
18560 }
18561  
18562 # Implementation complete
18563 return 1;
18564 }
18565 }
18566  
18567 { package Language::Axbasic::Statement::revpath;
18568  
18569 use strict;
18570 use warnings;
18571 # use diagnostics;
18572  
18573 use Glib qw(TRUE FALSE);
18574  
18575 @Language::Axbasic::Statement::revpath::ISA = qw(
18576 Language::Axbasic
18577 Language::Axbasic::Statement
18578 );
18579  
18580 # REVPATH variable-name
18581  
18582 ##################
18583 # Methods
18584  
18585 sub parse {
18586  
18587 # Called by LA::Line->parse directly after a call to LA::Statement->new
18588 #
18589 # Expected arguments
18590 # (none besides $self)
18591 #
18592 # Return values
18593 # 'undef' on improper arguments or if there is an error
18594 # 1 otherwise
18595  
18596 my ($self, $check) = @_;
18597  
18598 # Local variables
18599 my $lvalue;
18600  
18601 # Check for improper arguments
18602 if (defined $check) {
18603  
18604 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18605 }
18606  
18607 # (Copied from the SORT statement)
18608 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
18609 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
18610 # that created by
18611 # DIM path$ (10)
18612 # ...by a variable name that looks like a scalar, i.e.
18613 # REVPATH path$
18614 $self->scriptObj->set_declareMode('simple');
18615  
18616 # Get the variable name
18617 $lvalue = Language::Axbasic::Expression::Lvalue->new(
18618 $self->scriptObj,
18619 $self->tokenGroupObj,
18620 );
18621  
18622 if (! defined $lvalue) {
18623  
18624 return $self->scriptObj->setError(
18625 'missing_or_illegal_variable',
18626 $self->_objClass . '->parse',
18627 );
18628 }
18629  
18630 # Reset the temporary IV
18631 $self->scriptObj->set_declareMode('default');
18632  
18633 if (! $self->tokenGroupObj->testStatementEnd()) {
18634  
18635 return $self->scriptObj->setError(
18636 'unexpected_keywords,_operators_or_expressions',
18637 $self->_objClass . '->parse',
18638 );
18639 }
18640  
18641 # Store the variable for ->implement to use
18642 $self->ivAdd('parseDataHash', 'lvalue', $lvalue);
18643  
18644 # Parsing complete
18645 return 1;
18646 }
18647  
18648 sub implement {
18649  
18650 # Called by LA::Line->implement directly after a call to $self->parse
18651 #
18652 # Expected arguments
18653 # (none besides $self)
18654 #
18655 # Return values
18656 # 'undef' on improper arguments or if there is an error
18657 # 1 otherwise
18658  
18659 my ($self, $check) = @_;
18660  
18661 # Local variables
18662 my (
18663 $lvalue, $varObj, $count,
18664 @cellList, @valueList, @reversedList,
18665 );
18666  
18667 # Check for improper arguments
18668 if (defined $check) {
18669  
18670 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18671 }
18672  
18673 # Retrieve the array variable whose contents is to be reversed
18674 $lvalue = $self->ivShow('parseDataHash', 'lvalue');
18675 $varObj = $lvalue->varObj;
18676  
18677 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be reversed. Multi-dimensional arrays
18678 # (e.g. DIM var (5, 5, 2) ) can't be reversed
18679 if ($varObj->dimCount > 1) {
18680  
18681 return $self->scriptObj->setError(
18682 'REVPATH_statement_cannot_operate_on_multi-dimensional_array',
18683 $self->_objClass . '->implement',
18684 );
18685 }
18686  
18687 # Import the values stored in the array, reverse them, and store them back in the array
18688 @cellList = $varObj->cellList;
18689  
18690 # Take account of the first item in ->cellList, which is the lower bound
18691 shift @cellList;
18692  
18693 if (@cellList) {
18694  
18695 # Get the values stored in the variables
18696 foreach my $var (@cellList) {
18697  
18698 push (@valueList, $var->value);
18699 }
18700  
18701 # The first arg, 0, instructs the function to not abbreviate anything and, for secondary
18702 # directions that have more than one possible opposite direction, to use the first one
18703 @reversedList = $self->scriptObj->session->worldModelObj->reversePath(
18704 $self->scriptObj->session,
18705 'no_abbrev',
18706 @valueList,
18707 );
18708  
18709 # Use the existing variables stored in the array, and simply change their values to the
18710 # reversed list of directions
18711 $count = -1;
18712 foreach my $var (@cellList) {
18713  
18714 $count++;
18715 $var->set($reversedList[$count]);
18716 }
18717 }
18718  
18719 # Implementation complete
18720 return 1;
18721 }
18722 }
18723  
18724 { package Language::Axbasic::Statement::select;
18725  
18726 use strict;
18727 use warnings;
18728 # use diagnostics;
18729  
18730 use Glib qw(TRUE FALSE);
18731  
18732 @Language::Axbasic::Statement::select::ISA = qw(
18733 Language::Axbasic
18734 Language::Axbasic::Statement
18735 );
18736  
18737 # SELECT CASE variable-name
18738  
18739 ##################
18740 # Methods
18741  
18742 sub parse {
18743  
18744 # Called by LA::Line->parse directly after a call to LA::Statement->new
18745 #
18746 # Expected arguments
18747 # (none besides $self)
18748 #
18749 # Return values
18750 # 'undef' on improper arguments or if there is an error
18751 # 1 otherwise
18752  
18753 my ($self, $check) = @_;
18754  
18755 # Local variables
18756 my ($token, $expression, $subObj);
18757  
18758 # Check for improper arguments
18759 if (defined $check) {
18760  
18761 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18762 }
18763  
18764 # The 'select' keyword is not available in primitive numbering mode
18765 if ($self->scriptObj->executionMode ne 'no_line_num') {
18766  
18767 return $self->scriptObj->setError(
18768 'statement_not_available_with_line_numbers',
18769 $self->_objClass . '->parse',
18770 );
18771 }
18772  
18773 # The next token is always the keyword CASE
18774 $token = $self->tokenGroupObj->shiftMatchingToken('case');
18775 if (! defined $token) {
18776  
18777 return $self->scriptObj->setError(
18778 'syntax error',
18779 $self->_objClass . '->parse',
18780 );
18781 }
18782  
18783 # Read the variable name
18784 $expression = Language::Axbasic::Expression::Lvalue->new(
18785 $self->scriptObj,
18786 $self->tokenGroupObj,
18787 );
18788  
18789 if (! defined $expression) {
18790  
18791 return $self->scriptObj->setError(
18792 'missing_or_illegal_variable',
18793 $self->_objClass . '->parse',
18794 );
18795 }
18796  
18797 # Check there's nothing else in the statement after the variable
18798 if (! $self->tokenGroupObj->testStatementEnd()) {
18799  
18800 return $self->scriptObj->setError(
18801 'unexpected_keywords,_operators_or_expressions',
18802 $self->_objClass . '->parse',
18803 );
18804 }
18805  
18806 # Add this SELECT statement to the SELECT code block stack for the current subroutine
18807 $subObj = $self->scriptObj->returnCurrentSub();
18808 $subObj->push_selectStackList($self);
18809  
18810 # Store the iterator
18811 $self->ivAdd('parseDataHash', 'expression', $expression);
18812 # We don't know what the corresponding END SELECT (and, optionally, the CASE ELSE)
18813 # statements are, yet
18814 $self->ivAdd('parseDataHash', 'case_else_statement', undef);
18815 $self->ivAdd('parseDataHash', 'end_select_statement', undef);
18816  
18817 # Parsing complete
18818 return 1;
18819 }
18820  
18821 sub implement {
18822  
18823 # Called by LA::Line->implement directly after a call to $self->parse
18824 #
18825 # Expected arguments
18826 # (none besides $self)
18827 #
18828 # Return values
18829 # 'undef' on improper arguments or if there is an error
18830 # 1 otherwise
18831  
18832 my ($self, $check) = @_;
18833  
18834 # Local variables
18835 my (
18836 $expression, $value, $endStatement, $matchStatement, $caseElseStatement,
18837 $subObj,
18838 @caseStatementList,
18839 );
18840  
18841 # Check for improper arguments
18842 if (defined $check) {
18843  
18844 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
18845 }
18846  
18847 # Retrieve the variable to test and the corresponding CASE and END SELECT statements
18848 $expression = $self->ivShow('parseDataHash', 'expression');
18849 $endStatement = $self->ivShow('parseDataHash', 'end_select_statement');
18850 @caseStatementList = $self->parseDataList;
18851  
18852 # Get the value of the variable
18853 $value = $expression->evaluate();
18854  
18855 # Each CASE statement contains, in its ->parseDataList, a list of constants.
18856 # Test each CASE statement's constant list. The CASE statement which contains the constant
18857 # matching the variable's value is the one to execute next
18858 OUTER: foreach my $caseStatement (@caseStatementList) {
18859  
18860 INNER: foreach my $constant ($caseStatement->parseDataList) {
18861  
18862 if ($value eq $constant) {
18863  
18864 $matchStatement = $caseStatement;
18865 last OUTER;
18866 }
18867 }
18868 }
18869  
18870 if (! $matchStatement) {
18871  
18872 # Use the CASE ELSE statement, if it was found during the ->parse stage
18873 $caseElseStatement = $self->ivShow('parseDataHash', 'case_else_statement');
18874 if (defined $caseElseStatement) {
18875  
18876 # The next statement to execute is the one after CASE ELSE
18877 if (defined $caseElseStatement->nextStatement) {
18878  
18879 # LA::Script->nextStatement is currently set to this statement; continue
18880 # execution as if this were the SELECT statement
18881 $self->scriptObj->set_nextStatement($caseElseStatement);
18882  
18883 } else {
18884  
18885 $self->scriptObj->set_nextStatement(undef);
18886 $self->scriptObj->set_nextLine($caseElseStatement->lineObj->procLineNum + 1);
18887 }
18888  
18889 } else {
18890  
18891 return $self->scriptObj->setError(
18892 'no_CASE_selected_and_no_CASE_ELSE',
18893 $self->_objClass . '->implement',
18894 );
18895 }
18896  
18897 } else {
18898  
18899 # The next statement to execute is the one after $matchStatement
18900 if (defined $matchStatement->nextStatement) {
18901  
18902 $self->scriptObj->ivPoke('nextStatement', $matchStatement);
18903  
18904 } else {
18905  
18906 $self->scriptObj->set_nextStatement(undef);
18907 $self->scriptObj->set_nextLine($matchStatement->lineObj->procLineNum + 1);
18908 }
18909 }
18910  
18911 # Add this SELECT CASE code block to the main code block stack, since we're going to execute
18912 # it now. The corresponding CASE/END SELECT statement will remove it.
18913 # NB The main ->blockStackList is used during ->implement for all kinds of code blocks;
18914 # ->selectStackList is used during ->parse for SELECT CASE..CASE..END SELECT blocks
18915 # only
18916 $subObj = $self->scriptObj->returnCurrentSub();
18917 $subObj->push_blockStackList($self);
18918  
18919 # Implementation complete
18920 return 1;
18921 }
18922 }
18923  
18924 { package Language::Axbasic::Statement::send;
18925  
18926 use strict;
18927 use warnings;
18928 # use diagnostics;
18929  
18930 use Glib qw(TRUE FALSE);
18931  
18932 @Language::Axbasic::Statement::send::ISA = qw(
18933 Language::Axbasic
18934 Language::Axbasic::Statement
18935 );
18936  
18937 # SEND expression [ , expression [ , expression ... ] ]
18938  
18939 ##################
18940 # Methods
18941  
18942 sub parse {
18943  
18944 # Called by LA::Line->parse directly after a call to LA::Statement->new
18945 #
18946 # Expected arguments
18947 # (none besides $self)
18948 #
18949 # Return values
18950 # 'undef' on improper arguments or if there is an error
18951 # 1 otherwise
18952  
18953 my ($self, $check) = @_;
18954  
18955 # Local variables
18956 my (
18957 $cmdExp, $exitFlag,
18958 @otherExpList,
18959 );
18960  
18961 # Check for improper arguments
18962 if (defined $check) {
18963  
18964 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
18965 }
18966  
18967 # Get the command expression
18968 $cmdExp = Language::Axbasic::Expression::Arithmetic->new(
18969 $self->scriptObj,
18970 $self->tokenGroupObj,
18971 );
18972  
18973 if (! defined $cmdExp) {
18974  
18975 return $self->scriptObj->setError(
18976 'missing_or_illegal_expression',
18977 $self->_objClass . '->parse',
18978 );
18979 }
18980  
18981 # Get the optional expressions
18982 do {
18983 my ($token, $otherExp);
18984  
18985 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
18986  
18987 $token = $self->tokenGroupObj->lookAhead();
18988 if (defined $token) {
18989  
18990 $otherExp = Language::Axbasic::Expression::Arithmetic->new(
18991 $self->scriptObj,
18992 $self->tokenGroupObj,
18993 );
18994  
18995 if (! defined $otherExp) {
18996  
18997 return $self->scriptObj->setError(
18998 'missing_or_illegal_expression',
18999 $self->_objClass . '->parse',
19000 );
19001  
19002 } else {
19003  
19004 push (@otherExpList, $otherExp);
19005 }
19006 }
19007  
19008 } else {
19009  
19010 $exitFlag = TRUE;
19011 }
19012  
19013 } until ($exitFlag);
19014  
19015 # Check that nothing follows the expressions
19016 if (! $self->tokenGroupObj->testStatementEnd()) {
19017  
19018 return $self->scriptObj->setError(
19019 'unexpected_keywords,_operators_or_expressions',
19020 $self->_objClass . '->parse',
19021 );
19022 }
19023  
19024 # Store the expressions, so $self->implement can retrieve them
19025 $self->ivAdd('parseDataHash', 'cmd_exp', $cmdExp);
19026 $self->ivPoke('parseDataList', @otherExpList);
19027  
19028 # Parsing complete
19029 return 1;
19030 }
19031  
19032 sub implement {
19033  
19034 # Called by LA::Line->implement directly after a call to $self->parse
19035 #
19036 # Expected arguments
19037 # (none besides $self)
19038 #
19039 # Return values
19040 # 'undef' on improper arguments or if there is an error
19041 # 1 otherwise
19042  
19043 my ($self, $check) = @_;
19044  
19045 # Local variables
19046 my (
19047 $cmdExp, $cmd, $newCmd,
19048 @otherExpList, @otherList,
19049 );
19050  
19051 # Check for improper arguments
19052 if (defined $check) {
19053  
19054 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19055 }
19056  
19057 # Retrieve the arguments stored by $self->parse
19058 $cmdExp = $self->ivShow('parseDataHash', 'cmd_exp');
19059 @otherExpList = $self->parseDataList;
19060  
19061 # Evaluate each expression
19062 $cmd = $cmdExp->evaluate();
19063 foreach my $exp (@otherExpList) {
19064  
19065 push (@otherList, $exp->evaluate());
19066 }
19067  
19068 # Interpolate the command using the (optional) arguments in @otherExpList
19069 $newCmd = $self->scriptObj->session->prepareCmd($cmd, @otherList);
19070 if (! $newCmd) {
19071  
19072 # The command couldn't be interpolated, so just send $cmd
19073 $newCmd = $cmd;
19074 }
19075  
19076 $self->scriptObj->session->worldCmd($newCmd);
19077  
19078 # Implementation complete
19079 return 1;
19080 }
19081 }
19082  
19083 { package Language::Axbasic::Statement::setalias;
19084  
19085 use strict;
19086 use warnings;
19087 # use diagnostics;
19088  
19089 use Glib qw(TRUE FALSE);
19090  
19091 @Language::Axbasic::Statement::setalias::ISA = qw(
19092 Language::Axbasic
19093 Language::Axbasic::Statement
19094 );
19095  
19096 # SETALIAS expression [ , expression ]
19097  
19098 ##################
19099 # Methods
19100  
19101 sub parse {
19102  
19103 # Called by LA::Line->parse directly after a call to LA::Statement->new
19104 # when the first token in the statement is the keyword 'setalias'
19105 #
19106 # Expected arguments
19107 # (none besides $self)
19108 #
19109 # Return values
19110 # 'undef' on improper arguments or if there is an error
19111 # 1 otherwise
19112  
19113 my ($self, $check) = @_;
19114  
19115 # Check for improper arguments
19116 if (defined $check) {
19117  
19118 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19119 }
19120  
19121 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19122 # ready for $self->implement to access
19123 if (! $self->parseSetInterface()) {
19124  
19125 # ($self->scriptObj->setError has already been called)
19126 return undef;
19127 }
19128  
19129 # Parsing complete
19130 return 1;
19131 }
19132  
19133 sub implement {
19134  
19135 # Called by LA::Line->implement directly after a call to $self->parse
19136 #
19137 # Expected arguments
19138 # (none besides $self)
19139 #
19140 # Return values
19141 # 'undef' on improper arguments or if there is an error
19142 # 1 otherwise
19143  
19144 my ($self, $check) = @_;
19145  
19146 # Local variables
19147 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19148  
19149 # Check for improper arguments
19150 if (defined $check) {
19151  
19152 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19153 }
19154  
19155 # Retrieve the arguments stored by $self->parse
19156 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19157 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19158  
19159 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19160 # new script to call, ignore this statement altogether
19161 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19162  
19163 # Implementation complete. Execution resumes from the next statement
19164 return 1;
19165 }
19166  
19167 # Otherwise, evaluate the expressions
19168 $stimulus = $stimulusExp->evaluate();
19169 if (defined $newScriptExp) {
19170  
19171 $newScript = $newScriptExp->evaluate();
19172 }
19173  
19174 # Create the (dependent) alias
19175 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19176 'alias',
19177 $stimulus,
19178 $self->scriptObj->parentTask,
19179 'aliasNotifySeen',
19180 );
19181  
19182 if (defined $interfaceObj) {
19183  
19184 # Store the name of the new script to execute in the interface object
19185 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19186  
19187 # Add this alias to the list of interfaces created during the execution of the Axbasic
19188 # script
19189 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19190 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19191  
19192 } else {
19193  
19194 # Store the fact that creation of the interface failed
19195 $self->scriptObj->set_depInterfaceName(undef);
19196 }
19197  
19198 # Implementation complete
19199 return 1;
19200 }
19201 }
19202  
19203 { package Language::Axbasic::Statement::setgauge;
19204  
19205 use strict;
19206 use warnings;
19207 # use diagnostics;
19208  
19209 use Glib qw(TRUE FALSE);
19210  
19211 @Language::Axbasic::Statement::setgauge::ISA = qw(
19212 Language::Axbasic
19213 Language::Axbasic::Statement
19214 );
19215  
19216 # SETGAUGE expression , expression , expression
19217 # WINSETGAUGE expression , expression , expression
19218  
19219 ##################
19220 # Methods
19221  
19222 sub parse {
19223  
19224 # Called by LA::Line->parse directly after a call to LA::Statement->new
19225 #
19226 # Expected arguments
19227 # (none besides $self)
19228 #
19229 # Return values
19230 # 'undef' on improper arguments or if there is an error
19231 # 1 otherwise
19232  
19233 my ($self, $check) = @_;
19234  
19235 # Local variables
19236 my ($numberExp, $valExp, $maxValExp);
19237  
19238 # Check for improper arguments
19239 if (defined $check) {
19240  
19241 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19242 }
19243  
19244 # Convert the arguments into expressions
19245 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
19246 $self->scriptObj,
19247 $self->tokenGroupObj,
19248 );
19249  
19250 if (! defined $numberExp) {
19251  
19252 return $self->scriptObj->setError(
19253 'missing_or_illegal_expression',
19254 $self->_objClass . '->parse',
19255 );
19256 }
19257  
19258 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19259  
19260 return $self->scriptObj->setError(
19261 'syntax_error',
19262 $self->_objClass . '->parse',
19263 );
19264 }
19265  
19266 $valExp = Language::Axbasic::Expression::Arithmetic->new(
19267 $self->scriptObj,
19268 $self->tokenGroupObj,
19269 );
19270  
19271 if (! defined $valExp) {
19272  
19273 return $self->scriptObj->setError(
19274 'missing_or_illegal_expression',
19275 $self->_objClass . '->parse',
19276 );
19277 }
19278  
19279 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19280  
19281 return $self->scriptObj->setError(
19282 'syntax_error',
19283 $self->_objClass . '->parse',
19284 );
19285 }
19286  
19287 $maxValExp = Language::Axbasic::Expression::Arithmetic->new(
19288 $self->scriptObj,
19289 $self->tokenGroupObj,
19290 );
19291  
19292 if (! defined $maxValExp) {
19293  
19294 return $self->scriptObj->setError(
19295 'missing_or_illegal_expression',
19296 $self->_objClass . '->parse',
19297 );
19298 }
19299  
19300 # Check that nothing follows the expressions
19301 if (! $self->tokenGroupObj->testStatementEnd()) {
19302  
19303 return $self->scriptObj->setError(
19304 'unexpected_keywords,_operators_or_expressions',
19305 $self->_objClass . '->parse',
19306 );
19307 }
19308  
19309 # Store the expressions, so $self->implement can retrieve them
19310 $self->ivAdd('parseDataHash', 'number', $numberExp);
19311 $self->ivAdd('parseDataHash', 'val', $valExp);
19312 $self->ivAdd('parseDataHash', 'max_val', $maxValExp);
19313  
19314 # Parsing complete
19315 return 1;
19316 }
19317  
19318 sub implement {
19319  
19320 # Called by LA::Line->implement directly after a call to $self->parse
19321 #
19322 # Expected arguments
19323 # (none besides $self)
19324 #
19325 # Return values
19326 # 'undef' on improper arguments or if there is an error
19327 # 1 otherwise
19328  
19329 my ($self, $check) = @_;
19330  
19331 # Local variables
19332 my ($numberExp, $valExp, $maxValExp, $number, $val, $maxVal);
19333  
19334 # Check for improper arguments
19335 if (defined $check) {
19336  
19337 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19338 }
19339  
19340 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
19341 if (! $self->scriptObj->parentTask) {
19342  
19343 # Implementation complete. Execution resumes from the next statement
19344 return 1;
19345 }
19346  
19347 # Retrieve the arguments stored by $self->parse
19348 $numberExp = $self->ivShow('parseDataHash', 'number');
19349 $valExp = $self->ivShow('parseDataHash', 'val');
19350 $maxValExp = $self->ivShow('parseDataHash', 'max_val');
19351  
19352 # Evaluate each expression
19353 $number = $numberExp->evaluate();
19354 $val = $valExp->evaluate();
19355 $maxVal = $maxValExp->evaluate();
19356  
19357 # $num must be an integer, >= 0 (but it doesn't need to be a gauge number which has
19358 # actually been created with an ADDGAUGE or ADDCONGAUGE statement)
19359 if ($number =~ m/\D/ || $number < 0) {
19360  
19361 return $self->scriptObj->setError(
19362 'invalid_gauge_number',
19363 $self->_objClass . '->implement',
19364 );
19365 }
19366  
19367 # $val and $maxVal must both be decimal numbers, otherwise we'll have to change them to
19368 # 'undef'
19369 if (! ($val =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19370  
19371 $val = undef;
19372 }
19373  
19374 if (! ($maxVal =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19375  
19376 $maxVal = undef;
19377 }
19378  
19379 # Tell the Script task to set the gauge's value
19380 if ($self->keyword eq 'setgauge') {
19381 $self->scriptObj->parentTask->setMainWinGauge($number, $val, $maxVal);
19382 } elsif ($self->keyword eq 'winsetgauge') {
19383 $self->scriptObj->parentTask->setTaskWinGauge($number, $val, $maxVal);
19384 }
19385  
19386 # Implementation complete
19387 return 1;
19388 }
19389 }
19390  
19391 { package Language::Axbasic::Statement::sethook;
19392  
19393 use strict;
19394 use warnings;
19395 # use diagnostics;
19396  
19397 use Glib qw(TRUE FALSE);
19398  
19399 @Language::Axbasic::Statement::sethook::ISA = qw(
19400 Language::Axbasic
19401 Language::Axbasic::Statement
19402 );
19403  
19404 # SETHOOK expression [ , expression ]
19405  
19406 ##################
19407 # Methods
19408  
19409 sub parse {
19410  
19411 # Called by LA::Line->parse directly after a call to LA::Statement->new
19412 # when the first token in the statement is the keyword 'sethook'
19413 #
19414 # Expected arguments
19415 # (none besides $self)
19416 #
19417 # Return values
19418 # 'undef' on improper arguments or if there is an error
19419 # 1 otherwise
19420  
19421 my ($self, $check) = @_;
19422  
19423 # Check for improper arguments
19424 if (defined $check) {
19425  
19426 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19427 }
19428  
19429 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19430 # ready for $self->implement to access
19431 if (! $self->parseSetInterface()) {
19432  
19433 # ($self->scriptObj->setError has already been called)
19434 return undef;
19435 }
19436  
19437 # Parsing complete
19438 return 1;
19439 }
19440  
19441 sub implement {
19442  
19443 # Called by LA::Line->implement directly after a call to $self->parse
19444 #
19445 # Expected arguments
19446 # (none besides $self)
19447 #
19448 # Return values
19449 # 'undef' on improper arguments or if there is an error
19450 # 1 otherwise
19451  
19452 my ($self, $check) = @_;
19453  
19454 # Local variables
19455 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19456  
19457 # Check for improper arguments
19458 if (defined $check) {
19459  
19460 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19461 }
19462  
19463 # Retrieve the arguments stored by $self->parse
19464 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19465 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19466  
19467 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19468 # new script to call, ignore this statement altogether
19469 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19470  
19471 # Implementation complete. Execution resumes from the next statement
19472 return 1;
19473 }
19474  
19475 # Otherwise, evaluate the expressions
19476 $stimulus = $stimulusExp->evaluate();
19477 if (defined $newScriptExp) {
19478  
19479 $newScript = $newScriptExp->evaluate();
19480 }
19481  
19482 # Create the (dependent) hook
19483 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19484 'hook',
19485 $stimulus,
19486 $self->scriptObj->parentTask,
19487 'hookNotifySeen',
19488 );
19489  
19490 if (defined $interfaceObj) {
19491  
19492 # Store the name of the new script to execute in the interface object
19493 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19494  
19495 # Add this hook to the list of interfaces created during the execution of the Axbasic
19496 # script
19497 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19498 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19499  
19500 } else {
19501  
19502 # Store the fact that creation of the interface failed
19503 $self->scriptObj->set_depInterfaceName(undef);
19504 }
19505  
19506 # Implementation complete
19507 return 1;
19508 }
19509 }
19510  
19511 { package Language::Axbasic::Statement::setmacro;
19512  
19513 use strict;
19514 use warnings;
19515 # use diagnostics;
19516  
19517 use Glib qw(TRUE FALSE);
19518  
19519 @Language::Axbasic::Statement::setmacro::ISA = qw(
19520 Language::Axbasic
19521 Language::Axbasic::Statement
19522 );
19523  
19524 # SETMACRO expression [ , expression ]
19525  
19526 ##################
19527 # Methods
19528  
19529 sub parse {
19530  
19531 # Called by LA::Line->parse directly after a call to LA::Statement->new
19532 # when the first token in the statement is the keyword 'setmacro'
19533 #
19534 # Expected arguments
19535 # (none besides $self)
19536 #
19537 # Return values
19538 # 'undef' on improper arguments or if there is an error
19539 # 1 otherwise
19540  
19541 my ($self, $check) = @_;
19542  
19543 # Check for improper arguments
19544 if (defined $check) {
19545  
19546 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19547 }
19548  
19549 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19550 # ready for $self->implement to access
19551 if (! $self->parseSetInterface()) {
19552  
19553 # ($self->scriptObj->setError has already been called)
19554 return undef;
19555 }
19556  
19557 # Parsing complete
19558 return 1;
19559 }
19560  
19561 sub implement {
19562  
19563 # Called by LA::Line->implement directly after a call to $self->parse
19564 #
19565 # Expected arguments
19566 # (none besides $self)
19567 #
19568 # Return values
19569 # 'undef' on improper arguments or if there is an error
19570 # 1 otherwise
19571  
19572 my ($self, $check) = @_;
19573  
19574 # Local variables
19575 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19576  
19577 # Check for improper arguments
19578 if (defined $check) {
19579  
19580 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19581 }
19582  
19583 # Retrieve the arguments stored by $self->parse
19584 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19585 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19586  
19587 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19588 # new script to call, ignore this statement altogether
19589 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19590  
19591 # Implementation complete. Execution resumes from the next statement
19592 return 1;
19593 }
19594  
19595 # Otherwise, evaluate the expressions
19596 $stimulus = $stimulusExp->evaluate();
19597 if (defined $newScriptExp) {
19598  
19599 $newScript = $newScriptExp->evaluate();
19600 }
19601  
19602 # Create the (dependent) macro
19603 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19604 'macro',
19605 $stimulus,
19606 $self->scriptObj->parentTask,
19607 'macroNotifySeen',
19608 );
19609  
19610 if (defined $interfaceObj) {
19611  
19612 # Store the name of the new script to execute in the interface object
19613 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19614  
19615 # Add this macro to the list of interfaces created during the execution of the Axbasic
19616 # script
19617 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19618 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19619  
19620 } else {
19621  
19622 # Store the fact that creation of the interface failed
19623 $self->scriptObj->set_depInterfaceName(undef);
19624 }
19625  
19626 # Implementation complete
19627 return 1;
19628 }
19629 }
19630  
19631 { package Language::Axbasic::Statement::setstatus;
19632  
19633 use strict;
19634 use warnings;
19635 # use diagnostics;
19636  
19637 use Glib qw(TRUE FALSE);
19638  
19639 @Language::Axbasic::Statement::setstatus::ISA = qw(
19640 Language::Axbasic
19641 Language::Axbasic::Statement
19642 );
19643  
19644 # SETSTATUS expression , expression , expression
19645 # WINSETSTATUS expression , expression , expression
19646  
19647 ##################
19648 # Methods
19649  
19650 sub parse {
19651  
19652 # Called by LA::Line->parse directly after a call to LA::Statement->new
19653 #
19654 # Expected arguments
19655 # (none besides $self)
19656 #
19657 # Return values
19658 # 'undef' on improper arguments or if there is an error
19659 # 1 otherwise
19660  
19661 my ($self, $check) = @_;
19662  
19663 # Local variables
19664 my ($numberExp, $valExp, $maxValExp);
19665  
19666 # Check for improper arguments
19667 if (defined $check) {
19668  
19669 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19670 }
19671  
19672 # Convert the arguments into expressions
19673 $numberExp = Language::Axbasic::Expression::Arithmetic->new(
19674 $self->scriptObj,
19675 $self->tokenGroupObj,
19676 );
19677  
19678 if (! defined $numberExp) {
19679  
19680 return $self->scriptObj->setError(
19681 'missing_or_illegal_expression',
19682 $self->_objClass . '->parse',
19683 );
19684 }
19685  
19686 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19687  
19688 return $self->scriptObj->setError(
19689 'syntax_error',
19690 $self->_objClass . '->parse',
19691 );
19692 }
19693  
19694 $valExp = Language::Axbasic::Expression::Arithmetic->new(
19695 $self->scriptObj,
19696 $self->tokenGroupObj,
19697 );
19698  
19699 if (! defined $valExp) {
19700  
19701 return $self->scriptObj->setError(
19702 'missing_or_illegal_expression',
19703 $self->_objClass . '->parse',
19704 );
19705 }
19706  
19707 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
19708  
19709 return $self->scriptObj->setError(
19710 'syntax_error',
19711 $self->_objClass . '->parse',
19712 );
19713 }
19714  
19715 $maxValExp = Language::Axbasic::Expression::Arithmetic->new(
19716 $self->scriptObj,
19717 $self->tokenGroupObj,
19718 );
19719  
19720 if (! defined $maxValExp) {
19721  
19722 return $self->scriptObj->setError(
19723 'missing_or_illegal_expression',
19724 $self->_objClass . '->parse',
19725 );
19726 }
19727  
19728 # Check that nothing follows the expressions
19729 if (! $self->tokenGroupObj->testStatementEnd()) {
19730  
19731 return $self->scriptObj->setError(
19732 'unexpected_keywords,_operators_or_expressions',
19733 $self->_objClass . '->parse',
19734 );
19735 }
19736  
19737 # Store the expressions, so $self->implement can retrieve them
19738 $self->ivAdd('parseDataHash', 'number', $numberExp);
19739 $self->ivAdd('parseDataHash', 'val', $valExp);
19740 $self->ivAdd('parseDataHash', 'max_val', $maxValExp);
19741  
19742 # Parsing complete
19743 return 1;
19744 }
19745  
19746 sub implement {
19747  
19748 # Called by LA::Line->implement directly after a call to $self->parse
19749 #
19750 # Expected arguments
19751 # (none besides $self)
19752 #
19753 # Return values
19754 # 'undef' on improper arguments or if there is an error
19755 # 1 otherwise
19756  
19757 my ($self, $check) = @_;
19758  
19759 # Local variables
19760 my ($numberExp, $valExp, $maxValExp, $number, $val, $maxVal);
19761  
19762 # Check for improper arguments
19763 if (defined $check) {
19764  
19765 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19766 }
19767  
19768 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
19769 if (! $self->scriptObj->parentTask) {
19770  
19771 # Implementation complete. Execution resumes from the next statement
19772 return 1;
19773 }
19774  
19775 # Retrieve the arguments stored by $self->parse
19776 $numberExp = $self->ivShow('parseDataHash', 'number');
19777 $valExp = $self->ivShow('parseDataHash', 'val');
19778 $maxValExp = $self->ivShow('parseDataHash', 'max_val');
19779  
19780 # Evaluate each expression
19781 $number = $numberExp->evaluate();
19782 $val = $valExp->evaluate();
19783 $maxVal = $maxValExp->evaluate();
19784  
19785 # $num must be an integer, >= 0 (but it doesn't need to be a status bar number which has
19786 # actually been created with an ADDSTATUS or ADDCONSTATUS statement)
19787 if ($number =~ m/\D/ || $number < 0) {
19788  
19789 return $self->scriptObj->setError(
19790 'invalid_status_bar_number',
19791 $self->_objClass . '->implement',
19792 );
19793 }
19794  
19795 # $val and $maxVal must both be decimal numbers, otherwise we'll have to change them to
19796 # 'undef'
19797 if (! ($val =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19798  
19799 $val = undef;
19800 }
19801  
19802 if (! ($maxVal =~ m/^\-?((\d+(\.\d*)?)|(\.\d+))$/)) {
19803  
19804 $maxVal = undef;
19805 }
19806  
19807 # Tell the Script task to set the status bar's text
19808 if ($self->keyword eq 'setstatus') {
19809 $self->scriptObj->parentTask->setMainWinStatusBar($number, $val, $maxVal);
19810 } else {
19811 $self->scriptObj->parentTask->setTaskWinStatusBar($number, $val, $maxVal);
19812 }
19813  
19814 # Implementation complete
19815 return 1;
19816 }
19817 }
19818  
19819 { package Language::Axbasic::Statement::settimer;
19820  
19821 use strict;
19822 use warnings;
19823 # use diagnostics;
19824  
19825 use Glib qw(TRUE FALSE);
19826  
19827 @Language::Axbasic::Statement::settimer::ISA = qw(
19828 Language::Axbasic
19829 Language::Axbasic::Statement
19830 );
19831  
19832 # SETTIMER expression [ , expression ]
19833  
19834 ##################
19835 # Methods
19836  
19837 sub parse {
19838  
19839 # Called by LA::Line->parse directly after a call to LA::Statement->new
19840 # when the first token in the statement is the keyword 'settimer'
19841 #
19842 # Expected arguments
19843 # (none besides $self)
19844 #
19845 # Return values
19846 # 'undef' on improper arguments or if there is an error
19847 # 1 otherwise
19848  
19849 my ($self, $check) = @_;
19850  
19851 # Check for improper arguments
19852 if (defined $check) {
19853  
19854 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19855 }
19856  
19857 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19858 # ready for $self->implement to access
19859 if (! $self->parseSetInterface()) {
19860  
19861 # ($self->scriptObj->setError has already been called)
19862 return undef;
19863 }
19864  
19865 # Parsing complete
19866 return 1;
19867 }
19868  
19869 sub implement {
19870  
19871 # Called by LA::Line->implement directly after a call to $self->parse
19872 #
19873 # Expected arguments
19874 # (none besides $self)
19875 #
19876 # Return values
19877 # 'undef' on improper arguments or if there is an error
19878 # 1 otherwise
19879  
19880 my ($self, $check) = @_;
19881  
19882 # Local variables
19883 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
19884  
19885 # Check for improper arguments
19886 if (defined $check) {
19887  
19888 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
19889 }
19890  
19891 # Retrieve the arguments stored by $self->parse
19892 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
19893 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
19894  
19895 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
19896 # new script to call, ignore this statement altogether
19897 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
19898  
19899 # Implementation complete. Execution resumes from the next statement
19900 return 1;
19901 }
19902  
19903 # Otherwise, evaluate the expressions
19904 $stimulus = $stimulusExp->evaluate();
19905 if (defined $newScriptExp) {
19906  
19907 $newScript = $newScriptExp->evaluate();
19908 }
19909  
19910 # Create the (dependent) timer
19911 $interfaceObj = $self->scriptObj->session->createDependentInterface(
19912 'timer',
19913 $stimulus,
19914 $self->scriptObj->parentTask,
19915 'timerNotifySeen',
19916 );
19917  
19918 if (defined $interfaceObj) {
19919  
19920 # Store the name of the new script to execute in the interface object
19921 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
19922  
19923 # Add this timer to the list of interfaces created during the execution of the Axbasic
19924 # script
19925 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
19926 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
19927  
19928 } else {
19929  
19930 # Store the fact that creation of the interface failed
19931 $self->scriptObj->set_depInterfaceName(undef);
19932 }
19933  
19934 # Implementation complete
19935 return 1;
19936 }
19937 }
19938  
19939 { package Language::Axbasic::Statement::settrig;
19940  
19941 use strict;
19942 use warnings;
19943 # use diagnostics;
19944  
19945 use Glib qw(TRUE FALSE);
19946  
19947 @Language::Axbasic::Statement::settrig::ISA = qw(
19948 Language::Axbasic
19949 Language::Axbasic::Statement
19950 );
19951  
19952 # SETTRIG expression [ , expression ]
19953  
19954 ##################
19955 # Methods
19956  
19957 sub parse {
19958  
19959 # Called by LA::Line->parse directly after a call to LA::Statement->new
19960 # when the first token in the statement is the keyword 'settrig'
19961 #
19962 # Expected arguments
19963 # (none besides $self)
19964 #
19965 # Return values
19966 # 'undef' on improper arguments or if there is an error
19967 # 1 otherwise
19968  
19969 my ($self, $check) = @_;
19970  
19971 # Check for improper arguments
19972 if (defined $check) {
19973  
19974 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
19975 }
19976  
19977 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
19978 # ready for $self->implement to access
19979 if (! $self->parseSetInterface()) {
19980  
19981 # ($self->scriptObj->setError has already been called)
19982 return undef;
19983 }
19984  
19985 # Parsing complete
19986 return 1;
19987 }
19988  
19989 sub implement {
19990  
19991 # Called by LA::Line->implement directly after a call to $self->parse
19992 #
19993 # Expected arguments
19994 # (none besides $self)
19995 #
19996 # Return values
19997 # 'undef' on improper arguments or if there is an error
19998 # 1 otherwise
19999  
20000 my ($self, $check) = @_;
20001  
20002 # Local variables
20003 my ($stimulusExp, $stimulus, $newScriptExp, $newScript, $interfaceObj);
20004  
20005 # Check for improper arguments
20006 if (defined $check) {
20007  
20008 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20009 }
20010  
20011 # Retrieve the arguments stored by $self->parse
20012 $stimulusExp = $self->ivShow('parseDataHash', 'stimulus');
20013 $newScriptExp = $self->ivShow('parseDataHash', 'new_script'); # May be 'undef'
20014  
20015 # If the Axbasic script isn't being run from within an Axmud task and assuming there isn't a
20016 # new script to call, ignore this statement altogether
20017 if ((! $self->scriptObj->parentTask) && (! $newScriptExp)) {
20018  
20019 # Implementation complete. Execution resumes from the next statement
20020 return 1;
20021 }
20022  
20023 # Otherwise, evaluate the expressions
20024 $stimulus = $stimulusExp->evaluate();
20025 if (defined $newScriptExp) {
20026  
20027 $newScript = $newScriptExp->evaluate();
20028 }
20029  
20030 # Create the (dependent) trigger
20031 $interfaceObj = $self->scriptObj->session->createDependentInterface(
20032 'trigger',
20033 $stimulus,
20034 $self->scriptObj->parentTask,
20035 'triggerNotifySeen',
20036 );
20037  
20038 if (defined $interfaceObj) {
20039  
20040 # Store the name of the new script to execute in the interface object
20041 $interfaceObj->ivAdd('propertyHash', 'new_script', $newScript);
20042  
20043 # Add this trigger to the list of interfaces created during the execution of the Axbasic
20044 # script
20045 $self->scriptObj->push_depInterfaceList($interfaceObj->name);
20046 $self->scriptObj->set_depInterfaceName($interfaceObj->name);
20047  
20048 } else {
20049  
20050 # Store the fact that creation of the interface failed
20051 $self->scriptObj->set_depInterfaceName(undef);
20052 }
20053  
20054 # Implementation complete
20055 return 1;
20056 }
20057 }
20058  
20059 { package Language::Axbasic::Statement::shift;
20060  
20061 use strict;
20062 use warnings;
20063 # use diagnostics;
20064  
20065 use Glib qw(TRUE FALSE);
20066  
20067 @Language::Axbasic::Statement::shift::ISA = qw(
20068 Language::Axbasic
20069 Language::Axbasic::Statement
20070 );
20071  
20072 # SHIFT array-name [ , variable-name ]
20073  
20074 ##################
20075 # Methods
20076  
20077 sub parse {
20078  
20079 # Called by LA::Line->parse directly after a call to LA::Statement->new
20080 #
20081 # Expected arguments
20082 # (none besides $self)
20083 #
20084 # Return values
20085 # 'undef' on improper arguments or if there is an error
20086 # 1 otherwise
20087  
20088 my ($self, $check) = @_;
20089  
20090 # Local variables
20091 my ($arrayExp, $scalarExp);
20092  
20093 # Check for improper arguments
20094 if (defined $check) {
20095  
20096 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20097 }
20098  
20099 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20100 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20101 # that created by
20102 # DIM var (10)
20103 # ...by a variable name that looks like a scalar, i.e.
20104 # SORT var
20105 $self->scriptObj->set_declareMode('simple');
20106  
20107 # Get the array variable name
20108 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
20109 $self->scriptObj,
20110 $self->tokenGroupObj,
20111 );
20112  
20113 if (! defined $arrayExp) {
20114  
20115 return $self->scriptObj->setError(
20116 'missing_or_illegal_array_variable',
20117 $self->_objClass . '->parse',
20118 );
20119 }
20120  
20121 # Reset the temporary IV
20122 $self->scriptObj->set_declareMode('default');
20123  
20124 # Extract the optional scalar variable name
20125 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
20126  
20127 $scalarExp = Language::Axbasic::Expression::Lvalue->new(
20128 $self->scriptObj,
20129 $self->tokenGroupObj,
20130 );
20131  
20132 if (! defined $scalarExp) {
20133  
20134 return $self->scriptObj->setError(
20135 'missing_or_illegal_expression',
20136 $self->_objClass . '->parse',
20137 );
20138 }
20139 }
20140  
20141 if (! $self->tokenGroupObj->testStatementEnd()) {
20142  
20143 return $self->scriptObj->setError(
20144 'unexpected_keywords,_operators_or_expressions',
20145 $self->_objClass . '->parse',
20146 );
20147 }
20148  
20149 # Save the expression objects so $self->implement can use them, if it is called
20150 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
20151 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
20152  
20153 # Parsing complete
20154 return 1;
20155 }
20156  
20157 sub implement {
20158  
20159 # Called by LA::Line->implement directly after a call to $self->parse
20160 #
20161 # Expected arguments
20162 # (none besides $self)
20163 #
20164 # Return values
20165 # 'undef' on improper arguments
20166 # 1 otherwise
20167  
20168 my ($self, $check) = @_;
20169  
20170 # Local variables
20171 my ($arrayExp, $scalarExp, $removedVar);
20172  
20173 # Check for improper arguments
20174 if (defined $check) {
20175  
20176 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20177 }
20178  
20179 # Retrieve the variables stored by ->parse
20180 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
20181 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
20182  
20183 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be shifted. Multi-dimensional arrays
20184 # (e.g. DIM var (5, 5, 2) ) can't be shifted
20185 if ($arrayExp->varObj->dimCount > 1) {
20186  
20187 return $self->scriptObj->setError(
20188 'SHIFT_statement_cannot_operate_on_multi-dimensional_array',
20189 $self->_objClass . '->implement',
20190 );
20191 }
20192  
20193 # Cannot use a numeric array with a string scalar, and vice-versa
20194 if (
20195 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp->varObj) =~ m/Numeric/))
20196 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp->varObj) =~ m/String/))
20197 ) {
20198 return $self->scriptObj->setError(
20199 'type_mismatch_error',
20200 $self->_objClass . '->implement',
20201 );
20202 }
20203  
20204 # Shift the stack, and use the shifted value to set the variable. (If the array is empty, we
20205 # get an empty string or zero, as appropriate)
20206 $removedVar = $arrayExp->varObj->doShift();
20207 if ($removedVar) {
20208  
20209 $scalarExp->varObj->set($removedVar->value);
20210 }
20211  
20212 # Implementation complete
20213 return 1;
20214 }
20215 }
20216  
20217 { package Language::Axbasic::Statement::skipiface;
20218  
20219 use strict;
20220 use warnings;
20221 # use diagnostics;
20222  
20223 use Glib qw(TRUE FALSE);
20224  
20225 @Language::Axbasic::Statement::skipiface::ISA = qw(
20226 Language::Axbasic
20227 Language::Axbasic::Statement
20228 );
20229  
20230 # SKIPIFACE
20231  
20232 ##################
20233 # Methods
20234  
20235 sub parse {
20236  
20237 # Called by LA::Line->parse directly after a call to LA::Statement->new
20238 #
20239 # Expected arguments
20240 # (none besides $self)
20241 #
20242 # Return values
20243 # 'undef' on improper arguments or if there is an error
20244 # 1 otherwise
20245  
20246 my ($self, $check) = @_;
20247  
20248 # Local variables
20249 my ($subObj, $whileStatement);
20250  
20251 # Check for improper arguments
20252 if (defined $check) {
20253  
20254 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20255 }
20256  
20257 # SKIPIFACE statements always appear on their own
20258 if (! $self->tokenGroupObj->testStatementEnd()) {
20259  
20260 return $self->scriptObj->setError(
20261 'unexpected_keywords,_operators_or_expressions',
20262 $self->_objClass . '->parse',
20263 );
20264 }
20265  
20266 # Parsing complete
20267 return 1;
20268 }
20269  
20270 sub implement {
20271  
20272 # Called by LA::Line->implement directly after a call to $self->parse
20273 #
20274 # Expected arguments
20275 # (none besides $self)
20276 #
20277 # Return values
20278 # 'undef' on improper arguments or if there is an error
20279 # 1 otherwise
20280  
20281 my ($self, $check) = @_;
20282  
20283 # Local variables
20284 my $count;
20285  
20286 # Check for improper arguments
20287 if (defined $check) {
20288  
20289 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20290 }
20291  
20292 # Get the size of the notification list
20293 $count = $self->scriptObj->ivNumber('notificationList');
20294  
20295 # Do nothing, if the interface notification list is empty or if it contains only one
20296 # notification
20297 if ($count < 2) {
20298  
20299 # Implementation complete
20300 return 1;
20301  
20302 } else {
20303  
20304 if ($self->scriptObj->currentNotification == ($count - 1)) {
20305  
20306 # At the end of the list
20307 $self->scriptObj->set_currentNotification(0);
20308  
20309 } else {
20310  
20311 # Move along one position
20312 $self->scriptObj->inc_currentNotification();
20313 }
20314  
20315 # Implementation complete
20316 return 1;
20317 }
20318 }
20319 }
20320  
20321 { package Language::Axbasic::Statement::sort;
20322  
20323 use strict;
20324 use warnings;
20325 # use diagnostics;
20326  
20327 use Glib qw(TRUE FALSE);
20328  
20329 @Language::Axbasic::Statement::sort::ISA = qw(
20330 Language::Axbasic
20331 Language::Axbasic::Statement
20332 );
20333  
20334 # SORT variable-name
20335  
20336 ##################
20337 # Methods
20338  
20339 sub parse {
20340  
20341 # Called by LA::Line->parse directly after a call to LA::Statement->new
20342 #
20343 # Expected arguments
20344 # (none besides $self)
20345 #
20346 # Return values
20347 # 'undef' on improper arguments or if there is an error
20348 # 1 otherwise
20349  
20350 my ($self, $check) = @_;
20351  
20352 # Local variables
20353 my $expression;
20354  
20355 # Check for improper arguments
20356 if (defined $check) {
20357  
20358 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20359 }
20360  
20361 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20362 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20363 # that created by
20364 # DIM var (10)
20365 # ...by a variable name that looks like a scalar, i.e.
20366 # SORT var
20367 $self->scriptObj->set_declareMode('simple');
20368  
20369 # Get the variable name
20370 $expression = Language::Axbasic::Expression::Lvalue->new(
20371 $self->scriptObj,
20372 $self->tokenGroupObj,
20373 );
20374  
20375 if (! defined $expression) {
20376  
20377 return $self->scriptObj->setError(
20378 'missing_or_illegal_variable',
20379 $self->_objClass . '->parse',
20380 );
20381 }
20382  
20383 # Reset the temporary IV
20384 $self->scriptObj->set_declareMode('default');
20385  
20386 if (! $self->tokenGroupObj->testStatementEnd()) {
20387  
20388 return $self->scriptObj->setError(
20389 'unexpected_keywords,_operators_or_expressions',
20390 $self->_objClass . '->parse',
20391 );
20392 }
20393  
20394 # Store the variable for ->implement to use
20395 $self->ivAdd('parseDataHash', 'expression', $expression);
20396  
20397 # Parsing complete
20398 return 1;
20399 }
20400  
20401 sub implement {
20402  
20403 # Called by LA::Line->implement directly after a call to $self->parse
20404 #
20405 # Expected arguments
20406 # (none besides $self)
20407 #
20408 # Return values
20409 # 'undef' on improper arguments or if there is an error
20410 # 1 otherwise
20411  
20412 my ($self, $check) = @_;
20413  
20414 # Local variables
20415 my (
20416 $expression, $varObj, $lowerBound,
20417 @list, @sortedList,
20418 );
20419  
20420 # Check for improper arguments
20421 if (defined $check) {
20422  
20423 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20424 }
20425  
20426 # Retrieve the array variable to sort
20427 $expression = $self->ivShow('parseDataHash', 'expression');
20428 $varObj = $expression->varObj;
20429  
20430 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20431 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20432 if ($varObj->dimCount > 1) {
20433  
20434 return $self->scriptObj->setError(
20435 'SORT_statement_cannot_operate_on_multi-dimensional_array',
20436 $self->_objClass . '->implement',
20437 );
20438 }
20439  
20440 # Import the values stored in the array, sort them, and store them back in the array
20441 @list = $varObj->cellList;
20442  
20443 # Take account of the first item in ->cellList, which is the lower bound
20444 $lowerBound = shift @list;
20445  
20446 if (ref($varObj) =~ m/Numeric/) {
20447  
20448 # It's a numeric array
20449 @sortedList = sort {$a->value <=> $b->value} (@list);
20450  
20451 } else {
20452  
20453 # It's a string array
20454 @sortedList = sort {$a->value cmp $b->value} (@list);
20455 }
20456  
20457 # Restore the lower bound to its previous place
20458 unshift(@sortedList, $lowerBound);
20459 $varObj->ivPoke('cellList', @sortedList);
20460  
20461 # Implementation complete
20462 return 1;
20463 }
20464 }
20465  
20466 { package Language::Axbasic::Statement::sortcase;
20467  
20468 use strict;
20469 use warnings;
20470 # use diagnostics;
20471  
20472 use Glib qw(TRUE FALSE);
20473  
20474 @Language::Axbasic::Statement::sortcase::ISA = qw(
20475 Language::Axbasic
20476 Language::Axbasic::Statement
20477 );
20478  
20479 # SORTCASE variable-name
20480  
20481 ##################
20482 # Methods
20483  
20484 sub parse {
20485  
20486 # Called by LA::Line->parse directly after a call to LA::Statement->new
20487 #
20488 # Expected arguments
20489 # (none besides $self)
20490 #
20491 # Return values
20492 # 'undef' on improper arguments or if there is an error
20493 # 1 otherwise
20494  
20495 my ($self, $check) = @_;
20496  
20497 # Local variables
20498 my $expression;
20499  
20500 # Check for improper arguments
20501 if (defined $check) {
20502  
20503 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20504 }
20505  
20506 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20507 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20508 # that created by
20509 # DIM var (10)
20510 # ...by a variable name that looks like a scalar, i.e.
20511 # SORT var
20512 $self->scriptObj->set_declareMode('simple');
20513  
20514 # Get the variable name
20515 $expression = Language::Axbasic::Expression::Lvalue->new(
20516 $self->scriptObj,
20517 $self->tokenGroupObj,
20518 );
20519  
20520 if (! defined $expression) {
20521  
20522 return $self->scriptObj->setError(
20523 'missing_or_illegal_variable',
20524 $self->_objClass . '->parse',
20525 );
20526 }
20527  
20528 # Reset the temporary IV
20529 $self->scriptObj->set_declareMode('default');
20530  
20531 if (! $self->tokenGroupObj->testStatementEnd()) {
20532  
20533 return $self->scriptObj->setError(
20534 'unexpected_keywords,_operators_or_expressions',
20535 $self->_objClass . '->parse',
20536 );
20537 }
20538  
20539 # Store the variable for ->implement to use
20540 $self->ivAdd('parseDataHash', 'expression', $expression);
20541  
20542 # Parsing complete
20543 return 1;
20544 }
20545  
20546 sub implement {
20547  
20548 # Called by LA::Line->implement directly after a call to $self->parse
20549 #
20550 # Expected arguments
20551 # (none besides $self)
20552 #
20553 # Return values
20554 # 'undef' on improper arguments or if there is an error
20555 # 1 otherwise
20556  
20557 my ($self, $check) = @_;
20558  
20559 # Local variables
20560 my (
20561 $expression, $varObj, $lowerBound,
20562 @list, @sortedList,
20563 );
20564  
20565 # Check for improper arguments
20566 if (defined $check) {
20567  
20568 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20569 }
20570  
20571 # Retrieve the array variable to sort
20572 $expression = $self->ivShow('parseDataHash', 'expression');
20573 $varObj = $expression->varObj;
20574  
20575 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20576 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20577 if ($varObj->dimCount > 1) {
20578  
20579 return $self->scriptObj->setError(
20580 'SORTCASE_statement_cannot_operate_on_multi-dimensional_array',
20581 $self->_objClass . '->implement',
20582 );
20583 }
20584  
20585 # Import the values stored in the array, sort them, and store them back in the array
20586 @list = $varObj->cellList;
20587  
20588 # Take account of the first item in ->cellList, which is the lower bound
20589 $lowerBound = shift @list;
20590  
20591 if (ref($varObj) =~ m/Numeric/) {
20592  
20593 # It's a numeric array
20594 @sortedList = sort {$a->value <=> $b->value} (@list);
20595  
20596 } else {
20597  
20598 # It's a string array
20599 @sortedList = sort {lc($a->value) cmp ($b->value)} (@list);
20600 }
20601  
20602 # Restore the lower bound to its previous place
20603 unshift(@sortedList, $lowerBound);
20604 $varObj->ivPoke('cellList', @sortedList);
20605  
20606 # Implementation complete
20607 return 1;
20608 }
20609 }
20610  
20611 { package Language::Axbasic::Statement::sortcaser;
20612  
20613 use strict;
20614 use warnings;
20615 # use diagnostics;
20616  
20617 use Glib qw(TRUE FALSE);
20618  
20619 @Language::Axbasic::Statement::sortcaser::ISA = qw(
20620 Language::Axbasic
20621 Language::Axbasic::Statement
20622 );
20623  
20624 # SORTCASER variable-name
20625  
20626 ##################
20627 # Methods
20628  
20629 sub parse {
20630  
20631 # Called by LA::Line->parse directly after a call to LA::Statement->new
20632 #
20633 # Expected arguments
20634 # (none besides $self)
20635 #
20636 # Return values
20637 # 'undef' on improper arguments or if there is an error
20638 # 1 otherwise
20639  
20640 my ($self, $check) = @_;
20641  
20642 # Local variables
20643 my $expression;
20644  
20645 # Check for improper arguments
20646 if (defined $check) {
20647  
20648 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20649 }
20650  
20651 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20652 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20653 # that created by
20654 # DIM var (10)
20655 # ...by a variable name that looks like a scalar, i.e.
20656 # SORT var
20657 $self->scriptObj->set_declareMode('simple');
20658  
20659 # Get the variable name
20660 $expression = Language::Axbasic::Expression::Lvalue->new(
20661 $self->scriptObj,
20662 $self->tokenGroupObj,
20663 );
20664  
20665 if (! defined $expression) {
20666  
20667 return $self->scriptObj->setError(
20668 'missing_or_illegal_variable',
20669 $self->_objClass . '->parse',
20670 );
20671 }
20672  
20673 # Reset the temporary IV
20674 $self->scriptObj->set_declareMode('default');
20675  
20676 if (! $self->tokenGroupObj->testStatementEnd()) {
20677  
20678 return $self->scriptObj->setError(
20679 'unexpected_keywords,_operators_or_expressions',
20680 $self->_objClass . '->parse',
20681 );
20682 }
20683  
20684 # Store the variable for ->implement to use
20685 $self->ivAdd('parseDataHash', 'expression', $expression);
20686  
20687 # Parsing complete
20688 return 1;
20689 }
20690  
20691 sub implement {
20692  
20693 # Called by LA::Line->implement directly after a call to $self->parse
20694 #
20695 # Expected arguments
20696 # (none besides $self)
20697 #
20698 # Return values
20699 # 'undef' on improper arguments or if there is an error
20700 # 1 otherwise
20701  
20702 my ($self, $check) = @_;
20703  
20704 # Local variables
20705 my (
20706 $expression, $varObj, $lowerBound,
20707 @list, @sortedList,
20708 );
20709  
20710 # Check for improper arguments
20711 if (defined $check) {
20712  
20713 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20714 }
20715  
20716 # Retrieve the array variable to sort
20717 $expression = $self->ivShow('parseDataHash', 'expression');
20718 $varObj = $expression->varObj;
20719  
20720 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20721 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20722 if ($varObj->dimCount > 1) {
20723  
20724 return $self->scriptObj->setError(
20725 'SORTCASER_statement_cannot_operate_on_multi-dimensional_array',
20726 $self->_objClass . '->implement',
20727 );
20728 }
20729  
20730 # Import the values stored in the array, sort them, and store them back in the array
20731 @list = $varObj->cellList;
20732  
20733 # Take account of the first item in ->cellList, which is the lower bound
20734 $lowerBound = shift @list;
20735  
20736 if (ref($varObj) =~ m/Numeric/) {
20737  
20738 # It's a numeric array
20739 @sortedList = sort {$b->value <=> $a->value} (@list);
20740  
20741 } else {
20742  
20743 # It's a string array
20744 @sortedList = sort {lc($b->value) cmp lc($a->value)} (@list);
20745 }
20746  
20747 # Restore the lower bound to its previous place
20748 unshift(@sortedList, $lowerBound);
20749 $varObj->ivPoke('cellList', @sortedList);
20750  
20751 # Implementation complete
20752 return 1;
20753 }
20754 }
20755  
20756 { package Language::Axbasic::Statement::sortr;
20757  
20758 use strict;
20759 use warnings;
20760 # use diagnostics;
20761  
20762 use Glib qw(TRUE FALSE);
20763  
20764 @Language::Axbasic::Statement::sortr::ISA = qw(
20765 Language::Axbasic
20766 Language::Axbasic::Statement
20767 );
20768  
20769 # SORTR variable-name
20770  
20771 ##################
20772 # Methods
20773  
20774 sub parse {
20775  
20776 # Called by LA::Line->parse directly after a call to LA::Statement->new
20777 #
20778 # Expected arguments
20779 # (none besides $self)
20780 #
20781 # Return values
20782 # 'undef' on improper arguments or if there is an error
20783 # 1 otherwise
20784  
20785 my ($self, $check) = @_;
20786  
20787 # Local variables
20788 my $expression;
20789  
20790 # Check for improper arguments
20791 if (defined $check) {
20792  
20793 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20794 }
20795  
20796 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
20797 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
20798 # that created by
20799 # DIM var (10)
20800 # ...by a variable name that looks like a scalar, i.e.
20801 # SORT var
20802 $self->scriptObj->set_declareMode('simple');
20803  
20804 # Get the variable name
20805 $expression = Language::Axbasic::Expression::Lvalue->new(
20806 $self->scriptObj,
20807 $self->tokenGroupObj,
20808 );
20809  
20810 if (! defined $expression) {
20811  
20812 return $self->scriptObj->setError(
20813 'missing_or_illegal_variable',
20814 $self->_objClass . '->parse',
20815 );
20816 }
20817  
20818 # Reset the temporary IV
20819 $self->scriptObj->set_declareMode('default');
20820  
20821 if (! $self->tokenGroupObj->testStatementEnd()) {
20822  
20823 return $self->scriptObj->setError(
20824 'unexpected_keywords,_operators_or_expressions',
20825 $self->_objClass . '->parse',
20826 );
20827 }
20828  
20829 # Store the variable for ->implement to use
20830 $self->ivAdd('parseDataHash', 'expression', $expression);
20831  
20832 # Parsing complete
20833 return 1;
20834 }
20835  
20836 sub implement {
20837  
20838 # Called by LA::Line->implement directly after a call to $self->parse
20839 #
20840 # Expected arguments
20841 # (none besides $self)
20842 #
20843 # Return values
20844 # 'undef' on improper arguments or if there is an error
20845 # 1 otherwise
20846  
20847 my ($self, $check) = @_;
20848  
20849 # Local variables
20850 my (
20851 $expression, $varObj, $lowerBound,
20852 @list, @sortedList,
20853 );
20854  
20855 # Check for improper arguments
20856 if (defined $check) {
20857  
20858 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
20859 }
20860  
20861 # Retrieve the array variable to sort
20862 $expression = $self->ivShow('parseDataHash', 'expression');
20863 $varObj = $expression->varObj;
20864  
20865 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be sorted. Multi-dimensional arrays
20866 # (e.g. DIM var (5, 5, 2) ) can't be sorted
20867 if ($varObj->dimCount > 1) {
20868  
20869 return $self->scriptObj->setError(
20870 'SORTR_statement_cannot_operate_on_multi-dimensional_array',
20871 $self->_objClass . '->implement',
20872 );
20873 }
20874  
20875 # Import the values stored in the array, sort them, and store them back in the array
20876 @list = $varObj->cellList;
20877  
20878 # Take account of the first item in ->cellList, which is the lower bound
20879 $lowerBound = shift @list;
20880  
20881 if (ref($varObj) =~ m/Numeric/) {
20882  
20883 # It's a numeric array
20884 @sortedList = sort {$b->value <=> $a->value} (@list);
20885  
20886 } else {
20887  
20888 # It's a string array
20889 @sortedList = sort {$b->value cmp $a->value} (@list);
20890 }
20891  
20892 # Restore the lower bound to its previous place
20893 unshift(@sortedList, $lowerBound);
20894 $varObj->ivPoke('cellList', @sortedList);
20895  
20896 # Implementation complete
20897 return 1;
20898 }
20899 }
20900  
20901 { package Language::Axbasic::Statement::speak;
20902  
20903 use strict;
20904 use warnings;
20905 # use diagnostics;
20906  
20907 use Glib qw(TRUE FALSE);
20908  
20909 @Language::Axbasic::Statement::speak::ISA = qw(
20910 Language::Axbasic
20911 Language::Axbasic::Statement
20912 );
20913  
20914 # SPEAK expression [ , expression ]
20915  
20916 ##################
20917 # Methods
20918  
20919 sub parse {
20920  
20921 # Called by LA::Line->parse directly after a call to LA::Statement->new
20922 #
20923 # Expected arguments
20924 # (none besides $self)
20925 #
20926 # Return values
20927 # 'undef' on improper arguments or if there is an error
20928 # 1 otherwise
20929  
20930 my ($self, $check) = @_;
20931  
20932 # Local variables
20933 my ($textExp, $configExp, $token);
20934  
20935 # Check for improper arguments
20936 if (defined $check) {
20937  
20938 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
20939 }
20940  
20941 # Convert the text and configuration strings into expressions
20942 $textExp = Language::Axbasic::Expression::Arithmetic->new(
20943 $self->scriptObj,
20944 $self->tokenGroupObj,
20945 );
20946  
20947 if (! defined $textExp) {
20948  
20949 return $self->scriptObj->setError(
20950 'missing_or_illegal_expression',
20951 $self->_objClass . '->parse',
20952 );
20953 }
20954  
20955 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
20956  
20957 $configExp = Language::Axbasic::Expression::Arithmetic->new(
20958 $self->scriptObj,
20959 $self->tokenGroupObj,
20960 );
20961  
20962 if (! defined $configExp) {
20963  
20964 return $self->scriptObj->setError(
20965 'missing_or_illegal_expression',
20966 $self->_objClass . '->parse',
20967 );
20968 }
20969 }
20970  
20971 # Check that nothing follows the expressions
20972 if (! $self->tokenGroupObj->testStatementEnd()) {
20973  
20974 return $self->scriptObj->setError(
20975 'unexpected_keywords,_operators_or_expressions',
20976 $self->_objClass . '->parse',
20977 );
20978 }
20979  
20980 # Store the expressions, so $self->implement can retrieve them
20981 $self->ivAdd('parseDataHash', 'text', $textExp);
20982 $self->ivAdd('parseDataHash', 'config', $configExp);
20983  
20984 # Parsing complete
20985 return 1;
20986 }
20987  
20988 sub implement {
20989  
20990 # Called by LA::Line->implement directly after a call to $self->parse
20991 #
20992 # Expected arguments
20993 # (none besides $self)
20994 #
20995 # Return values
20996 # 'undef' on improper arguments or if there is an error
20997 # 1 otherwise
20998  
20999 my ($self, $check) = @_;
21000  
21001 # Local variables
21002 my ($textExp, $text, $configExp, $configuration, $cmd);
21003  
21004 # Check for improper arguments
21005 if (defined $check) {
21006  
21007 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21008 }
21009  
21010 # Retrieve the arguments stored by $self->parse
21011 $textExp = $self->ivShow('parseDataHash', 'text');
21012 $configExp = $self->ivShow('parseDataHash', 'config');
21013  
21014 # Evaluate each expression
21015 $text = $textExp->evaluate();
21016 if (defined $configExp) {
21017  
21018 $configuration = $configExp->evaluate();
21019 }
21020  
21021 # Prepare the client command
21022 $cmd = 'speak <' . $text . '>';
21023 if ($configuration) {
21024  
21025 $cmd .= ' -n ' . $configuration;
21026 }
21027  
21028 # Send the command
21029 $self->scriptObj->session->pseudoCmd($cmd, $self->scriptObj->pseudoCmdMode);
21030  
21031 # Implementation complete
21032 return 1;
21033 }
21034 }
21035  
21036 { package Language::Axbasic::Statement::speed;
21037  
21038 use strict;
21039 use warnings;
21040 # use diagnostics;
21041  
21042 use Glib qw(TRUE FALSE);
21043  
21044 @Language::Axbasic::Statement::speed::ISA = qw(
21045 Language::Axbasic
21046 Language::Axbasic::Statement
21047 );
21048  
21049 # SPEED expression
21050  
21051 ##################
21052 # Methods
21053  
21054 sub parse {
21055  
21056 # Called by LA::Line->parse directly after a call to LA::Statement->new
21057 #
21058 # Expected arguments
21059 # (none besides $self)
21060 #
21061 # Return values
21062 # 'undef' on improper arguments or if there is an error
21063 # 1 otherwise
21064  
21065 my ($self, $check) = @_;
21066  
21067 # Local variables
21068 my $expression;
21069  
21070 # Check for improper arguments
21071 if (defined $check) {
21072  
21073 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21074 }
21075  
21076 # Get the expression and store it for ->implement to use
21077 $expression = Language::Axbasic::Expression::Arithmetic->new(
21078 $self->scriptObj,
21079 $self->tokenGroupObj,
21080 );
21081  
21082 if (! defined $expression) {
21083  
21084 return $self->scriptObj->setError(
21085 'missing_or_illegal_expression',
21086 $self->_objClass . '->parse',
21087 );
21088  
21089 } else {
21090  
21091 $self->ivAdd('parseDataHash', 'expression', $expression);
21092 }
21093  
21094 # There should be nothing after the expression
21095 if (! $self->tokenGroupObj->testStatementEnd()) {
21096  
21097 return $self->scriptObj->setError(
21098 'unexpected_keywords,_operators_or_expressions',
21099 $self->_objClass . '->parse',
21100 );
21101 }
21102  
21103 # Parsing complete
21104 return 1;
21105 }
21106  
21107 sub implement {
21108  
21109 # Called by LA::Line->implement directly after a call to $self->parse
21110 #
21111 # Expected arguments
21112 # (none besides $self)
21113 #
21114 # Return values
21115 # 'undef' on improper arguments or if there is an error
21116 # 1 otherwise
21117  
21118 my ($self, $check) = @_;
21119  
21120 # Local variables
21121 my ($expression, $string);
21122  
21123 # Check for improper arguments
21124 if (defined $check) {
21125  
21126 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21127 }
21128  
21129 # Retrieve the expression to be written
21130 $expression = $self->ivShow('parseDataHash', 'expression');
21131 # Evaluate the expression to get a scalar value
21132 $string = $expression->evaluate();
21133  
21134 # Execute the expression as a speedwalk command
21135 $self->scriptObj->session->speedWalkCmd($string);
21136  
21137 # Implementation complete
21138 return 1;
21139 }
21140 }
21141  
21142 { package Language::Axbasic::Statement::stop;
21143  
21144 use strict;
21145 use warnings;
21146 # use diagnostics;
21147  
21148 use Glib qw(TRUE FALSE);
21149  
21150 @Language::Axbasic::Statement::stop::ISA = qw(
21151 Language::Axbasic
21152 Language::Axbasic::Statement
21153 );
21154  
21155 # STOP
21156  
21157 ##################
21158 # Methods
21159  
21160 sub parse {
21161  
21162 # Called by LA::Line->parse directly after a call to LA::Statement->new
21163 #
21164 # Expected arguments
21165 # (none besides $self)
21166 #
21167 # Return values
21168 # 'undef' on improper arguments or if there is an error
21169 # 1 otherwise
21170  
21171 my ($self, $check) = @_;
21172  
21173 # Check for improper arguments
21174 if (defined $check) {
21175  
21176 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21177 }
21178  
21179 # STOP statements always appear on their own
21180 if (! $self->tokenGroupObj->testStatementEnd()) {
21181  
21182 return $self->scriptObj->setError(
21183 'unexpected_keywords,_operators_or_expressions',
21184 $self->_objClass . '->parse',
21185 );
21186 }
21187  
21188 # Parsing complete
21189 return 1;
21190 }
21191  
21192 sub implement {
21193  
21194 # Called by LA::Line->implement directly after a call to $self->parse
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 # Check for improper arguments
21206 if (defined $check) {
21207  
21208 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21209 }
21210  
21211 # Execution of the Axbasic script can now stop
21212 if ($self->scriptObj->executionStatus ne 'finished') {
21213  
21214 # 'wait_input' means that parsing/implementation of the script has finished
21215 $self->scriptObj->set_executionStatus('finished');
21216 # 'finished' means that parsing/implementation finished without an error
21217 $self->scriptObj->set_scriptStatus('finished');
21218 }
21219  
21220 # Implementation complete
21221 return 1;
21222 }
21223 }
21224  
21225 { package Language::Axbasic::Statement::sub;
21226  
21227 use strict;
21228 use warnings;
21229 # use diagnostics;
21230  
21231 use Glib qw(TRUE FALSE);
21232  
21233 @Language::Axbasic::Statement::sub::ISA = qw(
21234 Language::Axbasic
21235 Language::Axbasic::Statement
21236 );
21237  
21238 # SUB NUMERIC subroutine-name
21239 # SUB NUMERIC subroutine-name ( [ parameter-list ] )
21240 # SUB subroutine-name
21241 # SUB subroutine-name ( [ parameter-list ] )
21242 # SUB STRING subroutine-name
21243 # SUB STRING subroutine-name ( [ parameter-list ] )
21244  
21245 ##################
21246 # Methods
21247  
21248 sub parse {
21249  
21250 # Called by LA::Line->parse directly after a call to LA::Statement->new
21251 #
21252 # Expected arguments
21253 # (none besides $self)
21254 #
21255 # Return values
21256 # 'undef' on improper arguments or if there is an error
21257 # 1 otherwise
21258  
21259 my ($self, $check) = @_;
21260  
21261 # Local variables
21262 my ($subExpression, $type, $subObj, $expression);
21263  
21264 # Check for improper arguments
21265 if (defined $check) {
21266  
21267 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21268 }
21269  
21270 # The SUB keyword is not available in primitive numbering mode
21271 if ($self->scriptObj->executionMode ne 'no_line_num') {
21272  
21273 return $self->scriptObj->setError(
21274 'statement_not_available_with_line_numbers',
21275 $self->_objClass . '->parse',
21276 );
21277 }
21278  
21279 # Look for the keywords NUMERIC or STRING, which define what type of return value the
21280 # subroutine will produce. If neither occurs, the subroutine returns a numeric value
21281 if (defined $self->tokenGroupObj->shiftMatchingToken('string')) {
21282  
21283 $type = 'string';
21284  
21285 } else {
21286  
21287 $self->tokenGroupObj->shiftMatchingToken('numeric');
21288 $type = 'numeric';
21289 }
21290  
21291 # Temporarily set the IV that allows undeclared variables to be created
21292 $self->scriptObj->set_declareMode('local_scalar');
21293  
21294 # The subroutine name, and its arguments, consist of all the tokens up until the close
21295 # parenthesis
21296 if ($type eq 'numeric') {
21297  
21298 $subExpression = Language::Axbasic::Expression::Subroutine::Numeric->new(
21299 $self->scriptObj,
21300 $self->tokenGroupObj,
21301 );
21302  
21303 } else {
21304  
21305 $subExpression = Language::Axbasic::Expression::Subroutine::String->new(
21306 $self->scriptObj,
21307 $self->tokenGroupObj,
21308 );
21309 }
21310  
21311 # Reset the temporary IV
21312 $self->scriptObj->set_declareMode('default');
21313  
21314 if (! defined $subExpression) {
21315  
21316 return $self->scriptObj->setError(
21317 'subroutine_declaration_error',
21318 $self->_objClass . '->parse',
21319 );
21320 }
21321  
21322 # Check that there is nothing after the list of arguments (except for the statement
21323 # separator, :)
21324 if (! defined $self->tokenGroupObj->testStatementEnd()) {
21325  
21326 return $self->scriptObj->setError(
21327 'unexpected_keywords,_operators_or_expressions',
21328 $self->_objClass . '->parse',
21329 );
21330 }
21331  
21332 # Subroutines cannot be declared inside another one (except for the implied *main
21333 # subroutine, in which any number of subroutines can be declared)
21334 if ($self->scriptObj->currentParseSub) {
21335  
21336 return $self->scriptObj->setError(
21337 'subroutine_declared_inside_another',
21338 $self->_objClass . '->parse',
21339 );
21340 }
21341  
21342 # We don't actually want the LA::Expression, just the LA::Subroutine object we've declared
21343 $subObj = $subExpression->subObj;
21344 # Store it in the script's list of subroutines
21345 $self->scriptObj->add_subName($subObj->name, $subObj);
21346  
21347 # Save the function object - ->implement needs it
21348 $self->ivAdd('parseDataHash', 'sub_obj', $subObj);
21349  
21350 # Tell LA::Script->parse that it's parsing statements inside a subroutine declaration now
21351 $self->scriptObj->set_currentParseSub($subObj);
21352 # Tell the subroutine in which statement it is declared
21353 $subObj->set_declareStatement($self);
21354 # Tell the subroutine what kind of return value it is going to send
21355 $subObj->set_returnVarType($type);
21356  
21357 # Parsing complete
21358 return 1;
21359 }
21360  
21361 sub implement {
21362  
21363 # Called by LA::Line->implement directly after a call to $self->parse
21364 #
21365 # Expected arguments
21366 # (none besides $self)
21367 #
21368 # Return values
21369 # 'undef' on improper arguments or if there is an error
21370 # 1 otherwise
21371  
21372 my ($self, $check) = @_;
21373  
21374 # Local variables
21375 my ($subObj, $endStatement);
21376  
21377 # Check for improper arguments
21378 if (defined $check) {
21379  
21380 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21381 }
21382  
21383 # SUB statements are ->implemented in the following situation
21384 #
21385 # PRINT "Hello world!"
21386 # SUB STRING test (var$)
21387 # ...
21388 # END SUB
21389 # PRINT "Goodbye cruel world!"
21390 # END
21391 #
21392 # ...namely, when a subroutine declaration occurs before the END statement
21393 # After executing the PRINT "Hello world!", this function locates the correct
21394 # LA::Subroutine, finds the END SUB statement, and marks the next statement
21395 # after that - in this case, the PRINT "Goodbye cruel world!" - as the
21396 # next statement to execute. Everything between SUB...END SUB is ignored
21397  
21398 $subObj = $self->ivShow('parseDataHash', 'sub_obj');
21399  
21400 # Find the subroutine's END SUB statement
21401 $endStatement = $subObj->terminateStatement;
21402  
21403 # The next statement to execute is the statement after that
21404 if (defined $endStatement->nextStatement) {
21405  
21406 # LA::Script->nextStatement is currently set to this statement; continue execution
21407 # as if this were the END statement
21408 $self->scriptObj->set_nextStatement($endStatement);
21409  
21410 } else {
21411  
21412 $self->scriptObj->set_nextStatement(undef);
21413 $self->scriptObj->set_nextLine($endStatement->lineObj->procLineNum + 1);
21414 }
21415  
21416 # Implementation complete
21417 return 1;
21418 }
21419 }
21420  
21421 { package Language::Axbasic::Statement::titlewin;
21422  
21423 use strict;
21424 use warnings;
21425 # use diagnostics;
21426  
21427 use Glib qw(TRUE FALSE);
21428  
21429 @Language::Axbasic::Statement::titlewin::ISA = qw(
21430 Language::Axbasic
21431 Language::Axbasic::Statement
21432 );
21433  
21434 # TITLEWIN expression
21435  
21436 ##################
21437 # Methods
21438  
21439 sub parse {
21440  
21441 # Called by LA::Line->parse directly after a call to LA::Statement->new
21442 #
21443 # Expected arguments
21444 # (none besides $self)
21445 #
21446 # Return values
21447 # 'undef' on improper arguments or if there is an error
21448 # 1 otherwise
21449  
21450 my ($self, $check) = @_;
21451  
21452 # Local variables
21453 my $expression;
21454  
21455 # Check for improper arguments
21456 if (defined $check) {
21457  
21458 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21459 }
21460  
21461 # Get the expression and store it for ->implement to use
21462 $expression = Language::Axbasic::Expression::Arithmetic->new(
21463 $self->scriptObj,
21464 $self->tokenGroupObj,
21465 );
21466  
21467 if (! defined $expression) {
21468  
21469 return $self->scriptObj->setError(
21470 'missing_or_illegal_expression',
21471 $self->_objClass . '->parse',
21472 );
21473  
21474 } else {
21475  
21476 $self->ivAdd('parseDataHash', 'expression', $expression);
21477 }
21478  
21479 # There should be nothing after the expression
21480 if (! $self->tokenGroupObj->testStatementEnd()) {
21481  
21482 return $self->scriptObj->setError(
21483 'unexpected_keywords,_operators_or_expressions',
21484 $self->_objClass . '->parse',
21485 );
21486 }
21487  
21488 # Parsing complete
21489 return 1;
21490 }
21491  
21492 sub implement {
21493  
21494 # Called by LA::Line->implement directly after a call to $self->parse
21495 #
21496 # Expected arguments
21497 # (none besides $self)
21498 #
21499 # Return values
21500 # 'undef' on improper arguments or if there is an error
21501 # 1 otherwise
21502  
21503 my ($self, $check) = @_;
21504  
21505 # Local variables
21506 my ($expression, $string);
21507  
21508 # Check for improper arguments
21509 if (defined $check) {
21510  
21511 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21512 }
21513  
21514 # Retrieve the expression to be used as a title
21515 $expression = $self->ivShow('parseDataHash', 'expression');
21516 # Evaluate the expression to get a string
21517 $string = $expression->evaluate();
21518  
21519 # If the Axbasic script is being run from within an Axmud task and the task window is open,
21520 # set its title. Otherwise, do nothing
21521 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->taskWinFlag) {
21522  
21523 # Write to the window. If $string is an empty string, restore the original title
21524 if ($string) {
21525 $self->scriptObj->parentTask->setTitle($string);
21526 } else {
21527 $self->scriptObj->parentTask->setTitle();
21528 }
21529 }
21530  
21531 # Implementation complete
21532 return 1;
21533 }
21534 }
21535  
21536 { package Language::Axbasic::Statement::unflashwin;
21537  
21538 use strict;
21539 use warnings;
21540 # use diagnostics;
21541  
21542 use Glib qw(TRUE FALSE);
21543  
21544 @Language::Axbasic::Statement::unflashwin::ISA = qw(
21545 Language::Axbasic
21546 Language::Axbasic::Statement
21547 );
21548  
21549 # UNFLASHWIN
21550  
21551 ##################
21552 # Methods
21553  
21554 sub parse {
21555  
21556 # Called by LA::Line->parse directly after a call to LA::Statement->new
21557 #
21558 # Expected arguments
21559 # (none besides $self)
21560 #
21561 # Return values
21562 # 'undef' on improper arguments or if there is an error
21563 # 1 otherwise
21564  
21565 my ($self, $check) = @_;
21566  
21567 # Local variables
21568 my ($expression);
21569  
21570 # Check for improper arguments
21571 if (defined $check) {
21572  
21573 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21574 }
21575  
21576 # UNFLASHWIN statements always appear on their own
21577 if (! $self->tokenGroupObj->testStatementEnd()) {
21578  
21579 return $self->scriptObj->setError(
21580 'unexpected_keywords,_operators_or_expressions',
21581 $self->_objClass . '->parse',
21582 );
21583 }
21584  
21585 # Parsing complete
21586 return 1;
21587 }
21588  
21589 sub implement {
21590  
21591 # Called by LA::Line->implement directly after a call to $self->parse
21592 #
21593 # Expected arguments
21594 # (none besides $self)
21595 #
21596 # Return values
21597 # 'undef' on improper arguments or if there is an error
21598 # 1 otherwise
21599  
21600 my ($self, $check) = @_;
21601  
21602 # Local variables
21603  
21604 # Check for improper arguments
21605 if (defined $check) {
21606  
21607 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21608 }
21609  
21610 # If the Axbasic script is being run from within an Axmud task and the task window is open,
21611 # reset the window's urgency hint. Otherwise, do nothing
21612 if ($self->scriptObj->parentTask && $self->scriptObj->parentTask->winObj) {
21613  
21614 # Sets the window urgency hint
21615 $self->scriptObj->parentTask->winObj->resetUrgent();
21616 }
21617  
21618 # Implementation complete
21619 return 1;
21620 }
21621 }
21622  
21623 { package Language::Axbasic::Statement::unshift;
21624  
21625 use strict;
21626 use warnings;
21627 # use diagnostics;
21628  
21629 use Glib qw(TRUE FALSE);
21630  
21631 @Language::Axbasic::Statement::unshift::ISA = qw(
21632 Language::Axbasic
21633 Language::Axbasic::Statement
21634 );
21635  
21636 # UNSHIFT array-name , expression
21637  
21638 ##################
21639 # Methods
21640  
21641 sub parse {
21642  
21643 # Called by LA::Line->parse directly after a call to LA::Statement->new
21644 #
21645 # Expected arguments
21646 # (none besides $self)
21647 #
21648 # Return values
21649 # 'undef' on improper arguments or if there is an error
21650 # 1 otherwise
21651  
21652 my ($self, $check) = @_;
21653  
21654 # Local variables
21655 my ($arrayExp, $scalarExp);
21656  
21657 # Check for improper arguments
21658 if (defined $check) {
21659  
21660 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21661 }
21662  
21663 # Abuse the IV that allows undeclared variables to be created by hijacking it to tell
21664 # LA::Variable->lookup that we're intentionally referring to an array variable, such as
21665 # that created by
21666 # DIM var (10)
21667 # ...by a variable name that looks like a scalar, i.e.
21668 # SORT var
21669 $self->scriptObj->set_declareMode('simple');
21670  
21671 # Get the array variable name
21672 $arrayExp = Language::Axbasic::Expression::Lvalue->new(
21673 $self->scriptObj,
21674 $self->tokenGroupObj,
21675 );
21676  
21677 if (! defined $arrayExp) {
21678  
21679 return $self->scriptObj->setError(
21680 'missing_or_illegal_array_variable',
21681 $self->_objClass . '->parse',
21682 );
21683 }
21684  
21685 # Reset the temporary IV
21686 $self->scriptObj->set_declareMode('default');
21687  
21688 if (! defined $self->tokenGroupObj->shiftMatchingToken(',')) {
21689  
21690 return $self->scriptObj->setError(
21691 'syntax_error',
21692 $self->_objClass . '->parse',
21693 );
21694 }
21695  
21696 # Extract the non-optional scalar expression
21697 $scalarExp = Language::Axbasic::Expression::Arithmetic->new(
21698 $self->scriptObj,
21699 $self->tokenGroupObj,
21700 );
21701  
21702 if (! defined $scalarExp) {
21703  
21704 return $self->scriptObj->setError(
21705 'missing_or_illegal_expression',
21706 $self->_objClass . '->parse',
21707 );
21708 }
21709  
21710 if (! $self->tokenGroupObj->testStatementEnd()) {
21711  
21712 return $self->scriptObj->setError(
21713 'unexpected_keywords,_operators_or_expressions',
21714 $self->_objClass . '->parse',
21715 );
21716 }
21717  
21718 # Save the expression objects so $self->implement can use them, if it is called
21719 $self->ivAdd('parseDataHash', 'array_exp', $arrayExp);
21720 $self->ivAdd('parseDataHash', 'scalar_exp', $scalarExp);
21721  
21722 # Parsing complete
21723 return 1;
21724 }
21725  
21726 sub implement {
21727  
21728 # Called by LA::Line->implement directly after a call to $self->parse
21729 #
21730 # Expected arguments
21731 # (none besides $self)
21732 #
21733 # Return values
21734 # 'undef' on improper arguments
21735 # 1 otherwise
21736  
21737 my ($self, $check) = @_;
21738  
21739 # Local variables
21740 my ($arrayExp, $scalarExp, $removedVar);
21741  
21742 # Check for improper arguments
21743 if (defined $check) {
21744  
21745 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21746 }
21747  
21748 # Retrieve the variables stored by ->parse
21749 $arrayExp = $self->ivShow('parseDataHash', 'array_exp');
21750 $scalarExp = $self->ivShow('parseDataHash', 'scalar_exp');
21751  
21752 # Only 1-dimensional arrays (e.g. DIM var (5) ) can be unshifted. Multi-dimensional arrays
21753 # (e.g. DIM var (5, 5, 2) ) can't be unshifted
21754 if ($arrayExp->varObj->dimCount > 1) {
21755  
21756 return $self->scriptObj->setError(
21757 'UNSHIFT_statement_cannot_operate_on_multi-dimensional_array',
21758 $self->_objClass . '->implement',
21759 );
21760 }
21761  
21762 # Cannot use a numeric array with a string scalar, and vice-versa
21763 if (
21764 ((ref ($arrayExp->varObj) =~ m/String/) && (ref ($scalarExp) =~ m/Numeric/))
21765 || ((ref ($arrayExp->varObj) =~ m/Numeric/) && (ref ($scalarExp) =~ m/String/))
21766 ) {
21767 return $self->scriptObj->setError(
21768 'type_mismatch_error',
21769 $self->_objClass . '->implement',
21770 );
21771 }
21772  
21773 # Evaluate the expression, and unshift it from the stack
21774 $arrayExp->varObj->doUnshift($scalarExp->evaluate());
21775  
21776 # Implementation complete
21777 return 1;
21778 }
21779 }
21780  
21781 { package Language::Axbasic::Statement::until;
21782  
21783 use strict;
21784 use warnings;
21785 # use diagnostics;
21786  
21787 use Glib qw(TRUE FALSE);
21788  
21789 @Language::Axbasic::Statement::until::ISA = qw(
21790 Language::Axbasic
21791 Language::Axbasic::Statement
21792 );
21793  
21794 # UNTIL condition
21795 # UNTIL expression
21796  
21797 ##################
21798 # Methods
21799  
21800 sub parse {
21801  
21802 # Called by LA::Line->parse directly after a call to LA::Statement->new
21803 #
21804 # Expected arguments
21805 # (none besides $self)
21806 #
21807 # Return values
21808 # 'undef' on improper arguments or if there is an error
21809 # 1 otherwise
21810  
21811 my ($self, $check) = @_;
21812  
21813 # Local variables
21814 my ($condition, $subObj, $doStatement);
21815  
21816 # Check for improper arguments
21817 if (defined $check) {
21818  
21819 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
21820 }
21821  
21822 # The 'until' keyword is not available in primitive numbering mode
21823 if ($self->scriptObj->executionMode ne 'no_line_num') {
21824  
21825 return $self->scriptObj->setError(
21826 'statement_not_available_with_line_numbers',
21827 $self->_objClass . '->parse',
21828 );
21829 }
21830  
21831 # Read a conditional expression
21832 $condition = Language::Axbasic::Expression::LogicalOr->new(
21833 $self->scriptObj,
21834 $self->tokenGroupObj,
21835 'maybe_arithmetic',
21836 );
21837  
21838 if (! defined $condition) {
21839  
21840 return $self->scriptObj->setError(
21841 'missing_or_illegal_conditional_expression',
21842 $self->_objClass . '->parse',
21843 );
21844  
21845 } else {
21846  
21847 # Store the condition expression, so $self->implement can retrieve it
21848 $self->ivAdd('parseDataHash', 'condition', $condition);
21849 }
21850  
21851 # Check there's nothing else in the statement after the condition expression
21852 if (! $self->tokenGroupObj->testStatementEnd()) {
21853  
21854 return $self->scriptObj->setError(
21855 'unexpected_keywords,_operators_or_expressions',
21856 $self->_objClass . '->parse',
21857 );
21858 }
21859  
21860 # Find the matching DO statement, which should already have been parsed
21861 $subObj = $self->scriptObj->returnCurrentSub();
21862 if (! $subObj->doStackList) {
21863  
21864 return $self->scriptObj->setError(
21865 'UNTIL_statement_without_matching_DO',
21866 $self->_objClass . '->parse',
21867 );
21868  
21869 } else {
21870  
21871 $doStatement = $subObj->pop_doStackList();
21872  
21873 # Tell the DO statement's ->implement what its matching LOOP statement (i.e. this one)
21874 # is
21875 $doStatement->add_parseDataHash('until_statement', $self);
21876 }
21877  
21878 # Parsing complete
21879 return 1;
21880 }
21881  
21882 sub implement {
21883  
21884 # Called by LA::Line->implement directly after a call to $self->parse
21885 #
21886 # Expected arguments
21887 # (none besides $self)
21888 #
21889 # Return values
21890 # 'undef' on improper arguments or if there is an error
21891 # 1 otherwise
21892  
21893 my ($self, $check) = @_;
21894  
21895 # Local variables
21896 my ($condition, $subObj, $doStatement, $exitFlag);
21897  
21898 # Check for improper arguments
21899 if (defined $check) {
21900  
21901 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
21902 }
21903  
21904 # Retrieve the condition expression stored by $self->parse
21905 $condition = $self->ivShow('parseDataHash', 'condition');
21906  
21907 # Get the corresponding DO statement from the current subroutine's code block stack. Keep
21908 # removing code blocks from the top of the stack until we get the right one
21909 $subObj = $self->scriptObj->returnCurrentSub();
21910 if (! $subObj->blockStackList) {
21911  
21912 return $self->scriptObj->setError(
21913 'UNTIL_statement_without_matching_DO',
21914 $self->_objClass . '->implement',
21915 );
21916 }
21917  
21918 do {
21919 $doStatement = $subObj->pop_blockStackList();
21920  
21921 # Check that it's a DO statement - not the start of another kind of code block
21922 if ($doStatement->keyword eq 'do') {
21923  
21924 # We've found the statement we're looking for
21925 $exitFlag = TRUE;
21926 }
21927  
21928 } until ($exitFlag || ! $subObj->blockStackList);
21929  
21930 if (! $exitFlag) {
21931  
21932 return $self->scriptObj->setError(
21933 'UNTIL_statement_without_matching_DO',
21934 $self->_objClass . '->implement',
21935 );
21936 }
21937  
21938 # Evaluate the condition expression
21939 if (! $condition->evaluate()) {
21940  
21941 # The condition expression is false, so we need to perform another iteration of the loop
21942 if (defined $doStatement->nextStatement) {
21943  
21944 # LA::Script->nextStatement is currently set to this statement; continue execution
21945 # as if this were the DO statement
21946 $self->scriptObj->set_nextStatement($doStatement);
21947  
21948 } else {
21949  
21950 $self->scriptObj->set_nextStatement(undef);
21951 $self->scriptObj->set_nextLine($doStatement->lineObj->procLineNum + 1);
21952 }
21953  
21954 # Put the corresponding DO statement back into the current subroutine's code block stack
21955 $subObj->push_blockStackList($doStatement);
21956 }
21957  
21958 # Implementation complete
21959 return 1;
21960 }
21961 }
21962  
21963 { package Language::Axbasic::Statement::waitactive;
21964  
21965 use strict;
21966 use warnings;
21967 # use diagnostics;
21968  
21969 use Glib qw(TRUE FALSE);
21970  
21971 @Language::Axbasic::Statement::waitactive::ISA = qw(
21972 Language::Axbasic
21973 Language::Axbasic::Statement
21974 );
21975  
21976 # WAITACTIVE expression
21977  
21978 ##################
21979 # Methods
21980  
21981 sub parse {
21982  
21983 # Called by LA::Line->parse directly after a call to LA::Statement->new
21984 #
21985 # Expected arguments
21986 # (none besides $self)
21987 #
21988 # Return values
21989 # 'undef' on improper arguments or if there is an error
21990 # 1 otherwise
21991  
21992 my ($self, $check) = @_;
21993  
21994 # Local variables
21995 my $taskNameExp;
21996  
21997 # Check for improper arguments
21998 if (defined $check) {
21999  
22000 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22001 }
22002  
22003 # Convert the task string into an expression
22004 $taskNameExp = Language::Axbasic::Expression::Arithmetic->new(
22005 $self->scriptObj,
22006 $self->tokenGroupObj,
22007 );
22008  
22009 if (! defined $taskNameExp) {
22010  
22011 return $self->scriptObj->setError(
22012 'missing_or_illegal_expression',
22013 $self->_objClass . '->parse',
22014 );
22015 }
22016  
22017 # Check that nothing follows the expression(s)
22018 if (! $self->tokenGroupObj->testStatementEnd()) {
22019  
22020 return $self->scriptObj->setError(
22021 'unexpected_keywords,_operators_or_expressions',
22022 $self->_objClass . '->parse',
22023 );
22024 }
22025  
22026 # Store the expression, so $self->implement can retrieve it
22027 $self->ivAdd('parseDataHash', 'task_name', $taskNameExp);
22028  
22029 # Parsing complete
22030 return 1;
22031 }
22032  
22033 sub implement {
22034  
22035 # Called by LA::Line->implement directly after a call to $self->parse
22036 #
22037 # Expected arguments
22038 # (none besides $self)
22039 #
22040 # Return values
22041 # 'undef' on improper arguments or if there is an error
22042 # 1 otherwise
22043  
22044 my ($self, $check) = @_;
22045  
22046 # Local variables
22047 my ($taskNameExp, $taskName, $taskObj);
22048  
22049 # Check for improper arguments
22050 if (defined $check) {
22051  
22052 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22053 }
22054  
22055 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22056 if (! $self->scriptObj->parentTask) {
22057  
22058 # Implementation complete. Execution resumes from the next statement
22059 return 1;
22060 }
22061  
22062 # Otherwise, retrieve the argument stored by $self->parse
22063 $taskNameExp = $self->ivShow('parseDataHash', 'task_name');
22064  
22065 # Evaluate the expression(s)
22066 $taskName = $taskNameExp->evaluate();
22067  
22068 # Look for a task matching $taskName. GA::Generic::Cmd->findTask recognises task labels
22069 # (stored in GA::Client->taskLabelHash), tasks' formal names (stored in
22070 # GA::Client->taskPackageHash), or task unique names in the current tasklist (stored in
22071 # GA::Session->currentTaskHash)
22072 ($taskObj) = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $taskName);
22073 if (! $taskObj) {
22074  
22075 # No matching task in the current tasklist
22076 return $self->scriptObj->setError(
22077 'WAITACTIVE_operation_failure',
22078 $self->_objClass . '->parse',
22079 );
22080 }
22081  
22082 # Inform the LA::Script's parent task that it should start waiting
22083 $self->scriptObj->parentTask->setUpMonitoring('task_active', $taskObj->uniqueName);
22084  
22085 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22086 $self->scriptObj->set_scriptStatus('wait_active');
22087  
22088 # Implementation complete
22089 return 1;
22090 }
22091 }
22092  
22093 { package Language::Axbasic::Statement::waitalias;
22094  
22095 use strict;
22096 use warnings;
22097 # use diagnostics;
22098  
22099 use Glib qw(TRUE FALSE);
22100  
22101 @Language::Axbasic::Statement::waitalias::ISA = qw(
22102 Language::Axbasic
22103 Language::Axbasic::Statement
22104 );
22105  
22106 # WAITALIAS expression [ , expression ]
22107  
22108 ##################
22109 # Methods
22110  
22111 sub parse {
22112  
22113 # Called by LA::Line->parse directly after a call to LA::Statement->new
22114 #
22115 # Expected arguments
22116 # (none besides $self)
22117 #
22118 # Return values
22119 # 'undef' on improper arguments or if there is an error
22120 # 1 otherwise
22121  
22122 my ($self, $check) = @_;
22123  
22124 # Check for improper arguments
22125 if (defined $check) {
22126  
22127 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22128 }
22129  
22130 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
22131 # ready for $self->implement to access
22132 if (! $self->parseWaitInterface()) {
22133  
22134 # ($self->scriptObj->setError has already been called)
22135 return undef;
22136 }
22137  
22138 # Parsing complete
22139 return 1;
22140 }
22141  
22142 sub implement {
22143  
22144 # Called by LA::Line->implement directly after a call to $self->parse
22145 #
22146 # Expected arguments
22147 # (none besides $self)
22148 #
22149 # Return values
22150 # 'undef' on improper arguments or if there is an error
22151 # 1 otherwise
22152  
22153 my ($self, $check) = @_;
22154  
22155 # Check for improper arguments
22156 if (defined $check) {
22157  
22158 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22159 }
22160  
22161 # Implement the statement, haveing parsed it
22162 if (! $self->implementWaitInterface('alias')) {
22163  
22164 # ($self->scriptObj->setError has already been called)
22165 return undef;
22166 }
22167  
22168 # Implementation complete
22169 return 1;
22170 }
22171 }
22172  
22173 { package Language::Axbasic::Statement::waitalive;
22174  
22175 use strict;
22176 use warnings;
22177 # use diagnostics;
22178  
22179 use Glib qw(TRUE FALSE);
22180  
22181 @Language::Axbasic::Statement::waitalive::ISA = qw(
22182 Language::Axbasic
22183 Language::Axbasic::Statement
22184 );
22185  
22186 # WAITALIVE [ expression ]
22187  
22188 ##################
22189 # Methods
22190  
22191 sub parse {
22192  
22193 # Called by LA::Line->parse directly after a call to LA::Statement->new
22194 #
22195 # Expected arguments
22196 # (none besides $self)
22197 #
22198 # Return values
22199 # 'undef' on improper arguments or if there is an error
22200 # 1 otherwise
22201  
22202 my ($self, $check) = @_;
22203  
22204 # Local variables
22205 my $timeoutExp;
22206  
22207 # Check for improper arguments
22208 if (defined $check) {
22209  
22210 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22211 }
22212  
22213 # Get the timeout, if specified, and convert it into an expression
22214 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22215  
22216 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22217 $self->scriptObj,
22218 $self->tokenGroupObj,
22219 );
22220  
22221 if (! defined $timeoutExp) {
22222  
22223 return $self->scriptObj->setError(
22224 'missing_or_illegal_expression',
22225 $self->_objClass . '->parse',
22226 );
22227 }
22228 }
22229  
22230 # Check that nothing follows the expression(s)
22231 if (! $self->tokenGroupObj->testStatementEnd()) {
22232  
22233 return $self->scriptObj->setError(
22234 'unexpected_keywords,_operators_or_expressions',
22235 $self->_objClass . '->parse',
22236 );
22237 }
22238  
22239 # Store the expression (if specified), so $self->implement can retrieve it
22240 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22241  
22242 # Parsing complete
22243 return 1;
22244 }
22245  
22246 sub implement {
22247  
22248 # Called by LA::Line->implement directly after a call to $self->parse
22249 #
22250 # Expected arguments
22251 # (none besides $self)
22252 #
22253 # Return values
22254 # 'undef' on improper arguments or if there is an error
22255 # 1 otherwise
22256  
22257 my ($self, $check) = @_;
22258  
22259 # Local variables
22260 my ($timeoutExp, $timeout);
22261  
22262 # Check for improper arguments
22263 if (defined $check) {
22264  
22265 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22266 }
22267  
22268 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22269 if (! $self->scriptObj->parentTask) {
22270  
22271 # Implementation complete. Execution resumes from the next statement
22272 return 1;
22273 }
22274  
22275 # Otherwise, retrieve the argument (if any) stored by $self->parse
22276 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22277  
22278 # Evaluate the expression, if specified
22279 if (defined $timeoutExp) {
22280  
22281 $timeout = $timeoutExp->evaluate();
22282  
22283 if (! ($timeout =~ /^\d+$/)) {
22284  
22285 return $self->scriptObj->setError(
22286 'invalid_integer',
22287 $self->_objClass . '->implement',
22288 );
22289  
22290 } elsif ($timeout < 1) {
22291  
22292 return $self->scriptObj->setError(
22293 'number_NUM_out_of_range',
22294 $self->_objClass . '->implement',
22295 'NUM', $timeout,
22296 );
22297 }
22298 }
22299  
22300 # Inform the parent task that it should start waiting
22301 $self->scriptObj->parentTask->setUpMonitoring(
22302 'status',
22303 'alive',
22304 undef,
22305 $timeout,
22306 );
22307  
22308 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22309 $self->scriptObj->set_scriptStatus('wait_status');
22310  
22311 # Implementation complete
22312 return 1;
22313 }
22314 }
22315  
22316 { package Language::Axbasic::Statement::waitarrive;
22317  
22318 use strict;
22319 use warnings;
22320 # use diagnostics;
22321  
22322 use Glib qw(TRUE FALSE);
22323  
22324 @Language::Axbasic::Statement::waitarrive::ISA = qw(
22325 Language::Axbasic
22326 Language::Axbasic::Statement
22327 );
22328  
22329 # WAITARRIVE [ expression ]
22330  
22331 ##################
22332 # Methods
22333  
22334 sub parse {
22335  
22336 # Called by LA::Line->parse directly after a call to LA::Statement->new
22337 #
22338 # Expected arguments
22339 # (none besides $self)
22340 #
22341 # Return values
22342 # 'undef' on improper arguments or if there is an error
22343 # 1 otherwise
22344  
22345 my ($self, $check) = @_;
22346  
22347 # Local variables
22348 my $timeoutExp;
22349  
22350 # Check for improper arguments
22351 if (defined $check) {
22352  
22353 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22354 }
22355  
22356 # Get the timeout, if specified, and convert it into an expression
22357 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22358  
22359 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22360 $self->scriptObj,
22361 $self->tokenGroupObj,
22362 );
22363  
22364 if (! defined $timeoutExp) {
22365  
22366 return $self->scriptObj->setError(
22367 'missing_or_illegal_expression',
22368 $self->_objClass . '->parse',
22369 );
22370 }
22371 }
22372  
22373 # Check that nothing follows the expression(s)
22374 if (! $self->tokenGroupObj->testStatementEnd()) {
22375  
22376 return $self->scriptObj->setError(
22377 'unexpected_keywords,_operators_or_expressions',
22378 $self->_objClass . '->parse',
22379 );
22380 }
22381  
22382 # Store the expression (if specified), so $self->implement can retrieve it
22383 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22384  
22385 # Parsing complete
22386 return 1;
22387 }
22388  
22389 sub implement {
22390  
22391 # Called by LA::Line->implement directly after a call to $self->parse
22392 #
22393 # Expected arguments
22394 # (none besides $self)
22395 #
22396 # Return values
22397 # 'undef' on improper arguments or if there is an error
22398 # 1 otherwise
22399  
22400 my ($self, $check) = @_;
22401  
22402 # Local variables
22403 my ($timeoutExp, $timeout);
22404  
22405 # Check for improper arguments
22406 if (defined $check) {
22407  
22408 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22409 }
22410  
22411 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22412 if (! $self->scriptObj->parentTask) {
22413  
22414 # Implementation complete. Execution resumes from the next statement
22415 return 1;
22416 }
22417  
22418 # Otherwise, retrieve the argument (if any) stored by $self->parse
22419 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22420  
22421 # Evaluate the expression, if specified
22422 if (defined $timeoutExp) {
22423  
22424 $timeout = $timeoutExp->evaluate();
22425  
22426 if (! ($timeout =~ /^\d+$/)) {
22427  
22428 return $self->scriptObj->setError(
22429 'invalid_integer',
22430 $self->_objClass . '->implement',
22431 );
22432  
22433 } elsif ($timeout < 1) {
22434  
22435 return $self->scriptObj->setError(
22436 'number_NUM_out_of_range',
22437 $self->_objClass . '->implement',
22438 'NUM', $timeout,
22439 );
22440 }
22441 }
22442  
22443 # Inform the parent task that it should start waiting
22444 $self->scriptObj->parentTask->setUpMonitoring(
22445 'locator',
22446 'arrive',
22447 undef,
22448 $timeout,
22449 );
22450  
22451 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22452 $self->scriptObj->set_scriptStatus('wait_status');
22453  
22454 # Implementation complete
22455 return 1;
22456 }
22457 }
22458  
22459 { package Language::Axbasic::Statement::waitdead;
22460  
22461 use strict;
22462 use warnings;
22463 # use diagnostics;
22464  
22465 use Glib qw(TRUE FALSE);
22466  
22467 @Language::Axbasic::Statement::waitdead::ISA = qw(
22468 Language::Axbasic
22469 Language::Axbasic::Statement
22470 );
22471  
22472 # WAITDEAD [ expression ]
22473  
22474 ##################
22475 # Methods
22476  
22477 sub parse {
22478  
22479 # Called by LA::Line->parse directly after a call to LA::Statement->new
22480 #
22481 # Expected arguments
22482 # (none besides $self)
22483 #
22484 # Return values
22485 # 'undef' on improper arguments or if there is an error
22486 # 1 otherwise
22487  
22488 my ($self, $check) = @_;
22489  
22490 # Local variables
22491 my $timeoutExp;
22492  
22493 # Check for improper arguments
22494 if (defined $check) {
22495  
22496 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22497 }
22498  
22499 # Get the timeout, if specified, and convert it into an expression
22500 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22501  
22502 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22503 $self->scriptObj,
22504 $self->tokenGroupObj,
22505 );
22506  
22507 if (! defined $timeoutExp) {
22508  
22509 return $self->scriptObj->setError(
22510 'missing_or_illegal_expression',
22511 $self->_objClass . '->parse',
22512 );
22513 }
22514 }
22515  
22516 # Check that nothing follows the expression(s)
22517 if (! $self->tokenGroupObj->testStatementEnd()) {
22518  
22519 return $self->scriptObj->setError(
22520 'unexpected_keywords,_operators_or_expressions',
22521 $self->_objClass . '->parse',
22522 );
22523 }
22524  
22525 # Store the expression (if specified), so $self->implement can retrieve it
22526 if (defined $timeoutExp) {
22527  
22528 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22529 }
22530  
22531 # Parsing complete
22532 return 1;
22533 }
22534  
22535 sub implement {
22536  
22537 # Called by LA::Line->implement directly after a call to $self->parse
22538 #
22539 # Expected arguments
22540 # (none besides $self)
22541 #
22542 # Return values
22543 # 'undef' on improper arguments or if there is an error
22544 # 1 otherwise
22545  
22546 my ($self, $check) = @_;
22547  
22548 # Local variables
22549 my ($timeoutExp, $timeout);
22550  
22551 # Check for improper arguments
22552 if (defined $check) {
22553  
22554 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22555 }
22556  
22557 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22558 if (! $self->scriptObj->parentTask) {
22559  
22560 # Implementation complete. Execution resumes from the next statement
22561 return 1;
22562 }
22563  
22564 # Otherwise, retrieve the argument (if any) stored by $self->parse
22565 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22566  
22567 # Evaluate the expression, if specified
22568 if (defined $timeoutExp) {
22569  
22570 $timeout = $timeoutExp->evaluate();
22571  
22572 if (! ($timeout =~ /^\d+$/)) {
22573  
22574 return $self->scriptObj->setError(
22575 'invalid_integer',
22576 $self->_objClass . '->implement',
22577 );
22578  
22579 } elsif ($timeout < 1) {
22580  
22581 return $self->scriptObj->setError(
22582 'number_NUM_out_of_range',
22583 $self->_objClass . '->implement',
22584 'NUM', $timeout,
22585 );
22586 }
22587 }
22588  
22589 # Inform the parent task that it should start waiting
22590 $self->scriptObj->parentTask->setUpMonitoring(
22591 'status',
22592 'dead',
22593 undef,
22594 $timeout,
22595 );
22596  
22597 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22598 $self->scriptObj->set_scriptStatus('wait_status');
22599  
22600 # Implementation complete
22601 return 1;
22602 }
22603 }
22604  
22605 { package Language::Axbasic::Statement::waitep;
22606  
22607 use strict;
22608 use warnings;
22609 # use diagnostics;
22610  
22611 use Glib qw(TRUE FALSE);
22612  
22613 @Language::Axbasic::Statement::waitep::ISA = qw(
22614 Language::Axbasic
22615 Language::Axbasic::Statement
22616 );
22617  
22618 # WAITEP expression [ , expression ]
22619  
22620 ##################
22621 # Methods
22622  
22623 sub parse {
22624  
22625 # Called by LA::Line->parse directly after a call to LA::Statement->new
22626 #
22627 # Expected arguments
22628 # (none besides $self)
22629 #
22630 # Return values
22631 # 'undef' on improper arguments or if there is an error
22632 # 1 otherwise
22633  
22634 my ($self, $check) = @_;
22635  
22636 # Local variables
22637 my ($valueExp, $timeoutExp);
22638  
22639 # Check for improper arguments
22640 if (defined $check) {
22641  
22642 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22643 }
22644  
22645 # Convert the value string into an expression
22646 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
22647 $self->scriptObj,
22648 $self->tokenGroupObj,
22649 );
22650  
22651 if (! defined $valueExp) {
22652  
22653 return $self->scriptObj->setError(
22654 'missing_or_illegal_expression',
22655 $self->_objClass . '->parse',
22656 );
22657 }
22658  
22659 # Get the timeout, if specified, and convert it into an expression
22660 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22661  
22662 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22663 $self->scriptObj,
22664 $self->tokenGroupObj,
22665 );
22666  
22667 if (! defined $timeoutExp) {
22668  
22669 return $self->scriptObj->setError(
22670 'missing_or_illegal_expression',
22671 $self->_objClass . '->parse',
22672 );
22673 }
22674 }
22675  
22676 # Check that nothing follows the expression(s)
22677 if (! $self->tokenGroupObj->testStatementEnd()) {
22678  
22679 return $self->scriptObj->setError(
22680 'unexpected_keywords,_operators_or_expressions',
22681 $self->_objClass . '->parse',
22682 );
22683 }
22684  
22685 # Store the expression(s), so $self->implement can retrieve them
22686 $self->ivAdd('parseDataHash', 'value', $valueExp);
22687 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22688  
22689 # Parsing complete
22690 return 1;
22691 }
22692  
22693 sub implement {
22694  
22695 # Called by LA::Line->implement directly after a call to $self->parse
22696 #
22697 # Expected arguments
22698 # (none besides $self)
22699 #
22700 # Return values
22701 # 'undef' on improper arguments or if there is an error
22702 # 1 otherwise
22703  
22704 my ($self, $check) = @_;
22705  
22706 # Local variables
22707 my ($valueExp, $value, $timeoutExp, $timeout);
22708  
22709 # Check for improper arguments
22710 if (defined $check) {
22711  
22712 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22713 }
22714  
22715 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22716 if (! $self->scriptObj->parentTask) {
22717  
22718 # Implementation complete. Execution resumes from the next statement
22719 return 1;
22720 }
22721  
22722 # Otherwise, retrieve the argument(s) stored by $self->parse
22723 $valueExp = $self->ivShow('parseDataHash', 'value');
22724 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22725  
22726 # Evaluate the expression(s)
22727 $value = $valueExp->evaluate();
22728 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
22729  
22730 # An illegitimate percentage, use the default value instead
22731 $value = 100;
22732 }
22733  
22734 if (defined $timeoutExp) {
22735  
22736 $timeout = $timeoutExp->evaluate();
22737  
22738 if (! ($timeout =~ /^\d+$/)) {
22739  
22740 return $self->scriptObj->setError(
22741 'invalid_integer',
22742 $self->_objClass . '->implement',
22743 );
22744  
22745 } elsif ($timeout < 1) {
22746  
22747 return $self->scriptObj->setError(
22748 'number_NUM_out_of_range',
22749 $self->_objClass . '->implement',
22750 'NUM', $timeout,
22751 );
22752 }
22753 }
22754  
22755 # Inform the parent task that it should start waiting
22756 $self->scriptObj->parentTask->setUpMonitoring(
22757 'status',
22758 'ep',
22759 $value,
22760 $timeout,
22761 );
22762  
22763 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22764 $self->scriptObj->set_scriptStatus('wait_status');
22765  
22766 # Implementation complete
22767 return 1;
22768 }
22769 }
22770  
22771 { package Language::Axbasic::Statement::waitgp;
22772  
22773 use strict;
22774 use warnings;
22775 # use diagnostics;
22776  
22777 use Glib qw(TRUE FALSE);
22778  
22779 @Language::Axbasic::Statement::waitgp::ISA = qw(
22780 Language::Axbasic
22781 Language::Axbasic::Statement
22782 );
22783  
22784 # WAITGP expression [ , expression ]
22785  
22786 ##################
22787 # Methods
22788  
22789 sub parse {
22790  
22791 # Called by LA::Line->parse directly after a call to LA::Statement->new
22792 #
22793 # Expected arguments
22794 # (none besides $self)
22795 #
22796 # Return values
22797 # 'undef' on improper arguments or if there is an error
22798 # 1 otherwise
22799  
22800 my ($self, $check) = @_;
22801  
22802 # Local variables
22803 my ($valueExp, $timeoutExp);
22804  
22805 # Check for improper arguments
22806 if (defined $check) {
22807  
22808 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22809 }
22810  
22811 # Convert the value string into an expression
22812 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
22813 $self->scriptObj,
22814 $self->tokenGroupObj,
22815 );
22816  
22817 if (! defined $valueExp) {
22818  
22819 return $self->scriptObj->setError(
22820 'missing_or_illegal_expression',
22821 $self->_objClass . '->parse',
22822 );
22823 }
22824  
22825 # Get the timeout, if specified, and convert it into an expression
22826 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
22827  
22828 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
22829 $self->scriptObj,
22830 $self->tokenGroupObj,
22831 );
22832  
22833 if (! defined $timeoutExp) {
22834  
22835 return $self->scriptObj->setError(
22836 'missing_or_illegal_expression',
22837 $self->_objClass . '->parse',
22838 );
22839 }
22840 }
22841  
22842 # Check that nothing follows the expression(s)
22843 if (! $self->tokenGroupObj->testStatementEnd()) {
22844  
22845 return $self->scriptObj->setError(
22846 'unexpected_keywords,_operators_or_expressions',
22847 $self->_objClass . '->parse',
22848 );
22849 }
22850  
22851 # Store the expression(s), so $self->implement can retrieve them
22852 $self->ivAdd('parseDataHash', 'value', $valueExp);
22853 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
22854  
22855 # Parsing complete
22856 return 1;
22857 }
22858  
22859 sub implement {
22860  
22861 # Called by LA::Line->implement directly after a call to $self->parse
22862 #
22863 # Expected arguments
22864 # (none besides $self)
22865 #
22866 # Return values
22867 # 'undef' on improper arguments or if there is an error
22868 # 1 otherwise
22869  
22870 my ($self, $check) = @_;
22871  
22872 # Local variables
22873 my ($valueExp, $value, $timeoutExp, $timeout);
22874  
22875 # Check for improper arguments
22876 if (defined $check) {
22877  
22878 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
22879 }
22880  
22881 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
22882 if (! $self->scriptObj->parentTask) {
22883  
22884 # Implementation complete. Execution resumes from the next statement
22885 return 1;
22886 }
22887  
22888 # Otherwise, retrieve the argument(s) stored by $self->parse
22889 $valueExp = $self->ivShow('parseDataHash', 'value');
22890 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
22891  
22892 # Evaluate the expression(s)
22893 $value = $valueExp->evaluate();
22894 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
22895  
22896 # An illegitimate percentage, use the default value instead
22897 $value = 100;
22898 }
22899  
22900 if (defined $timeoutExp) {
22901  
22902 $timeout = $timeoutExp->evaluate();
22903  
22904 if (! ($timeout =~ /^\d+$/)) {
22905  
22906 return $self->scriptObj->setError(
22907 'invalid_integer',
22908 $self->_objClass . '->implement',
22909 );
22910  
22911 } elsif ($timeout < 1) {
22912  
22913 return $self->scriptObj->setError(
22914 'number_NUM_out_of_range',
22915 $self->_objClass . '->implement',
22916 'NUM', $timeout,
22917 );
22918 }
22919 }
22920  
22921 # Inform the parent task that it should start waiting
22922 $self->scriptObj->parentTask->setUpMonitoring(
22923 'status',
22924 'gp',
22925 $value,
22926 $timeout,
22927 );
22928  
22929 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
22930 $self->scriptObj->set_scriptStatus('wait_status');
22931  
22932 # Implementation complete
22933 return 1;
22934 }
22935 }
22936  
22937 { package Language::Axbasic::Statement::waithook;
22938  
22939 use strict;
22940 use warnings;
22941 # use diagnostics;
22942  
22943 use Glib qw(TRUE FALSE);
22944  
22945 @Language::Axbasic::Statement::waithook::ISA = qw(
22946 Language::Axbasic
22947 Language::Axbasic::Statement
22948 );
22949  
22950 # WAITHOOK expression [ , expression ]
22951  
22952 ##################
22953 # Methods
22954  
22955 sub parse {
22956  
22957 # Called by LA::Line->parse directly after a call to LA::Statement->new
22958 #
22959 # Expected arguments
22960 # (none besides $self)
22961 #
22962 # Return values
22963 # 'undef' on improper arguments or if there is an error
22964 # 1 otherwise
22965  
22966 my ($self, $check) = @_;
22967  
22968 # Check for improper arguments
22969 if (defined $check) {
22970  
22971 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
22972 }
22973  
22974 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
22975 # ready for $self->implement to access
22976 if (! $self->parseWaitInterface()) {
22977  
22978 # ($self->scriptObj->setError has already been called)
22979 return undef;
22980 }
22981  
22982 # Parsing complete
22983 return 1;
22984 }
22985  
22986 sub implement {
22987  
22988 # Called by LA::Line->implement directly after a call to $self->parse
22989 #
22990 # Expected arguments
22991 # (none besides $self)
22992 #
22993 # Return values
22994 # 'undef' on improper arguments or if there is an error
22995 # 1 otherwise
22996  
22997 my ($self, $check) = @_;
22998  
22999 # Check for improper arguments
23000 if (defined $check) {
23001  
23002 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23003 }
23004  
23005 # Implement the statement, haveing parsed it
23006 if (! $self->implementWaitInterface('hook')) {
23007  
23008 # ($self->scriptObj->setError has already been called)
23009 return undef;
23010 }
23011  
23012 # Implementation complete
23013 return 1;
23014 }
23015 }
23016  
23017 { package Language::Axbasic::Statement::waithp;
23018  
23019 use strict;
23020 use warnings;
23021 # use diagnostics;
23022  
23023 use Glib qw(TRUE FALSE);
23024  
23025 @Language::Axbasic::Statement::waithp::ISA = qw(
23026 Language::Axbasic
23027 Language::Axbasic::Statement
23028 );
23029  
23030 # WAITHP expression [ , expression ]
23031  
23032 ##################
23033 # Methods
23034  
23035 sub parse {
23036  
23037 # Called by LA::Line->parse directly after a call to LA::Statement->new
23038 #
23039 # Expected arguments
23040 # (none besides $self)
23041 #
23042 # Return values
23043 # 'undef' on improper arguments or if there is an error
23044 # 1 otherwise
23045  
23046 my ($self, $check) = @_;
23047  
23048 # Local variables
23049 my ($valueExp, $timeoutExp);
23050  
23051 # Check for improper arguments
23052 if (defined $check) {
23053  
23054 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23055 }
23056  
23057 # Convert the value string into an expression
23058 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
23059 $self->scriptObj,
23060 $self->tokenGroupObj,
23061 );
23062  
23063 if (! defined $valueExp) {
23064  
23065 return $self->scriptObj->setError(
23066 'missing_or_illegal_expression',
23067 $self->_objClass . '->parse',
23068 );
23069 }
23070  
23071 # Get the timeout, if specified, and convert it into an expression
23072 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23073  
23074 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23075 $self->scriptObj,
23076 $self->tokenGroupObj,
23077 );
23078  
23079 if (! defined $timeoutExp) {
23080  
23081 return $self->scriptObj->setError(
23082 'missing_or_illegal_expression',
23083 $self->_objClass . '->parse',
23084 );
23085 }
23086 }
23087  
23088 # Check that nothing follows the expression(s)
23089 if (! $self->tokenGroupObj->testStatementEnd()) {
23090  
23091 return $self->scriptObj->setError(
23092 'unexpected_keywords,_operators_or_expressions',
23093 $self->_objClass . '->parse',
23094 );
23095 }
23096  
23097 # Store the expression(s), so $self->implement can retrieve them
23098 $self->ivAdd('parseDataHash', 'value', $valueExp);
23099 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23100  
23101 # Parsing complete
23102 return 1;
23103 }
23104  
23105 sub implement {
23106  
23107 # Called by LA::Line->implement directly after a call to $self->parse
23108 #
23109 # Expected arguments
23110 # (none besides $self)
23111 #
23112 # Return values
23113 # 'undef' on improper arguments or if there is an error
23114 # 1 otherwise
23115  
23116 my ($self, $check) = @_;
23117  
23118 # Local variables
23119 my ($valueExp, $value, $timeoutExp, $timeout);
23120  
23121 # Check for improper arguments
23122 if (defined $check) {
23123  
23124 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23125 }
23126  
23127 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23128 if (! $self->scriptObj->parentTask) {
23129  
23130 # Implementation complete. Execution resumes from the next statement
23131 return 1;
23132 }
23133  
23134 # Otherwise, retrieve the argument(s) stored by $self->parse
23135 $valueExp = $self->ivShow('parseDataHash', 'value');
23136 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23137  
23138 # Evaluate the expression(s)
23139 $value = $valueExp->evaluate();
23140 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
23141  
23142 # An illegitimate percentage, use the default value instead
23143 $value = 100;
23144 }
23145  
23146 if (defined $timeoutExp) {
23147  
23148 $timeout = $timeoutExp->evaluate();
23149  
23150 if (! ($timeout =~ /^\d+$/)) {
23151  
23152 return $self->scriptObj->setError(
23153 'invalid_integer',
23154 $self->_objClass . '->implement',
23155 );
23156  
23157 } elsif ($timeout < 1) {
23158  
23159 return $self->scriptObj->setError(
23160 'number_NUM_out_of_range',
23161 $self->_objClass . '->implement',
23162 'NUM', $timeout,
23163 );
23164 }
23165 }
23166  
23167 # Inform the parent task that it should start waiting
23168 $self->scriptObj->parentTask->setUpMonitoring(
23169 'status',
23170 'hp',
23171 $value,
23172 $timeout,
23173 );
23174  
23175 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23176 $self->scriptObj->set_scriptStatus('wait_status');
23177  
23178 # Implementation complete
23179 return 1;
23180 }
23181 }
23182  
23183 { package Language::Axbasic::Statement::waitmacro;
23184  
23185 use strict;
23186 use warnings;
23187 # use diagnostics;
23188  
23189 use Glib qw(TRUE FALSE);
23190  
23191 @Language::Axbasic::Statement::waitmacro::ISA = qw(
23192 Language::Axbasic
23193 Language::Axbasic::Statement
23194 );
23195  
23196 # WAITMACRO expression [ , expression ]
23197  
23198 ##################
23199 # Methods
23200  
23201 sub parse {
23202  
23203 # Called by LA::Line->parse directly after a call to LA::Statement->new
23204 #
23205 # Expected arguments
23206 # (none besides $self)
23207 #
23208 # Return values
23209 # 'undef' on improper arguments or if there is an error
23210 # 1 otherwise
23211  
23212 my ($self, $check) = @_;
23213  
23214 # Check for improper arguments
23215 if (defined $check) {
23216  
23217 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23218 }
23219  
23220 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
23221 # ready for $self->implement to access
23222 if (! $self->parseWaitInterface()) {
23223  
23224 # ($self->scriptObj->setError has already been called)
23225 return undef;
23226 }
23227  
23228 # Parsing complete
23229 return 1;
23230 }
23231  
23232 sub implement {
23233  
23234 # Called by LA::Line->implement directly after a call to $self->parse
23235 #
23236 # Expected arguments
23237 # (none besides $self)
23238 #
23239 # Return values
23240 # 'undef' on improper arguments or if there is an error
23241 # 1 otherwise
23242  
23243 my ($self, $check) = @_;
23244  
23245 # Check for improper arguments
23246 if (defined $check) {
23247  
23248 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23249 }
23250  
23251 # Implement the statement, haveing parsed it
23252 if (! $self->implementWaitInterface('macro')) {
23253  
23254 # ($self->scriptObj->setError has already been called)
23255 return undef;
23256 }
23257  
23258 # Implementation complete
23259 return 1;
23260 }
23261 }
23262  
23263 { package Language::Axbasic::Statement::waitmp;
23264  
23265 use strict;
23266 use warnings;
23267 # use diagnostics;
23268  
23269 use Glib qw(TRUE FALSE);
23270  
23271 @Language::Axbasic::Statement::waitmp::ISA = qw(
23272 Language::Axbasic
23273 Language::Axbasic::Statement
23274 );
23275  
23276 # WAITMP expression [ , expression ]
23277  
23278 ##################
23279 # Methods
23280  
23281 sub parse {
23282  
23283 # Called by LA::Line->parse directly after a call to LA::Statement->new
23284 #
23285 # Expected arguments
23286 # (none besides $self)
23287 #
23288 # Return values
23289 # 'undef' on improper arguments or if there is an error
23290 # 1 otherwise
23291  
23292 my ($self, $check) = @_;
23293  
23294 # Local variables
23295 my ($valueExp, $timeoutExp);
23296  
23297 # Check for improper arguments
23298 if (defined $check) {
23299  
23300 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23301 }
23302  
23303 # Convert the value string into an expression
23304 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
23305 $self->scriptObj,
23306 $self->tokenGroupObj,
23307 );
23308  
23309 if (! defined $valueExp) {
23310  
23311 return $self->scriptObj->setError(
23312 'missing_or_illegal_expression',
23313 $self->_objClass . '->parse',
23314 );
23315 }
23316  
23317 # Get the timeout, if specified, and convert it into an expression
23318 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23319  
23320 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23321 $self->scriptObj,
23322 $self->tokenGroupObj,
23323 );
23324  
23325 if (! defined $timeoutExp) {
23326  
23327 return $self->scriptObj->setError(
23328 'missing_or_illegal_expression',
23329 $self->_objClass . '->parse',
23330 );
23331 }
23332 }
23333  
23334 # Check that nothing follows the expression(s)
23335 if (! $self->tokenGroupObj->testStatementEnd()) {
23336  
23337 return $self->scriptObj->setError(
23338 'unexpected_keywords,_operators_or_expressions',
23339 $self->_objClass . '->parse',
23340 );
23341 }
23342  
23343 # Store the expression(s), so $self->implement can retrieve them
23344 $self->ivAdd('parseDataHash', 'value', $valueExp);
23345 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23346  
23347 # Parsing complete
23348 return 1;
23349 }
23350  
23351 sub implement {
23352  
23353 # Called by LA::Line->implement directly after a call to $self->parse
23354 #
23355 # Expected arguments
23356 # (none besides $self)
23357 #
23358 # Return values
23359 # 'undef' on improper arguments or if there is an error
23360 # 1 otherwise
23361  
23362 my ($self, $check) = @_;
23363  
23364 # Local variables
23365 my ($valueExp, $value, $timeoutExp, $timeout);
23366  
23367 # Check for improper arguments
23368 if (defined $check) {
23369  
23370 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23371 }
23372  
23373 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23374 if (! $self->scriptObj->parentTask) {
23375  
23376 # Implementation complete. Execution resumes from the next statement
23377 return 1;
23378 }
23379  
23380 # Otherwise, retrieve the argument(s) stored by $self->parse
23381 $valueExp = $self->ivShow('parseDataHash', 'value');
23382 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23383  
23384 # Evaluate the expression(s)
23385 $value = $valueExp->evaluate();
23386 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
23387  
23388 # An illegitimate percentage, use the default value instead
23389 $value = 100;
23390 }
23391  
23392 if (defined $timeoutExp) {
23393  
23394 $timeout = $timeoutExp->evaluate();
23395  
23396 if (! ($timeout =~ /^\d+$/)) {
23397  
23398 return $self->scriptObj->setError(
23399 'invalid_integer',
23400 $self->_objClass . '->implement',
23401 );
23402  
23403 } elsif ($timeout < 1) {
23404  
23405 return $self->scriptObj->setError(
23406 'number_NUM_out_of_range',
23407 $self->_objClass . '->implement',
23408 'NUM', $timeout,
23409 );
23410 }
23411 }
23412  
23413 # Inform the parent task that it should start waiting
23414 $self->scriptObj->parentTask->setUpMonitoring(
23415 'status',
23416 'mp',
23417 $value,
23418 $timeout,
23419 );
23420  
23421 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23422 $self->scriptObj->set_scriptStatus('wait_status');
23423  
23424 # Implementation complete
23425 return 1;
23426 }
23427 }
23428  
23429 { package Language::Axbasic::Statement::waitnextxp;
23430  
23431 use strict;
23432 use warnings;
23433 # use diagnostics;
23434  
23435 use Glib qw(TRUE FALSE);
23436  
23437 @Language::Axbasic::Statement::waitnextxp::ISA = qw(
23438 Language::Axbasic
23439 Language::Axbasic::Statement
23440 );
23441  
23442 # WAITNEXTXP expression [ , expression ]
23443  
23444 ##################
23445 # Methods
23446  
23447 sub parse {
23448  
23449 # Called by LA::Line->parse directly after a call to LA::Statement->new
23450 #
23451 # Expected arguments
23452 # (none besides $self)
23453 #
23454 # Return values
23455 # 'undef' on improper arguments or if there is an error
23456 # 1 otherwise
23457  
23458 my ($self, $check) = @_;
23459  
23460 # Local variables
23461 my ($valueExp, $timeoutExp);
23462  
23463 # Check for improper arguments
23464 if (defined $check) {
23465  
23466 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23467 }
23468  
23469 # Convert the value string into an expression
23470 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
23471 $self->scriptObj,
23472 $self->tokenGroupObj,
23473 );
23474  
23475 if (! defined $valueExp) {
23476  
23477 return $self->scriptObj->setError(
23478 'missing_or_illegal_expression',
23479 $self->_objClass . '->parse',
23480 );
23481 }
23482  
23483 # Get the timeout, if specified, and convert it into an expression
23484 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23485  
23486 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23487 $self->scriptObj,
23488 $self->tokenGroupObj,
23489 );
23490  
23491 if (! defined $timeoutExp) {
23492  
23493 return $self->scriptObj->setError(
23494 'missing_or_illegal_expression',
23495 $self->_objClass . '->parse',
23496 );
23497 }
23498 }
23499  
23500 # Check that nothing follows the expression(s)
23501 if (! $self->tokenGroupObj->testStatementEnd()) {
23502  
23503 return $self->scriptObj->setError(
23504 'unexpected_keywords,_operators_or_expressions',
23505 $self->_objClass . '->parse',
23506 );
23507 }
23508  
23509 # Store the expression(s), so $self->implement can retrieve them
23510 $self->ivAdd('parseDataHash', 'value', $valueExp);
23511 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23512  
23513 # Parsing complete
23514 return 1;
23515 }
23516  
23517 sub implement {
23518  
23519 # Called by LA::Line->implement directly after a call to $self->parse
23520 #
23521 # Expected arguments
23522 # (none besides $self)
23523 #
23524 # Return values
23525 # 'undef' on improper arguments or if there is an error
23526 # 1 otherwise
23527  
23528 my ($self, $check) = @_;
23529  
23530 # Local variables
23531 my ($valueExp, $value, $timeoutExp, $timeout);
23532  
23533 # Check for improper arguments
23534 if (defined $check) {
23535  
23536 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23537 }
23538  
23539 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23540 if (! $self->scriptObj->parentTask) {
23541  
23542 # Implementation complete. Execution resumes from the next statement
23543 return 1;
23544 }
23545  
23546 # Otherwise, retrieve the argument(s) stored by $self->parse
23547 $valueExp = $self->ivShow('parseDataHash', 'value');
23548 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23549  
23550 # Evaluate the expression(s)
23551 $value = $valueExp->evaluate();
23552 if (! ($value =~ /^\d+$/)) {
23553  
23554 return $self->scriptObj->setError(
23555 'invalid_integer',
23556 $self->_objClass . '->parse',
23557 );
23558 }
23559  
23560 if (defined $timeoutExp) {
23561  
23562 $timeout = $timeoutExp->evaluate();
23563  
23564 if (! ($timeout =~ /^\d+$/)) {
23565  
23566 return $self->scriptObj->setError(
23567 'invalid_integer',
23568 $self->_objClass . '->implement',
23569 );
23570  
23571 } elsif ($timeout < 1) {
23572  
23573 return $self->scriptObj->setError(
23574 'number_NUM_out_of_range',
23575 $self->_objClass . '->implement',
23576 'NUM', $timeout,
23577 );
23578 }
23579 }
23580  
23581 # Inform the parent task that it should start waiting
23582 $self->scriptObj->parentTask->setUpMonitoring(
23583 'status',
23584 'xp_next_level',
23585 $value,
23586 $timeout,
23587 );
23588  
23589 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23590 $self->scriptObj->set_scriptStatus('wait_status');
23591  
23592 # Implementation complete
23593 return 1;
23594 }
23595 }
23596  
23597 { package Language::Axbasic::Statement::waitnotactive;
23598  
23599 use strict;
23600 use warnings;
23601 # use diagnostics;
23602  
23603 use Glib qw(TRUE FALSE);
23604  
23605 @Language::Axbasic::Statement::waitnotactive::ISA = qw(
23606 Language::Axbasic
23607 Language::Axbasic::Statement
23608 );
23609  
23610 # WAITNOTACTIVE expression
23611  
23612 ##################
23613 # Methods
23614  
23615 sub parse {
23616  
23617 # Called by LA::Line->parse directly after a call to LA::Statement->new
23618 #
23619 # Expected arguments
23620 # (none besides $self)
23621 #
23622 # Return values
23623 # 'undef' on improper arguments or if there is an error
23624 # 1 otherwise
23625  
23626 my ($self, $check) = @_;
23627  
23628 # Local variables
23629 my $taskNameExp;
23630  
23631 # Check for improper arguments
23632 if (defined $check) {
23633  
23634 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23635 }
23636  
23637 # Convert the task string into an expression
23638 $taskNameExp = Language::Axbasic::Expression::Arithmetic->new(
23639 $self->scriptObj,
23640 $self->tokenGroupObj,
23641 );
23642  
23643 if (! defined $taskNameExp) {
23644  
23645 return $self->scriptObj->setError(
23646 'missing_or_illegal_expression',
23647 $self->_objClass . '->parse',
23648 );
23649 }
23650  
23651 # Check that nothing follows the expression(s)
23652 if (! $self->tokenGroupObj->testStatementEnd()) {
23653  
23654 return $self->scriptObj->setError(
23655 'unexpected_keywords,_operators_or_expressions',
23656 $self->_objClass . '->parse',
23657 );
23658 }
23659  
23660 # Store the expression, so $self->implement can retrieve it
23661 $self->ivAdd('parseDataHash', 'task_name', $taskNameExp);
23662  
23663 # Parsing complete
23664 return 1;
23665 }
23666  
23667 sub implement {
23668  
23669 # Called by LA::Line->implement directly after a call to $self->parse
23670 #
23671 # Expected arguments
23672 # (none besides $self)
23673 #
23674 # Return values
23675 # 'undef' on improper arguments or if there is an error
23676 # 1 otherwise
23677  
23678 my ($self, $check) = @_;
23679  
23680 # Local variables
23681 my ($taskNameExp, $taskName, $taskObj);
23682  
23683 # Check for improper arguments
23684 if (defined $check) {
23685  
23686 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23687 }
23688  
23689 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23690 if (! $self->scriptObj->parentTask) {
23691  
23692 # Implementation complete. Execution resumes from the next statement
23693 return 1;
23694 }
23695  
23696 # Otherwise, retrieve the argument stored by $self->parse
23697 $taskNameExp = $self->ivShow('parseDataHash', 'task_name');
23698  
23699 # Evaluate the expression(s)
23700 $taskName = $taskNameExp->evaluate();
23701  
23702 # Look for a task matching $taskName. GA::Generic::Cmd->findTask recognises task labels
23703 # (stored in GA::Client->taskLabelHash), tasks' formal names (stored in
23704 # GA::Client->taskPackageHash), or task unique names in the current tasklist (stored in
23705 # GA::Session->currentTaskHash)
23706 ($taskObj) = Games::Axmud::Generic::Cmd->findTask($self->scriptObj->session, $taskName);
23707 if (! $taskObj) {
23708  
23709 # No matching task in the current tasklist
23710 return $self->scriptObj->setError(
23711 'WAITACTIVE_operation_failure',
23712 $self->_objClass . '->parse',
23713 );
23714 }
23715  
23716 # Inform the LA::Script's parent task that it should start waiting
23717 $self->scriptObj->parentTask->setUpMonitoring('task_not_active', $taskObj->uniqueName);
23718  
23719 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23720 $self->scriptObj->set_scriptStatus('wait_not_active');
23721  
23722 # Implementation complete
23723 return 1;
23724 }
23725 }
23726  
23727 { package Language::Axbasic::Statement::waitpassout;
23728  
23729 use strict;
23730 use warnings;
23731 # use diagnostics;
23732  
23733 use Glib qw(TRUE FALSE);
23734  
23735 @Language::Axbasic::Statement::waitpassout::ISA = qw(
23736 Language::Axbasic
23737 Language::Axbasic::Statement
23738 );
23739  
23740 # WAITPASSOUT [ expression ]
23741  
23742 ##################
23743 # Methods
23744  
23745 sub parse {
23746  
23747 # Called by LA::Line->parse directly after a call to LA::Statement->new
23748 #
23749 # Expected arguments
23750 # (none besides $self)
23751 #
23752 # Return values
23753 # 'undef' on improper arguments or if there is an error
23754 # 1 otherwise
23755  
23756 my ($self, $check) = @_;
23757  
23758 # Local variables
23759 my $timeoutExp;
23760  
23761 # Check for improper arguments
23762 if (defined $check) {
23763  
23764 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23765 }
23766  
23767 # Get the timeout, if specified, and convert it into an expression
23768 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
23769  
23770 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
23771 $self->scriptObj,
23772 $self->tokenGroupObj,
23773 );
23774  
23775 if (! defined $timeoutExp) {
23776  
23777 return $self->scriptObj->setError(
23778 'missing_or_illegal_expression',
23779 $self->_objClass . '->parse',
23780 );
23781 }
23782 }
23783  
23784 # Check that nothing follows the expression(s)
23785 if (! $self->tokenGroupObj->testStatementEnd()) {
23786  
23787 return $self->scriptObj->setError(
23788 'unexpected_keywords,_operators_or_expressions',
23789 $self->_objClass . '->parse',
23790 );
23791 }
23792  
23793 # Store the expression (if specified), so $self->implement can retrieve it
23794 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
23795  
23796 # Parsing complete
23797 return 1;
23798 }
23799  
23800 sub implement {
23801  
23802 # Called by LA::Line->implement directly after a call to $self->parse
23803 #
23804 # Expected arguments
23805 # (none besides $self)
23806 #
23807 # Return values
23808 # 'undef' on improper arguments or if there is an error
23809 # 1 otherwise
23810  
23811 my ($self, $check) = @_;
23812  
23813 # Local variables
23814 my ($timeoutExp, $timeout);
23815  
23816 # Check for improper arguments
23817 if (defined $check) {
23818  
23819 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23820 }
23821  
23822 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
23823 if (! $self->scriptObj->parentTask) {
23824  
23825 # Implementation complete. Execution resumes from the next statement
23826 return 1;
23827 }
23828  
23829 # Otherwise, retrieve the argument (if any) stored by $self->parse
23830 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
23831  
23832 # Evaluate the expression, if specified
23833 if (defined $timeoutExp) {
23834  
23835 $timeout = $timeoutExp->evaluate();
23836  
23837 if (! ($timeout =~ /^\d+$/)) {
23838  
23839 return $self->scriptObj->setError(
23840 'invalid_integer',
23841 $self->_objClass . '->implement',
23842 );
23843  
23844 } elsif ($timeout < 1) {
23845  
23846 return $self->scriptObj->setError(
23847 'number_NUM_out_of_range',
23848 $self->_objClass . '->implement',
23849 'NUM', $timeout,
23850 );
23851 }
23852 }
23853  
23854 # Inform the parent task that it should start waiting
23855 $self->scriptObj->parentTask->setUpMonitoring(
23856 'status',
23857 'passout',
23858 undef,
23859 $timeout,
23860 );
23861  
23862 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23863 $self->scriptObj->set_scriptStatus('wait_status');
23864  
23865 # Implementation complete
23866 return 1;
23867 }
23868 }
23869  
23870 { package Language::Axbasic::Statement::waitscript;
23871  
23872 use strict;
23873 use warnings;
23874 # use diagnostics;
23875  
23876 use Glib qw(TRUE FALSE);
23877  
23878 @Language::Axbasic::Statement::waitscript::ISA = qw(
23879 Language::Axbasic
23880 Language::Axbasic::Statement
23881 );
23882  
23883 # WAITSCRIPT expression
23884  
23885 ##################
23886 # Methods
23887  
23888 sub parse {
23889  
23890 # Called by LA::Line->parse directly after a call to LA::Statement->new
23891 #
23892 # Expected arguments
23893 # (none besides $self)
23894 #
23895 # Return values
23896 # 'undef' on improper arguments or if there is an error
23897 # 1 otherwise
23898  
23899 my ($self, $check) = @_;
23900  
23901 # Local variables
23902 my $scriptNameExp;
23903  
23904 # Check for improper arguments
23905 if (defined $check) {
23906  
23907 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
23908 }
23909  
23910 # Convert the task string into an expression
23911 $scriptNameExp = Language::Axbasic::Expression::Arithmetic->new(
23912 $self->scriptObj,
23913 $self->tokenGroupObj,
23914 );
23915  
23916 if (! defined $scriptNameExp) {
23917  
23918 return $self->scriptObj->setError(
23919 'missing_or_illegal_expression ',
23920 $self->_objClass . '->parse',
23921 );
23922 }
23923  
23924 # Check that nothing follows the expression(s)
23925 if (! $self->tokenGroupObj->testStatementEnd()) {
23926  
23927 return $self->scriptObj->setError(
23928 'unexpected_keywords,_operators_or_expressions',
23929 $self->_objClass . '->parse',
23930 );
23931 }
23932  
23933 # Store the expression, so $self->implement can retrieve it
23934 $self->ivAdd('parseDataHash', 'script_exp', $scriptNameExp);
23935  
23936 # Parsing complete
23937 return 1;
23938 }
23939  
23940 sub implement {
23941  
23942 # Called by LA::Line->implement directly after a call to $self->parse
23943 #
23944 # Expected arguments
23945 # (none besides $self)
23946 #
23947 # Return values
23948 # 'undef' on improper arguments or if there is an error
23949 # 1 otherwise
23950  
23951 my ($self, $check) = @_;
23952  
23953 # Local variables
23954 my ($scriptNameExp, $scriptName, $packageName, $taskObj);
23955  
23956 # Check for improper arguments
23957 if (defined $check) {
23958  
23959 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
23960 }
23961  
23962 # If this Axbasic script isn't being run from within an Axmud task, ignore the statement
23963 if (! $self->scriptObj->parentTask) {
23964  
23965 # Implementation complete. Execution resumes from the next statement
23966 return 1;
23967 }
23968  
23969 # Otherwise, retrieve the argument stored by $self->parse
23970 $scriptNameExp = $self->ivShow('parseDataHash', 'script_exp');
23971 # Evaluate the expression(s)
23972 $scriptName = $scriptNameExp->evaluate();
23973  
23974 # Create the new Script task object
23975 $taskObj = Games::Axmud::Task::Script->new($self->scriptObj->session, 'current');
23976 if (! $taskObj) {
23977  
23978 # If the new task can't be created, it's a fatal error
23979 return $self->scriptObj->setError(
23980 'WAITSCRIPT_operation_failure',
23981 $self->_objClass . '->parse',
23982 );
23983 }
23984  
23985 # Tell the new task which Axbasic script to run
23986 $taskObj->ivPoke('scriptName', $scriptName);
23987  
23988 # Inform the LA::Script's parent task that it should start waiting
23989 $self->scriptObj->parentTask->setUpMonitoring('task', $taskObj->uniqueName);
23990  
23991 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
23992 $self->scriptObj->set_scriptStatus('wait_status');
23993  
23994 # Implementation complete
23995 return 1;
23996 }
23997 }
23998  
23999 { package Language::Axbasic::Statement::waitsleep;
24000  
24001 use strict;
24002 use warnings;
24003 # use diagnostics;
24004  
24005 use Glib qw(TRUE FALSE);
24006  
24007 @Language::Axbasic::Statement::waitsleep::ISA = qw(
24008 Language::Axbasic
24009 Language::Axbasic::Statement
24010 );
24011  
24012 # WAITSLEEP [ expression ]
24013  
24014 ##################
24015 # Methods
24016  
24017 sub parse {
24018  
24019 # Called by LA::Line->parse directly after a call to LA::Statement->new
24020 #
24021 # Expected arguments
24022 # (none besides $self)
24023 #
24024 # Return values
24025 # 'undef' on improper arguments or if there is an error
24026 # 1 otherwise
24027  
24028 my ($self, $check) = @_;
24029  
24030 # Local variables
24031 my $timeoutExp;
24032  
24033 # Check for improper arguments
24034 if (defined $check) {
24035  
24036 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24037 }
24038  
24039 # Get the timeout, if specified, and convert it into an expression
24040 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24041  
24042 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24043 $self->scriptObj,
24044 $self->tokenGroupObj,
24045 );
24046  
24047 if (! defined $timeoutExp) {
24048  
24049 return $self->scriptObj->setError(
24050 'missing_or_illegal_expression',
24051 $self->_objClass . '->parse',
24052 );
24053 }
24054 }
24055  
24056 # Check that nothing follows the expression(s)
24057 if (! $self->tokenGroupObj->testStatementEnd()) {
24058  
24059 return $self->scriptObj->setError(
24060 'unexpected_keywords,_operators_or_expressions',
24061 $self->_objClass . '->parse',
24062 );
24063 }
24064  
24065 # Store the expression (if specified), so $self->implement can retrieve it
24066 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24067  
24068 # Parsing complete
24069 return 1;
24070 }
24071  
24072 sub implement {
24073  
24074 # Called by LA::Line->implement directly after a call to $self->parse
24075 #
24076 # Expected arguments
24077 # (none besides $self)
24078 #
24079 # Return values
24080 # 'undef' on improper arguments or if there is an error
24081 # 1 otherwise
24082  
24083 my ($self, $check) = @_;
24084  
24085 # Local variables
24086 my ($timeoutExp, $timeout);
24087  
24088 # Check for improper arguments
24089 if (defined $check) {
24090  
24091 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24092 }
24093  
24094 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24095 if (! $self->scriptObj->parentTask) {
24096  
24097 # Implementation complete. Execution resumes from the next statement
24098 return 1;
24099 }
24100  
24101 # Otherwise, retrieve the argument (if any) stored by $self->parse
24102 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24103  
24104 # Evaluate the expression, if specified
24105 if (defined $timeoutExp) {
24106  
24107 $timeout = $timeoutExp->evaluate();
24108  
24109 if (! ($timeout =~ /^\d+$/)) {
24110  
24111 return $self->scriptObj->setError(
24112 'invalid_integer',
24113 $self->_objClass . '->implement',
24114 );
24115  
24116 } elsif ($timeout < 1) {
24117  
24118 return $self->scriptObj->setError(
24119 'number_NUM_out_of_range',
24120 $self->_objClass . '->implement',
24121 'NUM', $timeout,
24122 );
24123 }
24124 }
24125  
24126 # Inform the parent task that it should start waiting
24127 $self->scriptObj->parentTask->setUpMonitoring(
24128 'status',
24129 'sleep',
24130 undef,
24131 $timeout,
24132 );
24133  
24134 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24135 $self->scriptObj->set_scriptStatus('wait_status');
24136  
24137 # Implementation complete
24138 return 1;
24139 }
24140 }
24141  
24142 { package Language::Axbasic::Statement::waitsp;
24143  
24144 use strict;
24145 use warnings;
24146 # use diagnostics;
24147  
24148 use Glib qw(TRUE FALSE);
24149  
24150 @Language::Axbasic::Statement::waitsp::ISA = qw(
24151 Language::Axbasic
24152 Language::Axbasic::Statement
24153 );
24154  
24155 # WAITSP expression [ , expression ]
24156  
24157 ##################
24158 # Methods
24159  
24160 sub parse {
24161  
24162 # Called by LA::Line->parse directly after a call to LA::Statement->new
24163 #
24164 # Expected arguments
24165 # (none besides $self)
24166 #
24167 # Return values
24168 # 'undef' on improper arguments or if there is an error
24169 # 1 otherwise
24170  
24171 my ($self, $check) = @_;
24172  
24173 # Local variables
24174 my ($valueExp, $timeoutExp);
24175  
24176 # Check for improper arguments
24177 if (defined $check) {
24178  
24179 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24180 }
24181  
24182 # Convert the value string into an expression
24183 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
24184 $self->scriptObj,
24185 $self->tokenGroupObj,
24186 );
24187  
24188 if (! defined $valueExp) {
24189  
24190 return $self->scriptObj->setError(
24191 'missing_or_illegal_expression',
24192 $self->_objClass . '->parse',
24193 );
24194 }
24195  
24196 # Get the timeout, if specified, and convert it into an expression
24197 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24198  
24199 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24200 $self->scriptObj,
24201 $self->tokenGroupObj,
24202 );
24203  
24204 if (! defined $timeoutExp) {
24205  
24206 return $self->scriptObj->setError(
24207 'missing_or_illegal_expression',
24208 $self->_objClass . '->parse',
24209 );
24210 }
24211 }
24212  
24213 # Check that nothing follows the expression(s)
24214 if (! $self->tokenGroupObj->testStatementEnd()) {
24215  
24216 return $self->scriptObj->setError(
24217 'unexpected_keywords,_operators_or_expressions',
24218 $self->_objClass . '->parse',
24219 );
24220 }
24221  
24222 # Store the expression(s), so $self->implement can retrieve them
24223 $self->ivAdd('parseDataHash', 'value', $valueExp);
24224 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24225  
24226 # Parsing complete
24227 return 1;
24228 }
24229  
24230 sub implement {
24231  
24232 # Called by LA::Line->implement directly after a call to $self->parse
24233 #
24234 # Expected arguments
24235 # (none besides $self)
24236 #
24237 # Return values
24238 # 'undef' on improper arguments or if there is an error
24239 # 1 otherwise
24240  
24241 my ($self, $check) = @_;
24242  
24243 # Local variables
24244 my ($valueExp, $value, $timeoutExp, $timeout);
24245  
24246 # Check for improper arguments
24247 if (defined $check) {
24248  
24249 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24250 }
24251  
24252 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24253 if (! $self->scriptObj->parentTask) {
24254  
24255 # Implementation complete. Execution resumes from the next statement
24256 return 1;
24257 }
24258  
24259 # Otherwise, retrieve the argument(s) stored by $self->parse
24260 $valueExp = $self->ivShow('parseDataHash', 'value');
24261 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24262  
24263 # Evaluate the expression(s)
24264 $value = $valueExp->evaluate();
24265 if (! ($value =~ /^\d+$/) || $value < 0 || $value > 100) {
24266  
24267 # An illegitimate percentage, use the default value instead
24268 $value = 100;
24269 }
24270  
24271 if (defined $timeoutExp) {
24272  
24273 $timeout = $timeoutExp->evaluate();
24274  
24275 if (! ($timeout =~ /^\d+$/)) {
24276  
24277 return $self->scriptObj->setError(
24278 'invalid_integer',
24279 $self->_objClass . '->implement',
24280 );
24281  
24282 } elsif ($timeout < 1) {
24283  
24284 return $self->scriptObj->setError(
24285 'number_NUM_out_of_range',
24286 $self->_objClass . '->implement',
24287 'NUM', $timeout,
24288 );
24289 }
24290 }
24291  
24292 # Inform the parent task that it should start waiting
24293 $self->scriptObj->parentTask->setUpMonitoring(
24294 'status',
24295 'sp',
24296 $value,
24297 $timeout,
24298 );
24299  
24300 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24301 $self->scriptObj->set_scriptStatus('wait_status');
24302  
24303 # Implementation complete
24304 return 1;
24305 }
24306 }
24307  
24308 { package Language::Axbasic::Statement::waittask;
24309  
24310 use strict;
24311 use warnings;
24312 # use diagnostics;
24313  
24314 use Glib qw(TRUE FALSE);
24315  
24316 @Language::Axbasic::Statement::waittask::ISA = qw(
24317 Language::Axbasic
24318 Language::Axbasic::Statement
24319 );
24320  
24321 # WAITTASK expression
24322  
24323 ##################
24324 # Methods
24325  
24326 sub parse {
24327  
24328 # Called by LA::Line->parse directly after a call to LA::Statement->new
24329 #
24330 # Expected arguments
24331 # (none besides $self)
24332 #
24333 # Return values
24334 # 'undef' on improper arguments or if there is an error
24335 # 1 otherwise
24336  
24337 my ($self, $check) = @_;
24338  
24339 # Local variables
24340 my $taskNameExp;
24341  
24342 # Check for improper arguments
24343 if (defined $check) {
24344  
24345 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24346 }
24347  
24348 # Convert the task string into an expression
24349 $taskNameExp = Language::Axbasic::Expression::Arithmetic->new(
24350 $self->scriptObj,
24351 $self->tokenGroupObj,
24352 );
24353  
24354 if (! defined $taskNameExp) {
24355  
24356 return $self->scriptObj->setError(
24357 'missing_or_illegal_expression',
24358 $self->_objClass . '->parse',
24359 );
24360 }
24361  
24362 # Check that nothing follows the expression(s)
24363 if (! $self->tokenGroupObj->testStatementEnd()) {
24364  
24365 return $self->scriptObj->setError(
24366 'unexpected_keywords,_operators_or_expressions',
24367 $self->_objClass . '->parse',
24368 );
24369 }
24370  
24371 # Store the expression, so $self->implement can retrieve it
24372 $self->ivAdd('parseDataHash', 'task_name', $taskNameExp);
24373  
24374 # Parsing complete
24375 return 1;
24376 }
24377  
24378 sub implement {
24379  
24380 # Called by LA::Line->implement directly after a call to $self->parse
24381 #
24382 # Expected arguments
24383 # (none besides $self)
24384 #
24385 # Return values
24386 # 'undef' on improper arguments or if there is an error
24387 # 1 otherwise
24388  
24389 my ($self, $check) = @_;
24390  
24391 # Local variables
24392 my ($taskNameExp, $taskName, $packageName, $taskObj);
24393  
24394 # Check for improper arguments
24395 if (defined $check) {
24396  
24397 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24398 }
24399  
24400 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24401 if (! $self->scriptObj->parentTask) {
24402  
24403 # Implementation complete. Execution resumes from the next statement
24404 return 1;
24405 }
24406  
24407 # Otherwise, retrieve the argument stored by $self->parse
24408 $taskNameExp = $self->ivShow('parseDataHash', 'task_name');
24409  
24410 # Evaluate the expression(s)
24411 $taskName = $taskNameExp->evaluate();
24412  
24413 # The rest of this code is adapted from GA::Cmd::StartTask
24414 # GA::Generic::Cmd->findTaskPackageName recognises unique names of currently running tasks
24415 # (e.g. 'status_task_57'), so before we consult it, check that a task called $taskName
24416 # isn't already running
24417 if ($self->scriptObj->session->ivExists('currentTaskHash', $taskName)) {
24418  
24419 return $self->scriptObj->setError(
24420 'WAITTASK_operation_failure',
24421 $self->_objClass . '->parse',
24422 );
24423 }
24424  
24425 # Get the package name corresponding to $taskName (e.g. 'Games::Axmud::Task::Status',
24426 # 'Games::Axmud::Task::Divert')
24427 $packageName
24428 = Games::Axmud::Generic::Cmd->findTaskPackageName($self->scriptObj->session, $taskName);
24429  
24430 if (! defined $packageName) {
24431  
24432 return $self->scriptObj->setError(
24433 'WAITTASK_operation_failure',
24434 $self->_objClass . '->parse',
24435 );
24436 }
24437  
24438 # Create the new task object
24439 $taskObj = $packageName->new($self->scriptObj->session, 'current');
24440 if (! $taskObj) {
24441  
24442 # If the new task can't be created and set up properly, it's a fatal error
24443 return $self->scriptObj->setError(
24444 'WAITTASK_operation_failure',
24445 $self->_objClass . '->parse',
24446 'STRING', $taskName,
24447 );
24448 }
24449  
24450 # Inform the LA::Script's parent task that it should start waiting
24451 $self->scriptObj->parentTask->setUpMonitoring('task', $taskObj->uniqueName);
24452  
24453 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24454 $self->scriptObj->set_scriptStatus('wait_status');
24455  
24456 # Implementation complete
24457 return 1;
24458 }
24459 }
24460  
24461 { package Language::Axbasic::Statement::waittimer;
24462  
24463 use strict;
24464 use warnings;
24465 # use diagnostics;
24466  
24467 use Glib qw(TRUE FALSE);
24468  
24469 @Language::Axbasic::Statement::waittimer::ISA = qw(
24470 Language::Axbasic
24471 Language::Axbasic::Statement
24472 );
24473  
24474 # WAITTIMER expression [ , expression ]
24475  
24476 ##################
24477 # Methods
24478  
24479 sub parse {
24480  
24481 # Called by LA::Line->parse directly after a call to LA::Statement->new
24482 #
24483 # Expected arguments
24484 # (none besides $self)
24485 #
24486 # Return values
24487 # 'undef' on improper arguments or if there is an error
24488 # 1 otherwise
24489  
24490 my ($self, $check) = @_;
24491  
24492 # Check for improper arguments
24493 if (defined $check) {
24494  
24495 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24496 }
24497  
24498 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
24499 # ready for $self->implement to access
24500 if (! $self->parseWaitInterface()) {
24501  
24502 # ($self->scriptObj->setError has already been called)
24503 return undef;
24504 }
24505  
24506 # Parsing complete
24507 return 1;
24508 }
24509  
24510 sub implement {
24511  
24512 # Called by LA::Line->implement directly after a call to $self->parse
24513 #
24514 # Expected arguments
24515 # (none besides $self)
24516 #
24517 # Return values
24518 # 'undef' on improper arguments or if there is an error
24519 # 1 otherwise
24520  
24521 my ($self, $check) = @_;
24522  
24523 # Check for improper arguments
24524 if (defined $check) {
24525  
24526 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24527 }
24528  
24529 # Implement the statement, haveing parsed it
24530 if (! $self->implementWaitInterface('timer')) {
24531  
24532 # ($self->scriptObj->setError has already been called)
24533 return undef;
24534 }
24535  
24536 # Implementation complete
24537 return 1;
24538 }
24539 }
24540  
24541 { package Language::Axbasic::Statement::waittotalxp;
24542  
24543 use strict;
24544 use warnings;
24545 # use diagnostics;
24546  
24547 use Glib qw(TRUE FALSE);
24548  
24549 @Language::Axbasic::Statement::waittotalxp::ISA = qw(
24550 Language::Axbasic
24551 Language::Axbasic::Statement
24552 );
24553  
24554 # WAITTOTALXP expression [ , expression ]
24555  
24556 ##################
24557 # Methods
24558  
24559 sub parse {
24560  
24561 # Called by LA::Line->parse directly after a call to LA::Statement->new
24562 #
24563 # Expected arguments
24564 # (none besides $self)
24565 #
24566 # Return values
24567 # 'undef' on improper arguments or if there is an error
24568 # 1 otherwise
24569  
24570 my ($self, $check) = @_;
24571  
24572 # Local variables
24573 my ($valueExp, $timeoutExp);
24574  
24575 # Check for improper arguments
24576 if (defined $check) {
24577  
24578 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24579 }
24580  
24581 # Convert the value string into an expression
24582 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
24583 $self->scriptObj,
24584 $self->tokenGroupObj,
24585 );
24586  
24587 if (! defined $valueExp) {
24588  
24589 return $self->scriptObj->setError(
24590 'missing_or_illegal_expression',
24591 $self->_objClass . '->parse',
24592 );
24593 }
24594  
24595 # Get the timeout, if specified, and convert it into an expression
24596 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24597  
24598 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24599 $self->scriptObj,
24600 $self->tokenGroupObj,
24601 );
24602  
24603 if (! defined $timeoutExp) {
24604  
24605 return $self->scriptObj->setError(
24606 'missing_or_illegal_expression',
24607 $self->_objClass . '->parse',
24608 );
24609 }
24610 }
24611  
24612 # Check that nothing follows the expression(s)
24613 if (! $self->tokenGroupObj->testStatementEnd()) {
24614  
24615 return $self->scriptObj->setError(
24616 'unexpected_keywords,_operators_or_expressions',
24617 $self->_objClass . '->parse',
24618 );
24619 }
24620  
24621 # Store the expression(s), so $self->implement can retrieve them
24622 $self->ivAdd('parseDataHash', 'value', $valueExp);
24623 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24624  
24625 # Parsing complete
24626 return 1;
24627 }
24628  
24629 sub implement {
24630  
24631 # Called by LA::Line->implement directly after a call to $self->parse
24632 #
24633 # Expected arguments
24634 # (none besides $self)
24635 #
24636 # Return values
24637 # 'undef' on improper arguments or if there is an error
24638 # 1 otherwise
24639  
24640 my ($self, $check) = @_;
24641  
24642 # Local variables
24643 my ($valueExp, $value, $timeoutExp, $timeout);
24644  
24645 # Check for improper arguments
24646 if (defined $check) {
24647  
24648 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24649 }
24650  
24651 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24652 if (! $self->scriptObj->parentTask) {
24653  
24654 # Implementation complete. Execution resumes from the next statement
24655 return 1;
24656 }
24657  
24658 # Otherwise, retrieve the argument(s) stored by $self->parse
24659 $valueExp = $self->ivShow('parseDataHash', 'value');
24660 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24661  
24662 # Evaluate the expression(s)
24663 $value = $valueExp->evaluate();
24664 if (! ($value =~ /^\d+$/)) {
24665  
24666 return $self->scriptObj->setError(
24667 'invalid_integer',
24668 $self->_objClass . '->parse',
24669 );
24670 }
24671  
24672 if (defined $timeoutExp) {
24673  
24674 $timeout = $timeoutExp->evaluate();
24675  
24676 if (! ($timeout =~ /^\d+$/)) {
24677  
24678 return $self->scriptObj->setError(
24679 'invalid_integer',
24680 $self->_objClass . '->implement',
24681 );
24682  
24683 } elsif ($timeout < 1) {
24684  
24685 return $self->scriptObj->setError(
24686 'number_NUM_out_of_range',
24687 $self->_objClass . '->implement',
24688 'NUM', $timeout,
24689 );
24690 }
24691 }
24692  
24693 # Inform the parent task that it should start waiting
24694 $self->scriptObj->parentTask->setUpMonitoring(
24695 'status',
24696 'xp_total',
24697 $value,
24698 $timeout,
24699 );
24700  
24701 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24702 $self->scriptObj->set_scriptStatus('wait_status');
24703  
24704 # Implementation complete
24705 return 1;
24706 }
24707 }
24708  
24709 { package Language::Axbasic::Statement::waittrig;
24710  
24711 use strict;
24712 use warnings;
24713 # use diagnostics;
24714  
24715 use Glib qw(TRUE FALSE);
24716  
24717 @Language::Axbasic::Statement::waittrig::ISA = qw(
24718 Language::Axbasic
24719 Language::Axbasic::Statement
24720 );
24721  
24722 # WAITTRIG expression [ , expression ]
24723  
24724 ##################
24725 # Methods
24726  
24727 sub parse {
24728  
24729 # Called by LA::Line->parse directly after a call to LA::Statement->new
24730 #
24731 # Expected arguments
24732 # (none besides $self)
24733 #
24734 # Return values
24735 # 'undef' on improper arguments or if there is an error
24736 # 1 otherwise
24737  
24738 my ($self, $check) = @_;
24739  
24740 # Check for improper arguments
24741 if (defined $check) {
24742  
24743 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24744 }
24745  
24746 # Extract tokens. If the extraction is successful, they are stored in $self->parseDataList,
24747 # ready for $self->implement to access
24748 if (! $self->parseWaitInterface()) {
24749  
24750 # ($self->scriptObj->setError has already been called)
24751 return undef;
24752 }
24753  
24754 # Parsing complete
24755 return 1;
24756 }
24757  
24758 sub implement {
24759  
24760 # Called by LA::Line->implement directly after a call to $self->parse
24761 #
24762 # Expected arguments
24763 # (none besides $self)
24764 #
24765 # Return values
24766 # 'undef' on improper arguments or if there is an error
24767 # 1 otherwise
24768  
24769 my ($self, $check) = @_;
24770  
24771 # Check for improper arguments
24772 if (defined $check) {
24773  
24774 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24775 }
24776  
24777 # Implement the statement, haveing parsed it
24778 if (! $self->implementWaitInterface('trigger')) {
24779  
24780 # ($self->scriptObj->setError has already been called)
24781 return undef;
24782 }
24783  
24784 # Implementation complete
24785 return 1;
24786 }
24787 }
24788  
24789 { package Language::Axbasic::Statement::waitxp;
24790  
24791 use strict;
24792 use warnings;
24793 # use diagnostics;
24794  
24795 use Glib qw(TRUE FALSE);
24796  
24797 @Language::Axbasic::Statement::waitxp::ISA = qw(
24798 Language::Axbasic
24799 Language::Axbasic::Statement
24800 );
24801  
24802 # WAITXP expression [ , expression ]
24803  
24804 ##################
24805 # Methods
24806  
24807 sub parse {
24808  
24809 # Called by LA::Line->parse directly after a call to LA::Statement->new
24810 #
24811 # Expected arguments
24812 # (none besides $self)
24813 #
24814 # Return values
24815 # 'undef' on improper arguments or if there is an error
24816 # 1 otherwise
24817  
24818 my ($self, $check) = @_;
24819  
24820 # Local variables
24821 my ($valueExp, $timeoutExp);
24822  
24823 # Check for improper arguments
24824 if (defined $check) {
24825  
24826 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24827 }
24828  
24829 # Convert the value string into an expression
24830 $valueExp = Language::Axbasic::Expression::Arithmetic->new(
24831 $self->scriptObj,
24832 $self->tokenGroupObj,
24833 );
24834  
24835 if (! defined $valueExp) {
24836  
24837 return $self->scriptObj->setError(
24838 'missing_or_illegal_expression',
24839 $self->_objClass . '->parse',
24840 );
24841 }
24842  
24843 # Get the timeout, if specified, and convert it into an expression
24844 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
24845  
24846 $timeoutExp = Language::Axbasic::Expression::Arithmetic->new(
24847 $self->scriptObj,
24848 $self->tokenGroupObj,
24849 );
24850  
24851 if (! defined $timeoutExp) {
24852  
24853 return $self->scriptObj->setError(
24854 'missing_or_illegal_expression',
24855 $self->_objClass . '->parse',
24856 );
24857 }
24858 }
24859  
24860 # Check that nothing follows the expression(s)
24861 if (! $self->tokenGroupObj->testStatementEnd()) {
24862  
24863 return $self->scriptObj->setError(
24864 'unexpected_keywords,_operators_or_expressions',
24865 $self->_objClass . '->parse',
24866 );
24867 }
24868  
24869 # Store the expression(s), so $self->implement can retrieve them
24870 $self->ivAdd('parseDataHash', 'value', $valueExp);
24871 $self->ivAdd('parseDataHash', 'timeout', $timeoutExp);
24872  
24873 # Parsing complete
24874 return 1;
24875 }
24876  
24877 sub implement {
24878  
24879 # Called by LA::Line->implement directly after a call to $self->parse
24880 #
24881 # Expected arguments
24882 # (none besides $self)
24883 #
24884 # Return values
24885 # 'undef' on improper arguments or if there is an error
24886 # 1 otherwise
24887  
24888 my ($self, $check) = @_;
24889  
24890 # Local variables
24891 my ($valueExp, $value, $timeoutExp, $timeout);
24892  
24893 # Check for improper arguments
24894 if (defined $check) {
24895  
24896 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
24897 }
24898  
24899 # If the Axbasic script isn't being run from within an Axmud task, ignore the statement
24900 if (! $self->scriptObj->parentTask) {
24901  
24902 # Implementation complete. Execution resumes from the next statement
24903 return 1;
24904 }
24905  
24906 # Otherwise, retrieve the argument(s) stored by $self->parse
24907 $valueExp = $self->ivShow('parseDataHash', 'value');
24908 $timeoutExp = $self->ivShow('parseDataHash', 'timeout');
24909  
24910 # Evaluate the expression(s)
24911 $value = $valueExp->evaluate();
24912 if (! ($value =~ /^\d+$/)) {
24913  
24914 return $self->scriptObj->setError(
24915 'invalid_integer',
24916 $self->_objClass . '->parse',
24917 );
24918 }
24919  
24920 if (defined $timeoutExp) {
24921  
24922 $timeout = $timeoutExp->evaluate();
24923  
24924 if (! ($timeout =~ /^\d+$/)) {
24925  
24926 return $self->scriptObj->setError(
24927 'invalid_integer',
24928 $self->_objClass . '->implement',
24929 );
24930  
24931 } elsif ($timeout < 1) {
24932  
24933 return $self->scriptObj->setError(
24934 'number_NUM_out_of_range',
24935 $self->_objClass . '->implement',
24936 'NUM', $timeout,
24937 );
24938 }
24939 }
24940  
24941 # Inform the parent task that it should start waiting
24942 $self->scriptObj->parentTask->setUpMonitoring(
24943 'status',
24944 'xp_current',
24945 $value,
24946 $timeout,
24947 );
24948  
24949 # Halt execution of the Axbasic script to allow control to be passed back to the parent task
24950 $self->scriptObj->set_scriptStatus('wait_status');
24951  
24952 # Implementation complete
24953 return 1;
24954 }
24955 }
24956  
24957 { package Language::Axbasic::Statement::warning;
24958  
24959 use strict;
24960 use warnings;
24961 # use diagnostics;
24962  
24963 use Glib qw(TRUE FALSE);
24964  
24965 @Language::Axbasic::Statement::warning::ISA = qw(
24966 Language::Axbasic
24967 Language::Axbasic::Statement
24968 );
24969  
24970 # WARNING expression
24971  
24972 ##################
24973 # Methods
24974  
24975 sub parse {
24976  
24977 # Called by LA::Line->parse directly after a call to LA::Statement->new
24978 #
24979 # Expected arguments
24980 # (none besides $self)
24981 #
24982 # Return values
24983 # 'undef' on improper arguments or if there is an error
24984 # 1 otherwise
24985  
24986 my ($self, $check) = @_;
24987  
24988 # Local variables
24989 my $expression;
24990  
24991 # Check for improper arguments
24992 if (defined $check) {
24993  
24994 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
24995 }
24996  
24997 # Get the expression and store it for ->implement to use
24998 $expression = Language::Axbasic::Expression::Arithmetic->new(
24999 $self->scriptObj,
25000 $self->tokenGroupObj,
25001 );
25002  
25003 if (! defined $expression) {
25004  
25005 return $self->scriptObj->setError(
25006 'missing_or_illegal_expression',
25007 $self->_objClass . '->parse',
25008 );
25009  
25010 } else {
25011  
25012 $self->ivAdd('parseDataHash', 'expression', $expression);
25013 }
25014  
25015 # There should be nothing after the expression
25016 if (! $self->tokenGroupObj->testStatementEnd()) {
25017  
25018 return $self->scriptObj->setError(
25019 'unexpected_keywords,_operators_or_expressions',
25020 $self->_objClass . '->parse',
25021 );
25022 }
25023  
25024 # Parsing complete
25025 return 1;
25026 }
25027  
25028 sub implement {
25029  
25030 # Called by LA::Line->implement directly after a call to $self->parse
25031 #
25032 # Expected arguments
25033 # (none besides $self)
25034 #
25035 # Return values
25036 # 'undef' on improper arguments or if there is an error
25037 # 1 otherwise
25038  
25039 my ($self, $check) = @_;
25040  
25041 # Local variables
25042 my ($expression, $string);
25043  
25044 # Check for improper arguments
25045 if (defined $check) {
25046  
25047 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25048 }
25049  
25050 # Retrieve the expression to be written
25051 $expression = $self->ivShow('parseDataHash', 'expression');
25052 # Evaluate the expression to get a scalar value
25053 $string = $expression->evaluate();
25054  
25055 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
25056 # the error message appears on a new line
25057 if ($self->scriptObj->column != 0) {
25058  
25059 $self->scriptObj->session->writeText('', 'after');
25060 $self->scriptObj->set_column(0);
25061 }
25062  
25063 # Write the error message to the 'main' window
25064 $self->scriptObj->session->writeWarning($string);
25065  
25066 # Implementation complete
25067 return 1;
25068 }
25069 }
25070  
25071 { package Language::Axbasic::Statement::while;
25072  
25073 use strict;
25074 use warnings;
25075 # use diagnostics;
25076  
25077 use Glib qw(TRUE FALSE);
25078  
25079 @Language::Axbasic::Statement::while::ISA = qw(
25080 Language::Axbasic
25081 Language::Axbasic::Statement
25082 );
25083  
25084 # WHILE condition
25085 # WHILE expression
25086  
25087 ##################
25088 # Methods
25089  
25090 sub parse {
25091  
25092 # Called by LA::Line->parse directly after a call to LA::Statement->new
25093 #
25094 # Expected arguments
25095 # (none besides $self)
25096 #
25097 # Return values
25098 # 'undef' on improper arguments or if there is an error
25099 # 1 otherwise
25100  
25101 my ($self, $check) = @_;
25102  
25103 # Local variables
25104 my ($condition, $subObj);
25105  
25106 # Check for improper arguments
25107 if (defined $check) {
25108  
25109 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
25110 }
25111  
25112 # The 'while' keyword is not available in primitive numbering mode
25113 if ($self->scriptObj->executionMode ne 'no_line_num') {
25114  
25115 return $self->scriptObj->setError(
25116 'statement_not_available_with_line_numbers',
25117 $self->_objClass . '->parse',
25118 );
25119 }
25120  
25121 # Read a conditional expression
25122 $condition = Language::Axbasic::Expression::LogicalOr->new(
25123 $self->scriptObj,
25124 $self->tokenGroupObj,
25125 'maybe_arithmetic',
25126 );
25127  
25128 if (! defined $condition) {
25129  
25130 return $self->scriptObj->setError(
25131 'missing_or_illegal_conditional_expression',
25132 $self->_objClass . '->parse',
25133 );
25134  
25135 } else {
25136  
25137 # Store the condition expression, so $self->implement can retrieve it
25138 $self->ivAdd('parseDataHash', 'condition', $condition);
25139 }
25140  
25141 # Check there's nothing else in the statement after the condition expression
25142 if (! $self->tokenGroupObj->testStatementEnd()) {
25143  
25144 return $self->scriptObj->setError(
25145 'unexpected_keywords,_operators_or_expressions',
25146 $self->_objClass . '->parse',
25147 );
25148 }
25149  
25150 # Add this WHILE statement to the WHILE code block stack for the current subroutine
25151 $subObj = $self->scriptObj->returnCurrentSub();
25152 $subObj->push_whileStackList($self);
25153  
25154 # We don't know what the corresponding LOOP statement is, yet
25155 $self->ivAdd('parseDataHash', 'loop_statement', undef);
25156  
25157 # Parsing complete
25158 return 1;
25159 }
25160  
25161 sub implement {
25162  
25163 # Called by LA::Line->implement directly after a call to $self->parse when the
25164 # first token in the statement is the keyword 'while'
25165 #
25166 # Expected arguments
25167 # (none besides $self)
25168 #
25169 # Return values
25170 # 'undef' on improper arguments or if there is an error
25171 # 1 otherwise
25172  
25173 my ($self, $check) = @_;
25174  
25175 # Local variables
25176 my ($condition, $loopStatement, $subObj);
25177  
25178 # Check for improper arguments
25179 if (defined $check) {
25180  
25181 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25182 }
25183  
25184 # Retrieve the condition expression stored by $self->parse
25185 $condition = $self->ivShow('parseDataHash', 'condition');
25186  
25187 # Check the corresponding 'loop' statement from the current subroutine's WHILE code block
25188 # stack.
25189 if (! $self->ivShow('parseDataHash', 'loop_statement')) {
25190  
25191 return $self->scriptObj->setError(
25192 'WHILE_statement_without_matching_LOOP',
25193 $self->_objClass . '->implement',
25194 );
25195 }
25196  
25197 # Evaluate the condition expression
25198 if (! $condition->evaluate()) {
25199  
25200 # The condition expression is false, so we need to skip to the end of the WHILE..LOOP
25201 # code block
25202 $loopStatement = $self->ivShow('parseDataHash', 'loop_statement');
25203  
25204 if (defined $loopStatement->nextStatement) {
25205  
25206 # LA::Script->nextStatement is currently set to this statement; continue execution
25207 # as if this were the LOOP statement
25208 $self->scriptObj->set_nextStatement($loopStatement);
25209  
25210 } else {
25211  
25212 $self->scriptObj->set_nextStatement(undef);
25213 $self->scriptObj->set_nextLine($loopStatement->lineObj->procLineNum + 1),
25214 }
25215  
25216 } else {
25217  
25218 # Add this WHILE code block to the main code block stack, since we're going to execute
25219 # it now. The corresponding UNTIL statement will remove it.
25220 # NB The main ->blockStackList is used during ->implement for all kinds of code blocks;
25221 # ->whileStackList is used during ->parse for WHILE..LOOP blocks only
25222 $subObj = $self->scriptObj->returnCurrentSub();
25223 $subObj->push_blockStackList($self);
25224 }
25225  
25226 # Implementation complete
25227 return 1;
25228 }
25229 }
25230  
25231 { package Language::Axbasic::Statement::write;
25232  
25233 use strict;
25234 use warnings;
25235 # use diagnostics;
25236  
25237 use Glib qw(TRUE FALSE);
25238  
25239 @Language::Axbasic::Statement::write::ISA = qw(
25240 Language::Axbasic
25241 Language::Axbasic::Statement
25242 );
25243  
25244 # WRITE expression
25245  
25246 ##################
25247 # Methods
25248  
25249 sub parse {
25250  
25251 # Called by LA::Line->parse directly after a call to LA::Statement->new
25252 #
25253 # Expected arguments
25254 # (none besides $self)
25255 #
25256 # Return values
25257 # 'undef' on improper arguments or if there is an error
25258 # 1 otherwise
25259  
25260 my ($self, $check) = @_;
25261  
25262 # Local variables
25263 my $expression;
25264  
25265 # Check for improper arguments
25266 if (defined $check) {
25267  
25268 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
25269 }
25270  
25271 # Get the expression and store it for ->implement to use
25272 $expression = Language::Axbasic::Expression::Arithmetic->new(
25273 $self->scriptObj,
25274 $self->tokenGroupObj,
25275 );
25276  
25277 if (! defined $expression) {
25278  
25279 return $self->scriptObj->setError(
25280 'missing_or_illegal_expression',
25281 $self->_objClass . '->parse',
25282 );
25283  
25284 } else {
25285  
25286 $self->ivAdd('parseDataHash', 'expression', $expression);
25287 }
25288  
25289 # There should be nothing after the expression
25290 if (! $self->tokenGroupObj->testStatementEnd()) {
25291  
25292 return $self->scriptObj->setError(
25293 'unexpected_keywords,_operators_or_expressions',
25294 $self->_objClass . '->parse',
25295 );
25296 }
25297  
25298 # Parsing complete
25299 return 1;
25300 }
25301  
25302 sub implement {
25303  
25304 # Called by LA::Line->implement directly after a call to $self->parse
25305 #
25306 # Expected arguments
25307 # (none besides $self)
25308 #
25309 # Return values
25310 # 'undef' on improper arguments or if there is an error
25311 # 1 otherwise
25312  
25313 my ($self, $check) = @_;
25314  
25315 # Local variables
25316 my ($expression, $string);
25317  
25318 # Check for improper arguments
25319 if (defined $check) {
25320  
25321 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25322 }
25323  
25324 # Retrieve the expression to be written
25325 $expression = $self->ivShow('parseDataHash', 'expression');
25326 # Evaluate the expression to get a scalar value
25327 $string = $expression->evaluate();
25328  
25329 # If the last PRINT statement was followed by a semicolon, we need to reset the column so
25330 # the message appears on a new line
25331 if ($self->scriptObj->column != 0) {
25332  
25333 $self->scriptObj->session->writeText('', 'after');
25334 $self->scriptObj->set_column(0);
25335 }
25336  
25337 # Write the message to the 'main' window
25338 $self->scriptObj->session->writeText('AXBASIC: ' . $string);
25339  
25340 # Implementation complete
25341 return 1;
25342 }
25343 }
25344  
25345 { package Language::Axbasic::Statement::writewin;
25346  
25347 use strict;
25348 use warnings;
25349 # use diagnostics;
25350  
25351 use Glib qw(TRUE FALSE);
25352  
25353 @Language::Axbasic::Statement::writewin::ISA = qw(
25354 Language::Axbasic
25355 Language::Axbasic::Statement
25356 );
25357  
25358 # WRITEWIN expression [ , expression [ , expression ... ] ]
25359  
25360 ##################
25361 # Methods
25362  
25363 sub parse {
25364  
25365 # Called by LA::Line->parse directly after a call to LA::Statement->new
25366 #
25367 # Expected arguments
25368 # (none besides $self)
25369 #
25370 # Return values
25371 # 'undef' on improper arguments or if there is an error
25372 # 1 otherwise
25373  
25374 my ($self, $check) = @_;
25375  
25376 # Local variables
25377 my (
25378 $textExp, $exitFlag,
25379 @otherExpList,
25380 );
25381  
25382 # Check for improper arguments
25383 if (defined $check) {
25384  
25385 return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_);
25386 }
25387  
25388 # Get the text expression
25389 $textExp = Language::Axbasic::Expression::Arithmetic->new(
25390 $self->scriptObj,
25391 $self->tokenGroupObj,
25392 );
25393  
25394 if (! defined $textExp) {
25395  
25396 return $self->scriptObj->setError(
25397 'missing_or_illegal_expression',
25398 $self->_objClass . '->parse',
25399 );
25400 }
25401  
25402 # Get the optional expressions
25403 do {
25404 my ($token, $otherExp);
25405  
25406 if (defined $self->tokenGroupObj->shiftMatchingToken(',')) {
25407  
25408 $token = $self->tokenGroupObj->lookAhead();
25409 if (defined $token) {
25410  
25411 $otherExp = Language::Axbasic::Expression::Arithmetic->new(
25412 $self->scriptObj,
25413 $self->tokenGroupObj,
25414 );
25415  
25416 if (! defined $otherExp) {
25417  
25418 return $self->scriptObj->setError(
25419 'missing_or_illegal_expression',
25420 $self->_objClass . '->parse',
25421 );
25422  
25423 } else {
25424  
25425 push (@otherExpList, $otherExp);
25426 }
25427 }
25428  
25429 } else {
25430  
25431 $exitFlag = TRUE;
25432 }
25433  
25434 } until ($exitFlag);
25435  
25436 # Check that nothing follows the expressions
25437 if (! $self->tokenGroupObj->testStatementEnd()) {
25438  
25439 return $self->scriptObj->setError(
25440 'unexpected_keywords,_operators_or_expressions',
25441 $self->_objClass . '->parse',
25442 );
25443 }
25444  
25445 # Store the expressions, so $self->implement can retrieve them
25446 $self->ivAdd('parseDataHash', 'text_exp', $textExp);
25447 $self->ivPoke('parseDataList', @otherExpList);
25448  
25449 # Parsing complete
25450 return 1;
25451 }
25452  
25453 sub implement {
25454  
25455 # Called by LA::Line->implement directly after a call to $self->parse
25456 #
25457 # Expected arguments
25458 # (none besides $self)
25459 #
25460 # Return values
25461 # 'undef' on improper arguments or if there is an error
25462 # 1 otherwise
25463  
25464 my ($self, $check) = @_;
25465  
25466 # Local variables
25467 my (
25468 $textExp, $text,
25469 @otherExpList, @otherList,
25470 );
25471  
25472 # Check for improper arguments
25473 if (defined $check) {
25474  
25475 return $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_);
25476 }
25477  
25478 # Retrieve the arguments stored by $self->parse
25479 $textExp = $self->ivShow('parseDataHash', 'text_exp');
25480 @otherExpList = $self->parseDataList;
25481  
25482 # Evaluate each expression
25483 $text = $textExp->evaluate();
25484 foreach my $exp (@otherExpList) {
25485  
25486 push (@otherList, $exp->evaluate());
25487 }
25488  
25489 # If the Axbasic script is being run from within an Axmud task and the task window is open,
25490 # write to it. If run from within the task, the task window is closed but we're allowed to
25491 # write to the 'main' window, write to the 'main' window. Otherwise, do nothing
25492 if ($self->scriptObj->parentTask) {
25493  
25494 if ($self->scriptObj->parentTask->taskWinFlag) {
25495  
25496 # Write to the task window
25497 $self->scriptObj->parentTask->insertPrint($text, @otherList);
25498  
25499 } elsif ($self->scriptObj->ivShow('optionStatementHash', 'redirect')) {
25500  
25501 # Write to the 'main' window; ignore the contents of @otherList
25502 $self->scriptObj->session->writeText($text);
25503 }
25504 }
25505  
25506 # Implementation complete
25507 return 1;
25508 }
25509 }
25510  
25511 # Package must return a true value
25512 1