| 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, based on Language::Basic by Amir Karger | ||
| 16 | |||
| 17 | { package Language::Axbasic; | ||
| 18 | |||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | # use diagnostics; | ||
| 22 | |||
| 23 | use Fcntl qw(SEEK_SET SEEK_END); | ||
| 24 | use File::Basename; | ||
| 25 | use Glib qw(TRUE FALSE); | ||
| 26 | use Math::Trig; | ||
| 27 | use POSIX qw(ceil); | ||
| 28 | use Scalar::Util qw(looks_like_number); | ||
| 29 | |||
| 30 | require Exporter; | ||
| 31 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||
| 32 | @ISA = qw(Exporter Games::Axmud); | ||
| 33 | @EXPORT = qw(); | ||
| 34 | |||
| 35 | # Sub-packages | ||
| 36 | { | ||
| 37 | package Language::Axbasic::Script; | ||
| 38 | package Language::Axbasic::RawScript; | ||
| 39 | package Language::Axbasic::Subroutine; | ||
| 40 | package Language::Axbasic::Line; | ||
| 41 | |||
| 42 | package Language::Axbasic::TokenGroup; | ||
| 43 | package Language::Axbasic::Token; | ||
| 44 | |||
| 45 | package Language::Axbasic::Statement; | ||
| 46 | package Language::Axbasic::Expression; | ||
| 47 | package Language::Axbasic::Variable; | ||
| 48 | package Language::Axbasic::Function; | ||
| 49 | |||
| 50 | package Language::Axbasic::String; | ||
| 51 | package Language::Axbasic::Boolean; | ||
| 52 | package Language::Axbasic::Numeric; | ||
| 53 | } | ||
| 54 | |||
| 55 | ################## | ||
| 56 | # Accessors - get | ||
| 57 | |||
| 58 | # There are five standard IVs for every Axmud (and Axbasic) Perl object | ||
| 59 | sub _objName | ||
| 60 | { $_[0]->{_objName} } | ||
| 61 | sub _objClass | ||
| 62 | { $_[0]->{_objClass} } | ||
| 63 | sub _parentFile | ||
| 64 | { $_[0]->{_parentFile} } | ||
| 65 | sub _parentWorld | ||
| 66 | { $_[0]->{_parentWorld} } | ||
| 67 | sub _privFlag | ||
| 68 | { $_[0]->{_privFlag} } | ||
| 69 | } | ||
| 70 | |||
| 71 | { package Language::Axbasic::Error; | ||
| 72 | |||
| 73 | use strict; | ||
| 74 | use warnings; | ||
| 75 | # use diagnostics; | ||
| 76 | |||
| 77 | use Glib qw(TRUE FALSE); | ||
| 78 | |||
| 79 | @Language::Axbasic::Error::ISA = qw( | ||
| 80 | Language::Axbasic | ||
| 81 | ); | ||
| 82 | |||
| 83 | ################## | ||
| 84 | # Constructors | ||
| 85 | |||
| 86 | sub new { | ||
| 87 | |||
| 88 | # Creates a new instance of the Axbasic error object which stores data produced by an | ||
| 89 | # Axbasic error. Called whenever any part of the Axbasic code calls ->setError or | ||
| 90 | # ->setDebug | ||
| 91 | # The details of the error are stored in this object, and this object's blessed reference | ||
| 92 | # can then be added to LA::Script->errorList | ||
| 93 | # | ||
| 94 | # Expected arguments | ||
| 95 | # $scriptObj - Blessed reference to the parent LA::Script | ||
| 96 | # $category - 'error' (calls from ->setError) or 'debug' (calls from ->setDebug) | ||
| 97 | # $errorCode - The error message to display, e.g. 'syntax_error' | ||
| 98 | # $func - A string describing the function that generated the error (e.g. | ||
| 99 | # 'Language::Axbasic::Statement->parse') | ||
| 100 | # | ||
| 101 | # Optional arguments | ||
| 102 | # $line - Which line number in the script produced the error, if any (matches | ||
| 103 | # LA::Script->currentLine, 'undef' if no specific line) | ||
| 104 | # %errorHash - A hash of arguments used to substitute words in $errorCode (see comments | ||
| 105 | # below; can be an empty hash) | ||
| 106 | # | ||
| 107 | # Return values | ||
| 108 | # 'undef' on improper arguments | ||
| 109 | # Blessed reference to the newly-created object on success | ||
| 110 | |||
| 111 | my ($class, $scriptObj, $category, $errorCode, $func, $line, %errorHash) = @_; | ||
| 112 | |||
| 113 | # Check for improper arguments | ||
| 114 | if ( | ||
| 115 | ! defined $class || ! defined $scriptObj || ! defined $category || ! defined $errorCode | ||
| 116 | || ! defined $func | ||
| 117 | ) { | ||
| 118 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 119 | } | ||
| 120 | |||
| 121 | # Setup | ||
| 122 | my $self = { | ||
| 123 | _objName => $class, # Name Axbasic objects after their class | ||
| 124 | _objClass => $class, | ||
| 125 | _parentFile => undef, # No parent file object | ||
| 126 | _parentWorld => undef, # No parent file object | ||
| 127 | _privFlag => TRUE, # All IVs are private | ||
| 128 | |||
| 129 | # Perl object components | ||
| 130 | # ---------------------- | ||
| 131 | |||
| 132 | # The parent LA::Script | ||
| 133 | scriptObj => $scriptObj, | ||
| 134 | |||
| 135 | # IVs | ||
| 136 | # --- | ||
| 137 | |||
| 138 | # What kind of error this is ('error' or 'debug') | ||
| 139 | category => $category, | ||
| 140 | |||
| 141 | # The error message itself | ||
| 142 | # $errorCode is a string. For standard error messages, words are separated by underline | ||
| 143 | # characters, e.g. 'syntax_error' or 'illegal_word_WORD'. For non-standard error | ||
| 144 | # messages and debug messages, just use spaces | ||
| 145 | # For standard error messages, any word in $errorCode in CAPITALS, like the | ||
| 146 | # aforementioned WORD, is usually intended to be substituted using %errorHash. (If | ||
| 147 | # the word is not in capitals, substitution will still work) | ||
| 148 | errorCode => $errorCode, | ||
| 149 | # A string describing the function that generated the error | ||
| 150 | func => $func, | ||
| 151 | # Which line number in the script produced the error ('undef' if no specific line) | ||
| 152 | line => $line, | ||
| 153 | |||
| 154 | # A hash of arguments used to substitute words in $errorCode (empty if there are no | ||
| 155 | # words to substitute) | ||
| 156 | # For example, in the hypothetical error 'WORD_is_an_illegal_word', the key-value pair | ||
| 157 | # added to this hash would be | ||
| 158 | # key: WORD (all capitals signifies that this word should be substituted) | ||
| 159 | # value: the offending word itself, 'prnit' perhaps | ||
| 160 | errorHash => \%errorHash, | ||
| 161 | }; | ||
| 162 | |||
| 163 | bless $self, $class; | ||
| 164 | return $self; | ||
| 165 | } | ||
| 166 | |||
| 167 | ################## | ||
| 168 | # Methods | ||
| 169 | |||
| 170 | ################## | ||
| 171 | # Accessors - set | ||
| 172 | |||
| 173 | ################## | ||
| 174 | # Accessors - get | ||
| 175 | |||
| 176 | sub scriptObj | ||
| 177 | { $_[0]->{scriptObj} } | ||
| 178 | |||
| 179 | sub category | ||
| 180 | { $_[0]->{category} } | ||
| 181 | |||
| 182 | sub errorCode | ||
| 183 | { $_[0]->{errorCode} } | ||
| 184 | sub func | ||
| 185 | { $_[0]->{func} } | ||
| 186 | sub line | ||
| 187 | { $_[0]->{line} } | ||
| 188 | |||
| 189 | sub errorHash | ||
| 190 | { my $self = shift; return %{$self->{errorHash}}; } | ||
| 191 | } | ||
| 192 | |||
| 193 | { package Language::Axbasic::RawScript; | ||
| 194 | |||
| 195 | use strict; | ||
| 196 | use warnings; | ||
| 197 | # use diagnostics; | ||
| 198 | |||
| 199 | use Glib qw(TRUE FALSE); | ||
| 200 | |||
| 201 | @Language::Axbasic::RawScript::ISA = qw( | ||
| 202 | Language::Axbasic | ||
| 203 | ); | ||
| 204 | |||
| 205 | ################## | ||
| 206 | # Constructors | ||
| 207 | |||
| 208 | sub new { | ||
| 209 | |||
| 210 | # The class that handles a whole Axbasic script in its original, human-edited form | ||
| 211 | # (including empty lines, comments, leading whitespace, and primitive line numbers) | ||
| 212 | # The contents of the script can be edited freely. When LA::Script->new is called, it calls | ||
| 213 | # LA::RawScript->upload to make a copy of the script without empty lines, comments, or | ||
| 214 | # primitive line numbers | ||
| 215 | # After the call to LA::RawScript->upload, the copy of the script stored in LA::Script is | ||
| 216 | # fixed (and cannot be edited); meanwhile the copy stored in LA::RawScript can continue to | ||
| 217 | # be edited freely | ||
| 218 | # | ||
| 219 | # Call ->new to create the Perl object, ->loadFile to read a script into memory from a | ||
| 220 | # file, ->saveFile to save a script in memory to file | ||
| 221 | # Don't call ->upload directly; let LA::Script do it | ||
| 222 | # | ||
| 223 | # Expected arguments | ||
| 224 | # $session - The parent GA::Session | ||
| 225 | # $name - A named for the script | ||
| 226 | # | ||
| 227 | # Return values | ||
| 228 | # 'undef' on improper arguments | ||
| 229 | # Blessed reference to the newly-created object on success | ||
| 230 | |||
| 231 | my ($class, $session, $name, $check) = @_; | ||
| 232 | |||
| 233 | # Check for improper arguments | ||
| 234 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 235 | |||
| 236 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 237 | } | ||
| 238 | |||
| 239 | # Setup | ||
| 240 | my $self = { | ||
| 241 | _objName => $name, | ||
| 242 | _objClass => $class, | ||
| 243 | _parentFile => undef, # No parent file object | ||
| 244 | _parentWorld => undef, # No parent file object | ||
| 245 | _privFlag => TRUE, # All IVs are private | ||
| 246 | |||
| 247 | # Perl object components | ||
| 248 | # ---------------------- | ||
| 249 | |||
| 250 | # The parent GA::Session | ||
| 251 | session => $session, | ||
| 252 | |||
| 253 | # Raw script IVs | ||
| 254 | # -------------- | ||
| 255 | |||
| 256 | # The script name | ||
| 257 | name => $name, | ||
| 258 | # The full file path from which the script is loaded, every time $self->loadFile is | ||
| 259 | # called | ||
| 260 | filePath => undef, | ||
| 261 | |||
| 262 | # The lines of the script. A hash in the form | ||
| 263 | # $lineHash{line_number} = string_of_text | ||
| 264 | # ...where 'line_number' is in the range 1 to $self->lineCount | ||
| 265 | # | ||
| 266 | # (NB 'line_number' refers to the physical line number in the script - not the primitive | ||
| 267 | # line number, if it is being used) | ||
| 268 | lineHash => {}, | ||
| 269 | # How many lines in total (0 when the script is empty) | ||
| 270 | lineCount => 0, | ||
| 271 | |||
| 272 | # Flag set to TRUE whenever the script is modified. Set back to FALSE after any load or | ||
| 273 | # save operation | ||
| 274 | modifyFlag => FALSE, | ||
| 275 | }; | ||
| 276 | |||
| 277 | bless $self, $class; | ||
| 278 | return $self; | ||
| 279 | } | ||
| 280 | |||
| 281 | ################## | ||
| 282 | # Methods | ||
| 283 | |||
| 284 | sub setError { | ||
| 285 | |||
| 286 | # Can be called by any of the methods in this object when they notice an error caused by the | ||
| 287 | # Perl Code | ||
| 288 | # (Replaces LA::Script->setError, which can't be called because the corresponding | ||
| 289 | # LA::Script object probably doesn't exist yet) | ||
| 290 | # | ||
| 291 | # Expected arguments | ||
| 292 | # $errorMsg - The error message to display | ||
| 293 | # $func - A string describing the function that generated the error (e.g. | ||
| 294 | # 'Language::Axbasic::Statement->parse') | ||
| 295 | # | ||
| 296 | # Return values | ||
| 297 | # 'undef' | ||
| 298 | |||
| 299 | my ($self, $errorMsg, $func, $check) = @_; | ||
| 300 | |||
| 301 | # Check for improper arguments | ||
| 302 | if (! defined $errorMsg || ! defined $func || defined $check) { | ||
| 303 | |||
| 304 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setError', @_); | ||
| 305 | } | ||
| 306 | |||
| 307 | $self->session->writeText('AXBASIC: ERROR: ' . $errorMsg . ' (' . $func . ')'); | ||
| 308 | |||
| 309 | # This return value should trickle all the way down to LA::Script->parse or | ||
| 310 | # LA::Script->implement | ||
| 311 | return undef; | ||
| 312 | } | ||
| 313 | |||
| 314 | sub loadFile { | ||
| 315 | |||
| 316 | # Loads a file into memory. The file should contain an Axbasic script | ||
| 317 | # If the load succeeds, the contents of $self->lineHash and $self->lineCount are set from | ||
| 318 | # the contents of the file, and ->modifyFlag is set to FALSE. | ||
| 319 | # If the load fails, these IVs are not changed | ||
| 320 | # | ||
| 321 | # Expected arguments | ||
| 322 | # $filePath - Full path to the file to be loaded (must end with .bas) | ||
| 323 | # | ||
| 324 | # Return values | ||
| 325 | # 'undef' on improper arguments, if file loading/saving has been disabled, if the file | ||
| 326 | # doesn't exist, or if it can't be loaded, or if an operation to sort the lines into | ||
| 327 | # the right order fails | ||
| 328 | # 1 otherwise | ||
| 329 | |||
| 330 | my ($self, $filePath, $check) = @_; | ||
| 331 | |||
| 332 | # Local variables | ||
| 333 | my ( | ||
| 334 | $semaphoreHandle, $fileHandle, $lineCount, $result, | ||
| 335 | %lineHash, | ||
| 336 | ); | ||
| 337 | |||
| 338 | # Check for improper arguments | ||
| 339 | if (! defined $filePath || defined $check) { | ||
| 340 | |||
| 341 | return $axmud::CLIENT->writeImproper($self->_objClass . '->loadFile', @_); | ||
| 342 | } | ||
| 343 | |||
| 344 | # Check that file loading is enabled | ||
| 345 | if (! $axmud::CLIENT->loadDataFlag) { | ||
| 346 | |||
| 347 | return $self->setError( | ||
| 348 | 'Can\'t load Axbasic script because file access is disabled', | ||
| 349 | $self->_objClass . '->loadFile', | ||
| 350 | ); | ||
| 351 | } | ||
| 352 | |||
| 353 | # Check that the specified file exists | ||
| 354 | if (! (-e $filePath)) { | ||
| 355 | |||
| 356 | return $self->setError( | ||
| 357 | 'Can\'t load Axbasic script because the file \'' . $filePath . '\' doesn\'t exist', | ||
| 358 | $self->_objClass . '->loadFile', | ||
| 359 | ); | ||
| 360 | } | ||
| 361 | |||
| 362 | # Check that the specified file appears to be a .bas file | ||
| 363 | if (! $filePath =~ m/\.bas$/) { | ||
| 364 | |||
| 365 | return $self->setError( | ||
| 366 | 'Can\'t load Axbasic script because file doesn\'t appear to be a .bas file', | ||
| 367 | $self->_objClass . '->loadFile', | ||
| 368 | ); | ||
| 369 | } | ||
| 370 | |||
| 371 | # Get a shared lock on the twinned semaphore file using GA::Obj::File's file lock functions | ||
| 372 | $semaphoreHandle = $axmud::CLIENT->configFileObj->getFileLock( | ||
| 373 | $axmud::DATA_DIR . '/data/temp/axbasic.sem', # Semaphore file | ||
| 374 | FALSE, # Shared lock for reading | ||
| 375 | $filePath, | ||
| 376 | ); | ||
| 377 | |||
| 378 | # Don't try to load the file if no lock could be taken out on the semaphore file | ||
| 379 | if (! $semaphoreHandle) { | ||
| 380 | |||
| 381 | return $self->setError( | ||
| 382 | 'General error loading the Axbasic script', | ||
| 383 | $self->_objClass . '->loadFile', | ||
| 384 | ); | ||
| 385 | } | ||
| 386 | |||
| 387 | # Open the file for reading | ||
| 388 | if (! open ($fileHandle, "<$filePath")) { | ||
| 389 | |||
| 390 | return $self->setError( | ||
| 391 | 'General error loading the Axbasic script', | ||
| 392 | $self->_objClass . '->loadFile', | ||
| 393 | ); | ||
| 394 | } | ||
| 395 | |||
| 396 | # Read the file | ||
| 397 | $lineCount = 0; | ||
| 398 | while (defined (my $line = <$fileHandle>)) { | ||
| 399 | |||
| 400 | chomp $line; | ||
| 401 | $lineCount++; | ||
| 402 | $lineHash{$lineCount} = $line; | ||
| 403 | } | ||
| 404 | |||
| 405 | # Close the file | ||
| 406 | $result = close $fileHandle; | ||
| 407 | # Release the lock on the semaphore file | ||
| 408 | $axmud::CLIENT->configFileObj->releaseFileLock($semaphoreHandle); | ||
| 409 | |||
| 410 | if ($result) { | ||
| 411 | |||
| 412 | # Loading succeeded. Transfer the file's contents to this object's IVs | ||
| 413 | $self->ivPoke('filePath', $filePath); | ||
| 414 | $self->ivPoke('lineHash', %lineHash); | ||
| 415 | $self->ivPoke('lineCount', $lineCount); | ||
| 416 | $self->ivPoke('modifyFlag', FALSE); | ||
| 417 | |||
| 418 | return 1; | ||
| 419 | |||
| 420 | } else { | ||
| 421 | |||
| 422 | # Loading failed | ||
| 423 | return $self->setError( | ||
| 424 | 'General error loading the Axbasic script', | ||
| 425 | $self->_objClass . '->loadFile', | ||
| 426 | ); | ||
| 427 | } | ||
| 428 | } | ||
| 429 | |||
| 430 | sub saveFile { | ||
| 431 | |||
| 432 | # Saves a file from memory. The file should contain an Axbasic script. | ||
| 433 | # If the save succeeds, ->modifyFlag is set to FALSE. If the save fails, the flag is not | ||
| 434 | # changed | ||
| 435 | # | ||
| 436 | # Expected arguments | ||
| 437 | # $filePath - Full path to the file to be saved (must end with .bas) | ||
| 438 | # | ||
| 439 | # Return values | ||
| 440 | # 'undef' on improper arguments, if file loading/saving has been disabled, if the script | ||
| 441 | # in memory is empty or if the file can't be saved | ||
| 442 | # 1 otherwise | ||
| 443 | |||
| 444 | my ($self, $filePath, $check) = @_; | ||
| 445 | |||
| 446 | # Local variables | ||
| 447 | my ( | ||
| 448 | $semaphoreHandle, $fileHandle, $result, | ||
| 449 | @list, | ||
| 450 | ); | ||
| 451 | |||
| 452 | # Check for improper arguments | ||
| 453 | if (! defined $filePath || defined $check) { | ||
| 454 | |||
| 455 | return $axmud::CLIENT->writeImproper($self->_objClass . '->saveFile', @_); | ||
| 456 | } | ||
| 457 | |||
| 458 | # Check that file saving is enabled | ||
| 459 | if (! $axmud::CLIENT->saveDataFlag) { | ||
| 460 | |||
| 461 | return $self->setError( | ||
| 462 | 'Can\'t save Axbasic script because file access is disabled', | ||
| 463 | $self->_objClass . '->saveFile', | ||
| 464 | ); | ||
| 465 | } | ||
| 466 | |||
| 467 | # Check that the specified file appears to be a .bas file | ||
| 468 | if (! $filePath =~ m/\.bas$/) { | ||
| 469 | |||
| 470 | return $self->setError( | ||
| 471 | 'Can\'t save Axbasic script because file doesn\'t appear to be a .bas file', | ||
| 472 | $self->_objClass . '->saveFile', | ||
| 473 | ); | ||
| 474 | } | ||
| 475 | |||
| 476 | # Don't save anything if the script is empty | ||
| 477 | if (! $self->lineCount) { | ||
| 478 | |||
| 479 | return $self->setError( | ||
| 480 | 'Can\'t save Axbasic script because the script in memory is empty', | ||
| 481 | $self->_objClass . '->saveFile', | ||
| 482 | ); | ||
| 483 | } | ||
| 484 | |||
| 485 | # Get an exclusive lock on the twinned semaphore file using GA::Obj::FileObj's file lock | ||
| 486 | $semaphoreHandle = $axmud::CLIENT->configFileObj->getFileLock( | ||
| 487 | $axmud::DATA_DIR . '/data/temp/axbasic.sem', # Semaphore file | ||
| 488 | TRUE, # Exclusive lock for writing | ||
| 489 | $filePath, | ||
| 490 | ); | ||
| 491 | |||
| 492 | # Don't try to save the file if no lock could be taken out on the semaphore file | ||
| 493 | if (! defined $semaphoreHandle) { | ||
| 494 | |||
| 495 | return $self->setError( | ||
| 496 | 'General error saving the Axbasic script', | ||
| 497 | $self->_objClass . '->saveFile', | ||
| 498 | ); | ||
| 499 | } | ||
| 500 | |||
| 501 | # Open the file for writing, overwriting previous contents | ||
| 502 | if (! open ($fileHandle, ">$filePath")) { | ||
| 503 | |||
| 504 | return $self->setError( | ||
| 505 | 'General error saving the Axbasic script', | ||
| 506 | $self->_objClass . '->saveFile', | ||
| 507 | ); | ||
| 508 | } | ||
| 509 | |||
| 510 | # Retrieve the contents of the script as a list of strings, in order, from 1 to | ||
| 511 | # $self->lineCount | ||
| 512 | if ($self->lineCount) { | ||
| 513 | |||
| 514 | for (my $count = 1; $count <= $self->lineCount; $count++) { | ||
| 515 | |||
| 516 | if ($self->ivExists('lineHash', $count)) { | ||
| 517 | |||
| 518 | push (@list, $self->ivShow('lineHash', $count)); | ||
| 519 | } | ||
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 | # Add newline characters to every entry in @list before writing the whole list to the file | ||
| 524 | foreach my $item (@list) { | ||
| 525 | |||
| 526 | $item .= "\n"; | ||
| 527 | } | ||
| 528 | |||
| 529 | print $fileHandle @list; | ||
| 530 | |||
| 531 | # Writing complete | ||
| 532 | $result = close $fileHandle; | ||
| 533 | # Release the lock on the semaphore file | ||
| 534 | $axmud::CLIENT->configFileObj->releaseFileLock($semaphoreHandle); | ||
| 535 | |||
| 536 | if ($result) { | ||
| 537 | |||
| 538 | # Saving succeeded | ||
| 539 | $self->ivPoke('modifyFlag', FALSE); | ||
| 540 | |||
| 541 | return 1; | ||
| 542 | |||
| 543 | } else { | ||
| 544 | |||
| 545 | # Saving failed | ||
| 546 | return $self->setError( | ||
| 547 | 'General error saving the Axbasic script', | ||
| 548 | $self->_objClass . '->saveFile', | ||
| 549 | ); | ||
| 550 | } | ||
| 551 | } | ||
| 552 | |||
| 553 | sub upload { | ||
| 554 | |||
| 555 | # Called by LA::Script->new | ||
| 556 | # Processes the script in memory to remove all the extraneous stuff, including: | ||
| 557 | # - empty lines | ||
| 558 | # - leading whitespace at the beginning of lines | ||
| 559 | # - lines starting with comments (REM xxx) | ||
| 560 | # Also checks whether the Axbasic script seems to be using primitive line numbers. If so, | ||
| 561 | # the line numbers are removed from the beginning of each line and stored instead in a | ||
| 562 | # LA::Line object | ||
| 563 | # (However, statements like 'goto 550' don't have the line number removed - it's up to | ||
| 564 | # LA::Statement::Goto to deal with it) | ||
| 565 | # | ||
| 566 | # From the resulting stripped-down script, for every line of Axbasic, a new LA::Line | ||
| 567 | # object is created, and its blessed reference added to LA::Script->lineHash | ||
| 568 | # In this manner, the raw script stored in a LA::RawScript object is uploaded as a | ||
| 569 | # stripped-down copy of the script stored in a LA::Script object | ||
| 570 | # | ||
| 571 | # Expected arguments | ||
| 572 | # $scriptObj - Blessed reference to the LA::Script object, to which the script must | ||
| 573 | # be uploaded | ||
| 574 | # | ||
| 575 | # Return values | ||
| 576 | # 'undef' on improper arguments, or if there is no script in memory, if there is an error | ||
| 577 | # creating a LA::Line object, or if the script is empty (once all the extraneous stuff | ||
| 578 | # has been removed) | ||
| 579 | # 1 on success | ||
| 580 | |||
| 581 | my ($self, $scriptObj, $check) = @_; | ||
| 582 | |||
| 583 | # Local variables | ||
| 584 | my ( | ||
| 585 | $count, $procLineCount, $firstLine, $executionMode, | ||
| 586 | @initialList, | ||
| 587 | %uploadHash, %primLineHash, | ||
| 588 | ); | ||
| 589 | |||
| 590 | # Check for improper arguments | ||
| 591 | if (! defined $scriptObj || defined $check) { | ||
| 592 | |||
| 593 | return $axmud::CLIENT->writeImproper($self->_objClass . '->upload', @_); | ||
| 594 | } | ||
| 595 | |||
| 596 | # Check that there's a script in memory | ||
| 597 | if (! $self->lineCount) { | ||
| 598 | |||
| 599 | return $self->setError( | ||
| 600 | 'Can\'t process Axbasic script (the file is probably empty)', | ||
| 601 | $self->_objClass . '->upload', | ||
| 602 | ); | ||
| 603 | } | ||
| 604 | |||
| 605 | # Find the first line which contains a character. Test the first character on that line; | ||
| 606 | # if it's a digit, assume that the script uses primitive line numbering | ||
| 607 | $count = 0; | ||
| 608 | do { | ||
| 609 | |||
| 610 | $count++; | ||
| 611 | $firstLine = $self->ivShow('lineHash', $count); | ||
| 612 | |||
| 613 | if ($firstLine =~ m/\w/) { | ||
| 614 | |||
| 615 | # This contains at least one character, so use it as the first line | ||
| 616 | $count = $self->lineCount; # Escape the loop | ||
| 617 | } | ||
| 618 | |||
| 619 | } until ($count >= $self->lineCount); | ||
| 620 | |||
| 621 | if ($firstLine =~ m/^\s*(\d+)\s+/) { | ||
| 622 | |||
| 623 | # Primitive line numbering is now in effect | ||
| 624 | $executionMode = 'line_num'; | ||
| 625 | |||
| 626 | # Make sure all the lines in the script are in the right order | ||
| 627 | $self->sortLines(); | ||
| 628 | |||
| 629 | } else { | ||
| 630 | |||
| 631 | # No primitive line numbering | ||
| 632 | $executionMode = 'no_line_num'; | ||
| 633 | } | ||
| 634 | |||
| 635 | # For each line in the script... | ||
| 636 | $procLineCount = 0; | ||
| 637 | OUTER: for (my $origLineCount = 1; $origLineCount <= $self->lineCount; $origLineCount++) { | ||
| 638 | |||
| 639 | my ($lineText, $lineObj); | ||
| 640 | |||
| 641 | # Check that the line exists | ||
| 642 | if (! $self->ivExists('lineHash', $origLineCount)) { | ||
| 643 | |||
| 644 | # There is no reason why it should not exist - it's an error | ||
| 645 | return $self->setError( | ||
| 646 | 'Can\'t process Axbasic script, missing line #' . $origLineCount, | ||
| 647 | $self->_objClass . '->upload', | ||
| 648 | ); | ||
| 649 | } | ||
| 650 | |||
| 651 | # Check that the line actually contains some text | ||
| 652 | $lineText = $self->ivShow('lineHash', $origLineCount); | ||
| 653 | if (! $lineText || $lineText =~ m/^\s+$/) { | ||
| 654 | |||
| 655 | # This is an empty line. Move on to the next one | ||
| 656 | next OUTER; | ||
| 657 | } | ||
| 658 | |||
| 659 | # No primitive line numbering... | ||
| 660 | if ($executionMode eq 'no_line_num') { | ||
| 661 | |||
| 662 | # Remove any whitespace from the beginning and end of the line | ||
| 663 | $lineText = $axmud::CLIENT->trimWhitespace($lineText); | ||
| 664 | |||
| 665 | # If the whole line is a comment, ignore it | ||
| 666 | if ($lineText =~ /^rem /i) { | ||
| 667 | |||
| 668 | next OUTER; | ||
| 669 | } | ||
| 670 | |||
| 671 | # Create a LA::Line with what's left of the line (after whitespace was removed) | ||
| 672 | $procLineCount++; | ||
| 673 | $lineObj = Language::Axbasic::Line->new( | ||
| 674 | $scriptObj, | ||
| 675 | $lineText, | ||
| 676 | $origLineCount, | ||
| 677 | $procLineCount, | ||
| 678 | ); | ||
| 679 | |||
| 680 | if (! defined $lineObj) { | ||
| 681 | |||
| 682 | return $self->setError( | ||
| 683 | 'Can\'t upload Axbasic script, error creating line #' . $origLineCount, | ||
| 684 | $self->_objClass . 'upload', | ||
| 685 | ); | ||
| 686 | |||
| 687 | } else { | ||
| 688 | |||
| 689 | $uploadHash{$procLineCount} = $lineObj; | ||
| 690 | } | ||
| 691 | |||
| 692 | # Primitive line numbering... | ||
| 693 | } elsif ($executionMode eq 'line_num') { | ||
| 694 | |||
| 695 | my ($result, $primLineNum, $lineBody); | ||
| 696 | |||
| 697 | # Check that the line starts with a number, and has a body (text after the line | ||
| 698 | # number) | ||
| 699 | $result = $lineText =~ m/^\s*(\d+)\s+(.*)/; | ||
| 700 | $primLineNum = $1; | ||
| 701 | $lineBody = $2; | ||
| 702 | |||
| 703 | if (! $result) { | ||
| 704 | |||
| 705 | return $self->setError( | ||
| 706 | 'Can\'t process Axbasic script, invalid primitive line number format at' | ||
| 707 | . ' line #' . $origLineCount, | ||
| 708 | $self->_objClass . '->upload', | ||
| 709 | ); | ||
| 710 | } | ||
| 711 | |||
| 712 | # Remove any whitespace from the end of the line body | ||
| 713 | $lineBody =~ s/\s+$//; | ||
| 714 | |||
| 715 | # Create a LA::Line with the line body | ||
| 716 | $procLineCount++; | ||
| 717 | $lineObj = Language::Axbasic::Line->new( | ||
| 718 | $scriptObj, | ||
| 719 | $lineBody, | ||
| 720 | $origLineCount, | ||
| 721 | $procLineCount, | ||
| 722 | $primLineNum, | ||
| 723 | ); | ||
| 724 | |||
| 725 | if (! defined $lineObj) { | ||
| 726 | |||
| 727 | return $self->setError( | ||
| 728 | 'Can\'t process Axbasic script, error creating line #' | ||
| 729 | . $origLineCount, | ||
| 730 | $self->_objClass . '->upload', | ||
| 731 | ); | ||
| 732 | |||
| 733 | } else { | ||
| 734 | |||
| 735 | $uploadHash{$procLineCount} = $lineObj; | ||
| 736 | # Update the hash which converts the primitive line number into the processed | ||
| 737 | # line number | ||
| 738 | $primLineHash{$primLineNum} = $procLineCount; | ||
| 739 | } | ||
| 740 | } | ||
| 741 | } | ||
| 742 | |||
| 743 | if (! $procLineCount) { | ||
| 744 | |||
| 745 | # Nothing to upload. Use the same error message for an empty file, as for a file which | ||
| 746 | # just contains a load of whitespace | ||
| 747 | return $self->setError( | ||
| 748 | 'Can\'t process Axbasic script (the file is probably empty)', | ||
| 749 | $self->_objClass . '->upload', | ||
| 750 | ); | ||
| 751 | |||
| 752 | } else { | ||
| 753 | |||
| 754 | # Upload the processed script to the LA::Script object | ||
| 755 | $scriptObj->download( | ||
| 756 | ($procLineCount + 1), # Stored as LA::Script->lineCount | ||
| 757 | $executionMode, # ->executionMode | ||
| 758 | \%uploadHash, # ->lineHash | ||
| 759 | \%primLineHash, # ->primLineHash | ||
| 760 | ); | ||
| 761 | |||
| 762 | return 1; | ||
| 763 | } | ||
| 764 | } | ||
| 765 | |||
| 766 | sub sortLines { | ||
| 767 | |||
| 768 | # Called by $self->upload | ||
| 769 | # Sorts the script's lines into the right order | ||
| 770 | # e.g. '20 goto 10 : 10 print "hello"' becomes '10 print "hello" : 20 goto 10' | ||
| 771 | # | ||
| 772 | # Expected arguments | ||
| 773 | # (none besides $self) | ||
| 774 | # | ||
| 775 | # Return values | ||
| 776 | # 'undef' on improper arguments | ||
| 777 | # 1 on success | ||
| 778 | |||
| 779 | my ($self, $check) = @_; | ||
| 780 | |||
| 781 | # Local variables | ||
| 782 | my ( | ||
| 783 | $total, | ||
| 784 | @list, @sortedList, | ||
| 785 | %lineHash, %tempHash, | ||
| 786 | ); | ||
| 787 | |||
| 788 | # Check for improper arguments | ||
| 789 | if (defined $check) { | ||
| 790 | |||
| 791 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sortLines', @_); | ||
| 792 | } | ||
| 793 | |||
| 794 | # First import the values of the $self->lineHash into a list, so we can re-fill it. The | ||
| 795 | # current hash keys are now irrelevant | ||
| 796 | @list = $self->ivValues('lineHash'); | ||
| 797 | |||
| 798 | # Put the lines into a new hash, one by one | ||
| 799 | # The keys of the hash are the primitive line number. The values are the whole line, | ||
| 800 | # including the primitive line number | ||
| 801 | foreach my $line (@list) { | ||
| 802 | |||
| 803 | my $primLineNum; | ||
| 804 | |||
| 805 | if ($line =~ m/^\s*(\d+)(\s+)/) { | ||
| 806 | |||
| 807 | $primLineNum = $1; | ||
| 808 | |||
| 809 | # Check that a line with the same number doesn't already exist (duplicates are not | ||
| 810 | # allowed) | ||
| 811 | if (exists $tempHash{$primLineNum}) { | ||
| 812 | |||
| 813 | return $self->setError( | ||
| 814 | 'Duplicate line #' . $primLineNum, | ||
| 815 | $self->_objClass . '->sortLines', | ||
| 816 | ); | ||
| 817 | |||
| 818 | # Otherwise use this line | ||
| 819 | } else { | ||
| 820 | |||
| 821 | $tempHash{$primLineNum} = $line; | ||
| 822 | } | ||
| 823 | |||
| 824 | } else { | ||
| 825 | |||
| 826 | # Now that we're using primitive line numbering, lines without numbers are not | ||
| 827 | # allowed (but empty lines are allowed, and just ignored) | ||
| 828 | if ($line =~ m/\w/) { | ||
| 829 | |||
| 830 | return $self->setError( | ||
| 831 | 'Un-numbered line in raw script (expecting all lines to be numbered)', | ||
| 832 | $self->_objClass . '->sortLines', | ||
| 833 | ); | ||
| 834 | } | ||
| 835 | } | ||
| 836 | } | ||
| 837 | |||
| 838 | # Compile a sorted list of the primitive line numbers | ||
| 839 | @sortedList = sort {$a <=> $b} (keys %tempHash); | ||
| 840 | |||
| 841 | # Re-stock the original hash | ||
| 842 | $total = scalar @sortedList; | ||
| 843 | for (my $count = 1; $count <= $total; $count++) { | ||
| 844 | |||
| 845 | $lineHash{$count} = $tempHash{shift @sortedList}; | ||
| 846 | } | ||
| 847 | |||
| 848 | return 1; | ||
| 849 | } | ||
| 850 | |||
| 851 | ################## | ||
| 852 | # Accessors - set | ||
| 853 | |||
| 854 | ################## | ||
| 855 | # Accessors - get | ||
| 856 | |||
| 857 | sub session | ||
| 858 | { $_[0]->{session} } | ||
| 859 | |||
| 860 | sub name | ||
| 861 | { $_[0]->{name} } | ||
| 862 | sub filePath | ||
| 863 | { $_[0]->{filePath} } | ||
| 864 | |||
| 865 | sub lineHash | ||
| 866 | { my $self = shift; return %{$self->{lineHash}}; } | ||
| 867 | sub lineCount | ||
| 868 | { $_[0]->{lineCount} } | ||
| 869 | |||
| 870 | sub modifyFlag | ||
| 871 | { $_[0]->{modifyFlag} } | ||
| 872 | } | ||
| 873 | |||
| 874 | { package Language::Axbasic::Script; | ||
| 875 | |||
| 876 | use strict; | ||
| 877 | use warnings; | ||
| 878 | # use diagnostics; | ||
| 879 | |||
| 880 | use Glib qw(TRUE FALSE); | ||
| 881 | |||
| 882 | @Language::Axbasic::Script::ISA = qw( | ||
| 883 | Language::Axbasic | ||
| 884 | ); | ||
| 885 | |||
| 886 | ################## | ||
| 887 | # Constructors | ||
| 888 | |||
| 889 | sub new { | ||
| 890 | |||
| 891 | # The class that handles a whole script in a processed form (with all the empty lines, | ||
| 892 | # comments, etc removed). | ||
| 893 | # Call ->new to create a LA::Script object, which automatically downloads the code from | ||
| 894 | # the specified LA::RawScript object | ||
| 895 | # (LA::RawScript contains a script includes whitespace, empty lines, comments and possibly | ||
| 896 | # line numbers; LA::Script contains a script with all that stuff removed) | ||
| 897 | # | ||
| 898 | # Once created, the script stored in this object can be accessed in two modes: | ||
| 899 | # - Call ->parse to parse the script, looking for errors, but don't actually execute it | ||
| 900 | # - Call ->implement to parse the script, line-by-line, and then execute it | ||
| 901 | # If the Axbasic script pauses (usually when the script is being executed as an Axmud task), | ||
| 902 | # call ->parse or ->implement again to resume execution | ||
| 903 | # | ||
| 904 | # Expected arguments | ||
| 905 | # $session - The parent GA::Session | ||
| 906 | # | ||
| 907 | # Optional arguments | ||
| 908 | # $rawScriptObj - Blessed reference of the LA::RawScript from which to download the | ||
| 909 | # Axbasic script. If not specified, no script is downloaded (this | ||
| 910 | # is useful for accessing default values stored in this object's IVs) | ||
| 911 | # | ||
| 912 | # Return values | ||
| 913 | # 'undef' on improper arguments, or if the specified raw script can't be uploaded or if | ||
| 914 | # there's an error setting up intrinsic function objects | ||
| 915 | # Blessed reference to the newly-created object on success | ||
| 916 | |||
| 917 | my ($class, $session, $rawScriptObj, $check) = @_; | ||
| 918 | |||
| 919 | # Local variables | ||
| 920 | my ( | ||
| 921 | @keywordList, @logicalOpList, | ||
| 922 | %keywordHash, | ||
| 923 | ); | ||
| 924 | |||
| 925 | # Check for improper arguments | ||
| 926 | if (! defined $class || ! defined $session || defined $check) { | ||
| 927 | |||
| 928 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 929 | } | ||
| 930 | |||
| 931 | # Define the list of Axbasic keywords - used to set more than one IV | ||
| 932 | @keywordList = ( | ||
| 933 | 'access', 'addalias', 'addcongauge', 'addconstatus', 'addgauge', 'addhook', 'addmacro', | ||
| 934 | 'addstatus', 'addtimer', 'addtrig', 'angle', 'array', 'beep', 'begin', 'break', | ||
| 935 | 'bypass', 'call', 'case', 'client', 'cls', 'close', 'closewin', 'create', 'data', | ||
| 936 | 'debug', 'def', 'degrees', 'delalias', 'delgauge', 'delhook', 'deliface', 'delmacro', | ||
| 937 | 'delstatus', 'deltimer', 'deltrig', 'dim', 'dimensions', 'do', 'each', 'else', | ||
| 938 | 'elseif', 'emptywin', 'end', 'erase', 'error', 'exit', 'flashwin', 'for', 'global', | ||
| 939 | 'gosub', 'goto', 'help', 'if', 'in', 'input', 'let', 'local', 'login', 'loop', 'lower', | ||
| 940 | 'multi', 'move', 'name', 'needtask', 'new', 'newold', 'next', 'nextiface', 'nolet', | ||
| 941 | 'numeric', 'old', 'on', 'open', 'openentry', 'openwin', 'option', 'org', 'organization', | ||
| 942 | 'outin', 'output', 'paintwin', 'pause', 'peek', 'peekequals', 'peekexists', 'peekfind', | ||
| 943 | 'peekfirst', 'peekget', 'peekindex', 'peekkeys', 'peeklast', 'peekmatch', 'peeknumber', | ||
| 944 | 'peekpairs', 'peekshow', 'peekvalues', 'perl', 'persist', 'play', 'poke', 'pokeadd', | ||
| 945 | 'pokedec', 'pokedechash', 'pokedelete', 'pokedivide', 'pokeempty', 'pokefalse', | ||
| 946 | 'pokeinc', 'pokeinchash', 'pokeint', 'pokeminus', 'pokemultiply', 'pokeplus', 'pokepop', | ||
| 947 | 'pokepush', 'pokereplace', 'pokeset', 'pokeshift', 'poketrue', 'pokeundef', | ||
| 948 | 'pokeunshift', 'pop', 'print', 'profile', 'pseudo', 'push', 'radians', 'randomize', | ||
| 949 | 'read', 'redim', 'redirect', 'relay', 'rem', 'require', 'reset', 'restore', 'return', | ||
| 950 | 'revpath', 'select', 'send', 'setalias', 'setgauge', 'sethook', 'setmacro', 'setstatus', | ||
| 951 | 'settimer', 'settrig', 'shift', 'silent', 'size', 'skipiface', 'sleep', 'sort', | ||
| 952 | 'sortcase', 'sortcaser', 'sortr', 'speak', 'speed', 'step', 'stop', 'string', 'sub', | ||
| 953 | 'tab', 'text', 'titlewin', 'then', 'to', 'typo', 'unflashwin', 'unshift', 'until', | ||
| 954 | 'upper', 'waitactive', 'waitalias', 'waitalive', 'waitarrive', 'waitdead', 'waitep', | ||
| 955 | 'waitgp', 'waithook', 'waithp', 'waitmacro', 'waitmp', 'waitnextxp', 'waitnotactive', | ||
| 956 | 'waitpassout', 'waitscript', 'waitsleep', 'waitsp', 'waittask', 'waittimer', | ||
| 957 | 'waittotalxp', 'waittrig', 'waitxp', 'warning', 'while', 'winaddcongauge', | ||
| 958 | 'winaddconstatus', 'winaddgauge', 'winaddstatus', 'windelgauge', 'windelstatus', | ||
| 959 | 'winsetgauge', 'winsetstatus', 'write', 'writewin', | ||
| 960 | ); | ||
| 961 | |||
| 962 | foreach my $keyword (@keywordList) { | ||
| 963 | |||
| 964 | $keywordHash{$keyword} = undef; | ||
| 965 | } | ||
| 966 | |||
| 967 | # Define the list of logical operators - used to set more than one IV | ||
| 968 | @logicalOpList = ('and', 'or', 'not'); | ||
| 969 | |||
| 970 | # Setup | ||
| 971 | my $self = { | ||
| 972 | _objName => $class, # Name Axbasic objects after their class | ||
| 973 | _objClass => $class, | ||
| 974 | _parentFile => undef, # No parent file object | ||
| 975 | _parentWorld => undef, # No parent file object | ||
| 976 | _privFlag => TRUE, # All IVs are private | ||
| 977 | |||
| 978 | # Perl object components | ||
| 979 | # ---------------------- | ||
| 980 | |||
| 981 | # The parent GA::Session | ||
| 982 | session => $session, | ||
| 983 | |||
| 984 | # Script IVs | ||
| 985 | # ---------- | ||
| 986 | |||
| 987 | # The script name (matches the ->name of the LA::RawScript object from which the Axbasic | ||
| 988 | # script has been downloaded; set to 'undef' until then) | ||
| 989 | name => undef, | ||
| 990 | # The full file path from which the script is loaded, every time LA::RawScript->loadFile | ||
| 991 | # is called (set by this function, if a script is downloaded, but remains set to | ||
| 992 | # 'undef' otherwise) | ||
| 993 | filePath => undef, | ||
| 994 | |||
| 995 | # All the lines in the script, a hash in the form | ||
| 996 | # $lineHash{line_number} = blessed_reference_to_LA::Line object | ||
| 997 | # The first line number is $lineHash{1} | ||
| 998 | lineHash => {}, | ||
| 999 | # How many lines in total (0 when the script is empty) | ||
| 1000 | lineCount => 0, | ||
| 1001 | # The current line number (matches a key in $self->lineHash) | ||
| 1002 | currentLine => undef, | ||
| 1003 | # The next line to execute (the line's ->procLineNum, not its blessed reference) | ||
| 1004 | nextLine => undef, | ||
| 1005 | # Blessed reference of the next statement to execute | ||
| 1006 | nextStatement => undef, | ||
| 1007 | |||
| 1008 | # A hash to convert primitive line numbers into ->procLineNum values | ||
| 1009 | # e.g. 10 PRINT "hello" | ||
| 1010 | # 20 GOTO 10 | ||
| 1011 | # key = 10, value = 0 / key = 20, value = 1 | ||
| 1012 | primLineHash => {}, | ||
| 1013 | |||
| 1014 | # Execution mode: | ||
| 1015 | # 'not_set' - not set yet | ||
| 1016 | # 'no_line_num' - modern-style BASIC scripts without line numbers, GOTO, etc | ||
| 1017 | # 'line_num' primitive BASIC scripts with line numbers, GOTO, etc | ||
| 1018 | # When LA::RawScript->upload is called, it sets this IV. If the first character in | ||
| 1019 | # the raw script is a number, it assumes that it's a primitive script with line | ||
| 1020 | # numbers, and sets this IV to 'line_num'. Otherwise, sets it to 'no_line_num' | ||
| 1021 | executionMode => 'not_set', | ||
| 1022 | # Normally, only the first error message generated is displayed in the 'main' window by | ||
| 1023 | # $self->terminateExecution. In that case, this flag is set to FALSE. | ||
| 1024 | # If the flag is set to TRUE, all error messages are displayed (this can make for a | ||
| 1025 | # confusing experience for the user, which is why it's turned off by default) | ||
| 1026 | allErrorsFlag => FALSE, | ||
| 1027 | # Flag set to TRUE at the start of a call to $self->implement, and set back to FALSE | ||
| 1028 | # when that function ends. | ||
| 1029 | # When the flag is true, any recursive calls to $self->implement are ignored; this | ||
| 1030 | # prevents any part of the Axmud code calling ->implement, which in turn calls some | ||
| 1031 | # part of the Axmud code, which in turns calls ->implement again | ||
| 1032 | implementFlag => FALSE, | ||
| 1033 | |||
| 1034 | # A list of all Axbasic keywords | ||
| 1035 | keywordList => \@keywordList, | ||
| 1036 | # A hash of keywords (for lookup by the Axbasic help functions), in the form | ||
| 1037 | # $keywordHash{keyword} = undef | ||
| 1038 | keywordHash => \%keywordHash, | ||
| 1039 | # A list of Axbasic keywords only available in $self->executionMode 'no_line_num' | ||
| 1040 | # (modern-style BASIC scripts) | ||
| 1041 | modernKeywordList => [ | ||
| 1042 | 'call', 'case', 'do', 'exit', 'global', 'local', 'loop', 'numeric', 'select', | ||
| 1043 | 'string', 'sub', 'until', 'while', | ||
| 1044 | ], | ||
| 1045 | # A list of Axbasic keywords only available in $self->executionMode 'line_num' | ||
| 1046 | # (primitive BASIC scripts) | ||
| 1047 | primKeywordList => [ | ||
| 1048 | 'goto', 'gosub', 'on', | ||
| 1049 | ], | ||
| 1050 | # A list of keywords used to set/fetch Axmud's internal variables | ||
| 1051 | peekPokeList => [ | ||
| 1052 | 'peek', 'peekequals', 'peekexists', 'peekfind', 'peekfirst', 'peekget', 'peekindex', | ||
| 1053 | 'peekkeys', 'peeklast', 'peekmatch', 'peeknumber', 'peekpairs', 'peekshow', | ||
| 1054 | 'peekvalues', 'poke', 'pokeadd', 'pokedec', 'pokedechash', 'pokedelete', | ||
| 1055 | 'pokedivide', 'pokeempty', 'pokefalse', 'pokeinc', 'pokeinchash', 'pokeint', | ||
| 1056 | 'pokeminus', 'pokemultiply', 'pokeplus', 'pokepop', 'pokepush', 'pokereplace', | ||
| 1057 | 'pokeset', 'pokeshift', 'poketrue', 'pokeundef', 'pokeunshift', | ||
| 1058 | ], | ||
| 1059 | # A hash of keywords that can't begin a statement. The keys in the hash are the keywords | ||
| 1060 | # themselves; the corresponding values are keywords which can begin a statement. When | ||
| 1061 | # the user types a command like ';axbasic help angle', they are presented help for the | ||
| 1062 | # value ('option') corresponding to the key ('angle') | ||
| 1063 | weakKeywordHash => { | ||
| 1064 | 'access' => 'open', | ||
| 1065 | 'array' => 'peek', # Also used in POKE, PEEK..., POKE... | ||
| 1066 | 'angle' => 'option', | ||
| 1067 | 'begin' => 'reset', | ||
| 1068 | 'create' => 'open', | ||
| 1069 | 'degrees' => 'option', | ||
| 1070 | 'dimensions' => 'let', | ||
| 1071 | 'each' => 'for', | ||
| 1072 | 'in' => 'for', | ||
| 1073 | 'lower' => 'let', | ||
| 1074 | 'name' => 'open', | ||
| 1075 | 'needtask' => 'option', | ||
| 1076 | 'new' => 'open', | ||
| 1077 | 'newold' => 'open', | ||
| 1078 | 'nolet' => 'option', | ||
| 1079 | 'numeric' => 'sub', | ||
| 1080 | 'old' => 'open', | ||
| 1081 | 'org' => 'open', | ||
| 1082 | 'organization' => 'open', | ||
| 1083 | 'outin' => 'open', | ||
| 1084 | 'output' => 'open', | ||
| 1085 | 'persist' => 'option', | ||
| 1086 | 'pseudo' => 'option', | ||
| 1087 | 'radians' => 'option', | ||
| 1088 | 'redirect' => 'option', | ||
| 1089 | 'require' => 'option', | ||
| 1090 | 'silent' => 'option', | ||
| 1091 | 'size' => 'let', | ||
| 1092 | 'step' => 'for', | ||
| 1093 | 'string' => 'sub', | ||
| 1094 | 'tab' => 'print', | ||
| 1095 | 'text' => 'open', | ||
| 1096 | 'then' => 'for', | ||
| 1097 | 'to' => 'for', | ||
| 1098 | 'typo' => 'option', | ||
| 1099 | 'upper' => 'let', | ||
| 1100 | }, | ||
| 1101 | # A hash of keywords that are either synonyms of other keywords (such as PAUSE and | ||
| 1102 | # SLEEP), or whose code is so similar that their LA::Statement objects should be | ||
| 1103 | # combined (such as ADDGAUGE and ADDCONGAUGE) | ||
| 1104 | equivKeywordHash => { | ||
| 1105 | 'addcongauge' => 'addgauge', | ||
| 1106 | 'addconstatus' => 'addstatus', | ||
| 1107 | 'elseif' => 'else', | ||
| 1108 | 'sleep' => 'pause', | ||
| 1109 | 'winaddcongauge' => 'addgauge', | ||
| 1110 | 'winaddconstatus' => 'addstatus', | ||
| 1111 | 'winaddgauge' => 'addgauge', | ||
| 1112 | 'winaddstatus' => 'addstatus', | ||
| 1113 | 'windelgauge' => 'delgauge', | ||
| 1114 | 'windelstatus' => 'delstatus', | ||
| 1115 | 'winsetgauge' => 'setgauge', | ||
| 1116 | 'winsetstatus' => 'setstatus', | ||
| 1117 | }, | ||
| 1118 | # A list of statements that interact directly with Axmud | ||
| 1119 | clientKeywordList => [ | ||
| 1120 | 'addalias', 'addcongauge', 'addconstatus', 'addgauge', 'addstatus', 'addhook', | ||
| 1121 | 'addmacro', 'addtimer', 'addtrig', 'array', 'beep', 'break', 'bypass', 'client', | ||
| 1122 | 'closewin', 'debug', 'delalias', 'delgauge', 'deliface', 'delhook', 'delmacro', | ||
| 1123 | 'delstatus', 'deltimer', 'deltrig', 'emptywin', 'error', 'flashwin', 'login', | ||
| 1124 | 'move', 'multi', 'nextiface', 'openentry', 'openwin', 'paintwin', 'pause', 'peek', | ||
| 1125 | 'peekequals', 'peekexists', 'peekfind', 'peekfirst', 'peekget', 'peekindex', | ||
| 1126 | 'peekkeys', 'peeklast', 'peekmatch', 'peeknumber', 'peekpairs', 'peekshow', | ||
| 1127 | 'peekvalues', 'perl', 'play', 'poke', 'pokeadd', 'pokedec', 'pokedechash', | ||
| 1128 | 'pokedelete', 'pokedivide', 'pokeempty', 'pokefalse', 'pokeinc', 'pokeinchash', | ||
| 1129 | 'pokeint', 'pokeminus', 'pokemultiply', 'pokeplus', 'pokepop', 'pokepush', | ||
| 1130 | 'pokereplace', 'pokeset', 'pokeshift', 'poketrue', 'pokeundef', 'pokeunshift', | ||
| 1131 | 'profile', 'relay', 'revpath', 'send', 'setalias', 'setgauge', 'sethook', | ||
| 1132 | 'setmacro', 'setstatus', 'settimer', 'settrig', 'skipiface', 'sleep', 'speak', | ||
| 1133 | 'speed', 'titlewin', 'unflashwin', 'waitactive', 'waitalias', 'waitalive', | ||
| 1134 | 'waitarrive', 'waitdead', 'waitep', 'waitgp', 'waithook', 'waithp', 'waitmacro', | ||
| 1135 | 'waitmp', 'waitnextxp', 'waitpassout', 'waitscript', 'waitsleep', 'waitsp', | ||
| 1136 | 'waittask', 'waittimer', 'waittotalxp', 'waittrig', 'waitxp', 'warning', | ||
| 1137 | 'winaddcongauge', 'winaddconstatus', 'winaddgauge', 'winaddstatus', 'windelgauge', | ||
| 1138 | 'windelstatus', 'winsetgauge', 'winsetstatus', 'write', 'writewin', | ||
| 1139 | ], | ||
| 1140 | # A list of keywords that are ignored when the Axbasic script isn't being run from | ||
| 1141 | # within a task | ||
| 1142 | taskKeywordList => [ | ||
| 1143 | 'addcongauge', 'addgauge', 'addconstatus', 'addstatus', 'break', 'closewin', | ||
| 1144 | 'delgauge', 'emptywin', 'flashwin', 'openentry', 'openwin', 'paintwin', 'pause', | ||
| 1145 | 'setalias', 'setgauge', 'sethook', 'setmacro', 'settimer', 'settrig', 'sleep', | ||
| 1146 | 'titlewin', 'unflashwin', 'waitactive', 'waitalias', 'waitalive', 'waitarrive', | ||
| 1147 | 'waitdead', 'waitep', 'waitgp', 'waithook', 'waithp', 'waitmacro', 'waitmp', | ||
| 1148 | 'waitnextxp', 'waitnotactive', 'waitpassout', 'waitscript', 'waitsleep', 'waitsp', | ||
| 1149 | 'waittask', 'waittimer', 'waittotalxp', 'waittrig', 'waitxp', 'winaddcongauge', | ||
| 1150 | 'winaddconstatus', 'winaddgauge', 'winaddstatus', 'windelgauge', 'windelstatus', | ||
| 1151 | 'winsetgauge', 'winsetstatus', 'writewin', | ||
| 1152 | ], | ||
| 1153 | |||
| 1154 | # A list of logical operators ('and', 'or', 'not') | ||
| 1155 | logicalOpList => \@logicalOpList, | ||
| 1156 | # A list of regular expression with which to split a line of Axbasic into a series of | ||
| 1157 | # tokens, in the format | ||
| 1158 | # $regexHash{token_category} = regex_to_identify_it | ||
| 1159 | regexHash => { | ||
| 1160 | 'short_comment' => '(?i)!($|.*)', | ||
| 1161 | 'comment' => '(?i)REM($|\s.*)', | ||
| 1162 | 'keyword' => "(?i)(" . join("|", @keywordList) . ")\\b", | ||
| 1163 | 'identifier' => '(?i)[A-Z][A-Z0-9_]*\\$?', | ||
| 1164 | 'logical_operator' => "(?i)(" . join("|", @logicalOpList) . ")\\b", | ||
| 1165 | 'string_constant' => '".*?"', | ||
| 1166 | 'numeric_constant' => '(\\d*\\.)?\\d+', | ||
| 1167 | 'left_paren' => '\\(', | ||
| 1168 | 'right_paren' => '\\)', | ||
| 1169 | 'file_channel' => '\#[0-9]+\s*\:?', | ||
| 1170 | 'separator' => '[,;]' , | ||
| 1171 | 'arithmetic_operator' => '[-+&]', | ||
| 1172 | 'multiplicative_operator' | ||
| 1173 | => '[*/\^]', | ||
| 1174 | 'relational_operator' => '<[=>]?|>=?|=', | ||
| 1175 | 'assignment_operator' => '=', | ||
| 1176 | 'statement_end' => ':', | ||
| 1177 | }, | ||
| 1178 | |||
| 1179 | # The list of token categories, in a standard order | ||
| 1180 | categoryList => [ | ||
| 1181 | 'short_comment', | ||
| 1182 | 'comment', | ||
| 1183 | 'keyword', | ||
| 1184 | 'identifier', | ||
| 1185 | 'logical_operator', | ||
| 1186 | 'string_constant', | ||
| 1187 | 'numeric_constant', | ||
| 1188 | 'left_paren', | ||
| 1189 | 'right_paren', | ||
| 1190 | 'file_channel', | ||
| 1191 | 'separator', | ||
| 1192 | 'arithmetic_operator', | ||
| 1193 | 'multiplicative_operator', | ||
| 1194 | 'relational_operator', | ||
| 1195 | 'assignment_operator', | ||
| 1196 | 'statement_end', | ||
| 1197 | ], | ||
| 1198 | |||
| 1199 | # The script's status: | ||
| 1200 | # 'waiting' - parsing (or implementation) not yet started | ||
| 1201 | # 'parsing' - being parsed (or implemented) | ||
| 1202 | # 'paused' - being parsed (or implemented), but paused (normally when the Axbasic | ||
| 1203 | # script is being run as an Axmud task) | ||
| 1204 | # 'wait_input' - being implemented (when the Axbasic script is being run as an Axmud | ||
| 1205 | # task), but waiting for INPUT | ||
| 1206 | # 'finished' - parsed (or implemented) and finished | ||
| 1207 | # 'basic_error' - parsed (or implemented) but found an error in the Axbasic script | ||
| 1208 | # 'perl_error' - parsed (or implemented) but found an error in the Perl Code | ||
| 1209 | # 'wait_status' - being implemented, but execution has halted after a statement like | ||
| 1210 | # WAITHP. Control is passed back to the parent task, but the parent task isn't | ||
| 1211 | # paused | ||
| 1212 | # 'wait_active' - being implemented, but execution has halted after a WAITACTIVE | ||
| 1213 | # statement. Control is passed back to the parent task, but the parent task isn't | ||
| 1214 | # paused | ||
| 1215 | # 'wait_not_active' - being implemented, but execution has halted after a | ||
| 1216 | # WAITNOTACTIVE statement. Control is passed back to the parent task, but the | ||
| 1217 | # parent task isn't paused | ||
| 1218 | # NB Only the first error message sets ->scriptStatus | ||
| 1219 | scriptStatus => 'waiting', | ||
| 1220 | # The execution mode | ||
| 1221 | # 'waiting' - execution not yet started | ||
| 1222 | # 'parse' - parse, but don't execute (used for checking for syntax errors), set when | ||
| 1223 | # $self->parse is called | ||
| 1224 | # 'implement - execute (implement), set when $self->implement is called | ||
| 1225 | # 'finished' - parsing/implementation finished | ||
| 1226 | executionStatus => 'waiting', | ||
| 1227 | |||
| 1228 | # Blessed reference of the Script task running the script ('undef' if the script isn't | ||
| 1229 | # being run from within a task) | ||
| 1230 | parentTask => undef, | ||
| 1231 | # When the script is being run by an Axmud task, it's useful to limit the number of | ||
| 1232 | # steps allowed on each spin of the task loop; so that if the script gets into a very | ||
| 1233 | # long calculation (or even an infinite loop), the Axmud client doesn't freeze | ||
| 1234 | # If the value is set to 0, there is no maximum: the script will keep running until a | ||
| 1235 | # PAUSE, BREAK or END (etc) statement | ||
| 1236 | stepMax => 100, | ||
| 1237 | # How many steps have been used during this task loop (0 if script not run by a task) | ||
| 1238 | stepCount => 0, | ||
| 1239 | |||
| 1240 | # List of names of the independent interfaces created by ADDTRIG, ADDALIAS, ADDMACRO, | ||
| 1241 | # ADDTIMER and ADDHOOK statements, which are stored in the current world's cages | ||
| 1242 | # (unless a different cage is specified) | ||
| 1243 | # If OPTION PERSIST has not been used, all these interfaces must are deleted when the | ||
| 1244 | # Axbasic script terminates | ||
| 1245 | # The list is in the form: | ||
| 1246 | # ( | ||
| 1247 | # independent_interface_name, profile_name, category, | ||
| 1248 | # independent_interface_name, profile_name, category | ||
| 1249 | # ... | ||
| 1250 | # ) | ||
| 1251 | # 'category' will be one of 'trigger', 'alias', 'macro', 'timer' or 'hook' | ||
| 1252 | indepInterfaceList => [], | ||
| 1253 | # IV which stores whether the most recent attempt to create an independent trigger | ||
| 1254 | # (etc) was successful | ||
| 1255 | # Stores the name of the trigger (etc) for success, or 'undef' for failure (or when none | ||
| 1256 | # yet created by this Axbasic script) | ||
| 1257 | indepInterfaceName => undef, | ||
| 1258 | # List of names of the dependent interfaces created by SETTRIG (etc) and WAITTRIG (etc) | ||
| 1259 | # statements. | ||
| 1260 | # These interfaces are deleted when the script terminates, regardless of whether | ||
| 1261 | # OPTION PERSIST has been used | ||
| 1262 | # NB ->indepInterfaceList and ->indepInterfaceName are not currently updated to remove | ||
| 1263 | # an interface, after a DELTRIG (etc) statement | ||
| 1264 | depInterfaceList => [], | ||
| 1265 | # Flag which stores whether the most recent attempt to create a dependent trigger (etc) | ||
| 1266 | # resulted in the creation of an interface | ||
| 1267 | # Stores the name of the interface for success, or 'undef' for failure (or when none | ||
| 1268 | # created by this Axbasic script) | ||
| 1269 | depInterfaceName => undef, | ||
| 1270 | # Every time a dependent interface created by a SETTRIG (etc) statement fires, | ||
| 1271 | # information about the interface is stored in a LA::Notification object, which is | ||
| 1272 | # then added to the end of this list. (The script can retrieve notifications from the | ||
| 1273 | # list at its own convenience) | ||
| 1274 | # NB ->depInterfaceList and ->depInterfaceName ARE currently updated to remove an | ||
| 1275 | # interface, after a DELIFACE statement | ||
| 1276 | notificationList => [], | ||
| 1277 | # If there is more than one LA::Notification in ->notificationList, one of them (usually | ||
| 1278 | # the first in the list) is the 'current' one. This IV stores the index containing the | ||
| 1279 | # current LA::Notification. If there is one notification in the list, this IV is set | ||
| 1280 | # to 0. When the list is empty, it is set to -1 | ||
| 1281 | currentNotification => -1, | ||
| 1282 | |||
| 1283 | # Whenever an error is found, a LA::Error object is created to store details of the | ||
| 1284 | # error, until the error message (or messages) can be displayed, at the moment when | ||
| 1285 | # execution halts | ||
| 1286 | # The error objects are stored in this list. The first error generated corresponds to | ||
| 1287 | # the first error object in the list | ||
| 1288 | errorList => [], | ||
| 1289 | |||
| 1290 | # The following IVs are set with calls to $self->popSubStack and $self->pushSubStack | ||
| 1291 | # Subroutine/function stack. (Single-line functions, declared with the 'def' statement, | ||
| 1292 | # aren't inserted into the stack) | ||
| 1293 | # In execution mode 1 (no line numbers), contains a list of LA::Subroutines; the first | ||
| 1294 | # one in the list is the '*main" 'subroutine' which represents the main Axbasic | ||
| 1295 | # script | ||
| 1296 | # In execution mode 2 (primitive line numbers), contains only '*main' | ||
| 1297 | subStackList => [], | ||
| 1298 | # How many subroutines/functions are in the stack | ||
| 1299 | subCount => 0, | ||
| 1300 | # In execution mode 1 (no line numbers), not used | ||
| 1301 | # In execution mode 2 (primitive line numbers), contains a list of GOSUB or ON-GOSUB | ||
| 1302 | # statements so that, upon RETURN, execution resumes with the line immediately after | ||
| 1303 | # the GOSUB statement | ||
| 1304 | gosubStackList => [], | ||
| 1305 | |||
| 1306 | # Subroutines and functions have separate namespaces, so it's possible to have a | ||
| 1307 | # function, and a subroutine, both called 'test' | ||
| 1308 | # Hash of subroutine names, so that we don't create two subroutines with the same name | ||
| 1309 | # (this should cause an error). Hash in the form | ||
| 1310 | # $subNameHash{name} = blessed_reference_to_LA::Subroutine | ||
| 1311 | # (This is only used in execution mode 1) | ||
| 1312 | subNameHash => {}, | ||
| 1313 | # Hash of function names (including single-line functions). If a function is declared a | ||
| 1314 | # second time, it overwrites the original profile (even if it's an intrinsic | ||
| 1315 | # function). Hash in the form | ||
| 1316 | # $funcNameHash{name} = blessed_reference_to_LA::Function | ||
| 1317 | # (This is only used in execution mode 1) | ||
| 1318 | funcNameHash => {}, | ||
| 1319 | # Hash of intrinsic (pre-defined) functions, in the form | ||
| 1320 | # $funcArgHash{function_name} = argument_string | ||
| 1321 | # Each argument in the argument string is represented by a letter; N for a numeric | ||
| 1322 | # argument, S for a string argument. Arguments after a ';' are optional. An empty | ||
| 1323 | # argument string is used with intrinsic functions that take no arguments | ||
| 1324 | # Intrinsic function return either a string value (in which case, they end with $) or | ||
| 1325 | # a numeric value | ||
| 1326 | funcArgHash => { | ||
| 1327 | # Pure BASIC functions (returning a numeric value) | ||
| 1328 | 'abs' => 'N', | ||
| 1329 | 'acos' => 'N', | ||
| 1330 | 'angle' => 'NN', | ||
| 1331 | 'asc' => 'S', | ||
| 1332 | 'asin' => 'N', | ||
| 1333 | 'atn' => 'N', | ||
| 1334 | 'ceil' => 'N', | ||
| 1335 | 'cos' => 'N', | ||
| 1336 | 'cosh' => 'N', | ||
| 1337 | 'cot' => 'N', | ||
| 1338 | 'cpos' => 'SS;N', | ||
| 1339 | 'cposr' => 'SS;N', | ||
| 1340 | 'csc' => 'N', | ||
| 1341 | 'date' => '', | ||
| 1342 | 'deg' => 'N', | ||
| 1343 | 'eof' => 'N', | ||
| 1344 | 'epoch' => '', | ||
| 1345 | 'exp' => 'N', | ||
| 1346 | 'floor' => 'N', | ||
| 1347 | 'fp' => 'N', | ||
| 1348 | 'int' => 'N', | ||
| 1349 | 'ip' => 'N', | ||
| 1350 | 'len' => 'S', | ||
| 1351 | 'log' => 'N', | ||
| 1352 | 'log10' => 'N', | ||
| 1353 | 'log2' => 'N', | ||
| 1354 | 'match' => 'SS', | ||
| 1355 | 'matchi' => 'SS', | ||
| 1356 | 'max' => 'NN', | ||
| 1357 | 'min' => 'NN', | ||
| 1358 | 'mod' => 'NN', | ||
| 1359 | 'ncpos' => 'SS;N', | ||
| 1360 | 'ncposr' => 'SS;N', | ||
| 1361 | 'pi' => '', | ||
| 1362 | 'pos' => 'SS;N', | ||
| 1363 | 'posr' => 'SS;N', | ||
| 1364 | 'rad' => 'N', | ||
| 1365 | 'remainder' => 'NN', | ||
| 1366 | 'rnd' => 'N', | ||
| 1367 | 'round' => 'N;N', | ||
| 1368 | 'sec' => 'N', | ||
| 1369 | 'sgn' => 'N', | ||
| 1370 | 'sin' => 'N', | ||
| 1371 | 'sinh' => 'N', | ||
| 1372 | 'sqr' => 'N', | ||
| 1373 | 'tan' => 'N', | ||
| 1374 | 'tanh' => 'N', | ||
| 1375 | 'testpat' => 'S', | ||
| 1376 | 'time' => '', | ||
| 1377 | 'trunc' => 'N;N', | ||
| 1378 | 'val' => 'S', | ||
| 1379 | 'version' => '', | ||
| 1380 | # Pure BASIC functions (returning a string value) | ||
| 1381 | 'chr$' => 'N', | ||
| 1382 | 'date$' => '', | ||
| 1383 | 'ip$' => '', | ||
| 1384 | 'lcase$' => 'S', | ||
| 1385 | 'left$' => 'SN', | ||
| 1386 | 'ltrim$' => 'S', | ||
| 1387 | 'mid$' => 'SN;N', | ||
| 1388 | 'repeat$' => 'SN', | ||
| 1389 | 'right$' => 'SN', | ||
| 1390 | 'rtrim$' => 'S', | ||
| 1391 | 'str$' => 'N', | ||
| 1392 | 'testpat$' => 'S', | ||
| 1393 | 'time$', => '', | ||
| 1394 | 'trim$' => 'S', | ||
| 1395 | 'ucase$' => 'S', | ||
| 1396 | # Axmud-dependent functions (returning a numeric value) | ||
| 1397 | 'addexit' => 'NS;S', | ||
| 1398 | 'addfirstroom' => '', | ||
| 1399 | 'addlabel' => 'SNNN', | ||
| 1400 | 'addregion' => 'S', | ||
| 1401 | 'addroom' => 'NNN', | ||
| 1402 | 'addtempregion' => ';S', | ||
| 1403 | 'addtwinexit' => 'N', | ||
| 1404 | 'closemap' => '', | ||
| 1405 | 'connectexit' => 'NN', | ||
| 1406 | 'counttask' => 'S', | ||
| 1407 | 'delexit' => 'N', | ||
| 1408 | 'delregion' => 'S', | ||
| 1409 | 'delroom' => 'N', | ||
| 1410 | 'deltempregions' => '', | ||
| 1411 | 'disconnectexit' => 'N', | ||
| 1412 | 'getexitdest' => 'N', | ||
| 1413 | 'getexitnum' => 'N', | ||
| 1414 | 'getexittwin' => 'N', | ||
| 1415 | 'getlostroom' => '', | ||
| 1416 | 'getobjectalive' => 'N', | ||
| 1417 | 'getobjectcount' => 'N', | ||
| 1418 | 'getregionnum' => '', | ||
| 1419 | 'getroomexits' => '', | ||
| 1420 | 'getroomnum' => '', | ||
| 1421 | 'getroomobjects' => ';S', | ||
| 1422 | 'ifacecount' => '', | ||
| 1423 | 'ifacedefined' => 'N', | ||
| 1424 | 'ifacepos' => '', | ||
| 1425 | 'ifacenum' => '', | ||
| 1426 | 'ifacestrings' => '', | ||
| 1427 | 'ifacetime' => '', | ||
| 1428 | 'isexit' => 'N', | ||
| 1429 | 'isfinished' => 'S', | ||
| 1430 | 'ishiddenexit' => 'N', | ||
| 1431 | 'isregion' => 'S', | ||
| 1432 | 'isroom' => 'N', | ||
| 1433 | 'isscript' => '', | ||
| 1434 | 'ismap' => '', | ||
| 1435 | 'istask' => '', | ||
| 1436 | 'istempregion' => 'S', | ||
| 1437 | 'iswin' => '', | ||
| 1438 | 'openmap' => '', | ||
| 1439 | 'sethiddenexit' => 'N', | ||
| 1440 | 'setlight' => 'S', | ||
| 1441 | 'setmapmode' => 'S', | ||
| 1442 | 'setornament' => 'N;S', | ||
| 1443 | 'setrandomexit' => 'N;S', | ||
| 1444 | 'setregion' => 'S', | ||
| 1445 | 'setregionnum' => 'N', | ||
| 1446 | 'setroomnum' => ';N', | ||
| 1447 | 'setroomtagged' => ';S', | ||
| 1448 | 'timestamp' => '', | ||
| 1449 | # Axmud-dependent functions (returning a string value) | ||
| 1450 | 'abbrevdir$' => 'S', | ||
| 1451 | 'clientdate$' => '', | ||
| 1452 | 'clientname$' => '', | ||
| 1453 | 'clientversion$' => '', | ||
| 1454 | 'findtask$' => 'S', | ||
| 1455 | 'getexit$' => 'N', | ||
| 1456 | 'getexitdrawn$' => 'N', | ||
| 1457 | 'getexitstatus$' => 'N', | ||
| 1458 | 'getexittype$' => 'N', | ||
| 1459 | 'getlight$' => '', | ||
| 1460 | 'getmapmode$' => '', | ||
| 1461 | 'getobject$' => 'N', | ||
| 1462 | 'getobjectnoun$' => 'N', | ||
| 1463 | 'getobjecttype$' => 'N', | ||
| 1464 | 'getornament$' => 'N', | ||
| 1465 | 'getrandomexit$' => 'N', | ||
| 1466 | 'getregion$' => '', | ||
| 1467 | 'getroomdescrip$' => ';S', | ||
| 1468 | 'getroomguild$' => '', | ||
| 1469 | 'getroomsource$' => '', | ||
| 1470 | 'getroomtag$' => '', | ||
| 1471 | 'getroomtitle$' => '', | ||
| 1472 | 'iface$' => '', | ||
| 1473 | 'ifacedata$' => '', | ||
| 1474 | 'ifacename$' => '', | ||
| 1475 | 'ifacepop$' => '', | ||
| 1476 | 'ifaceselect$' => 'N', | ||
| 1477 | 'ifaceshift$' => '', | ||
| 1478 | 'ifacetext$' => '', | ||
| 1479 | 'ifacetype$' => '', | ||
| 1480 | 'popup$' => 'SSS', | ||
| 1481 | 'scriptname$' => '', | ||
| 1482 | 'showprofile$' => '', | ||
| 1483 | 'unabbrevdir$' => 'S', | ||
| 1484 | }, | ||
| 1485 | # While parsing the script (in $self->parse), we need to keep track of whether the line | ||
| 1486 | # being parsed is within a subroutine declaration, or whether it is outside one - so | ||
| 1487 | # that we can detect subroutines declared inside another, and respond to correctly to | ||
| 1488 | # an END SUB | ||
| 1489 | # While parsing statements inside a subroutine declaration, this IV stores the | ||
| 1490 | # LA::Subroutine. While parsing statements outside a subroutine declaration (but | ||
| 1491 | # inside the implied *main subroutine), this IV is set to 'undef' | ||
| 1492 | currentParseSub => undef, | ||
| 1493 | |||
| 1494 | # Needed by a few statements (most notably PRINT statements) to display stuff in the | ||
| 1495 | # way that BASIC is accustomed to displaying stuff | ||
| 1496 | column => 0, | ||
| 1497 | |||
| 1498 | # Variable declare mode | ||
| 1499 | # When $self->parse processes a variable, it calls LA::Variable->lookup to find the | ||
| 1500 | # LA::Variable in LA::Subroutine's ->localScalarHash / ->localArrayHash. If it's not | ||
| 1501 | # there, it looks in this object's ->globalScalarHash / ->globalArrayHash | ||
| 1502 | # If the variable isn't there, it hasn't been declared yet. In execution mode | ||
| 1503 | # 'no_line_num', variables must be declared with GLOBAL or LOCAL statements before | ||
| 1504 | # being used. (In execution mode 'line_num' (primitive line numbers), all variables | ||
| 1505 | # are global and don't have to be declared, so this IV is ignored) | ||
| 1506 | # This IV is normally set to 'default'. When $self->parse is processing a GLOBAL | ||
| 1507 | # statement, it is briefly set to 'global_scalar' (for scalars) or 'global_array' (for | ||
| 1508 | # arrays). When processing a LOCAL or SUB statement, it is briefly set to | ||
| 1509 | # 'local_scalar' (for scalars) or 'local_array' (for arrays). When processing a PEEK | ||
| 1510 | # or PEEK... statement, it is briefly set to 'peek_scalar' (for scalars) or | ||
| 1511 | # 'peek_array' (for arrays) | ||
| 1512 | # When processing a FOR EACH, POP, PUSH, SHIFT or UNSHIFT statement, or a SORT statement | ||
| 1513 | # (or similar), it is set to 'simple' | ||
| 1514 | # A non-'default' value tells ->lookup to declare the variable by adding it one of the | ||
| 1515 | # declared variable hashes. Otherwise, when the script refers to an undeclared | ||
| 1516 | # variable, an error is produced | ||
| 1517 | declareMode => 'default', | ||
| 1518 | # Global variable hashes | ||
| 1519 | # A hash of global scalar variables, in the form | ||
| 1520 | # $globalScalarHash{scalar_name} = blessed_reference_to_scalar_object | ||
| 1521 | # (The object is a LA::Variable::Scalar::String or LA::Variable::Scalar::Numeric) | ||
| 1522 | globalScalarHash => {}, | ||
| 1523 | # A hash of global array variables, in the form | ||
| 1524 | # $globalArrayHash{array_name} = blessed_reference_to_array_object | ||
| 1525 | # (The object is a LA::Variable::Array::String or LA::Variable::Array::Numeric) | ||
| 1526 | globalArrayHash => {}, | ||
| 1527 | |||
| 1528 | # Global data list - all the values in DATA statements, which are gathered by | ||
| 1529 | # $self->parse and stored here until a READ statement accesses them | ||
| 1530 | globalDataList => [], | ||
| 1531 | # The same data list, with items removed by successive READ statements. The whole list | ||
| 1532 | # is reset to match the contents of ->globalDataList by a RESTORE statement | ||
| 1533 | readDataList => [], | ||
| 1534 | |||
| 1535 | # Hash of LA::FileChannel objects, each one representing a data file opened with an | ||
| 1536 | # OPEN statement. Hash in the form | ||
| 1537 | # $fileChannelHash{number} = blessed_reference_to_file_channel_object | ||
| 1538 | fileChannelHash => {}, | ||
| 1539 | |||
| 1540 | # Hash of things declared with the OPTION statement | ||
| 1541 | # KEY VALUE | ||
| 1542 | # angle radians (default) / degrees | ||
| 1543 | # | ||
| 1544 | # - Specifies the type of angle measure used with trigonometric and graphics | ||
| 1545 | # functions | ||
| 1546 | # | ||
| 1547 | # needtask FALSE (default) / TRUE | ||
| 1548 | # | ||
| 1549 | # - Script refuses to run without a parent task, if TRUE | ||
| 1550 | # | ||
| 1551 | # nolet FALSE (default) / TRUE | ||
| 1552 | # | ||
| 1553 | # - Allows LET keyword to be omitted, if TRUE | ||
| 1554 | # | ||
| 1555 | # persist FALSE (default) / TRUE | ||
| 1556 | # | ||
| 1557 | # - Independent triggers (etc) not destroyed when the script ends, if TRUE | ||
| 1558 | # | ||
| 1559 | # pseudo 'show_all' / 'hide_complete' (default) / 'hide_system' / 'win_error' | ||
| 1560 | # / 'win_only' | ||
| 1561 | # | ||
| 1562 | # - Sets ->pseudoCmdMode (so value in ->optionStatementHash not used) | ||
| 1563 | # | ||
| 1564 | # redirect FALSE (default) / TRUE | ||
| 1565 | # | ||
| 1566 | # - If task window is not open, WRITEWIN statements redirect their output to the | ||
| 1567 | # 'main' window | ||
| 1568 | # | ||
| 1569 | # require 0 / float (e.g. 1.0) | ||
| 1570 | # | ||
| 1571 | # - Script refuses to run unless global variable $BASIC_VERSION >= float | ||
| 1572 | # | ||
| 1573 | # silent FALSE (default) / TRUE | ||
| 1574 | # | ||
| 1575 | # - Script does not display messages like 'AXBASIC: Executing 'test'' or | ||
| 1576 | # 'AXBASIC: Execution of 'test' complete' | ||
| 1577 | # | ||
| 1578 | # typo FALSE (default) / TRUE | ||
| 1579 | # | ||
| 1580 | # - Allows GLOBAL/LOCAL variable declarations to be omitted, if TRUE. Ignored in | ||
| 1581 | # scripts with line numbers | ||
| 1582 | optionStatementHash => { | ||
| 1583 | 'angle' => 'radians', | ||
| 1584 | 'needtask' => FALSE, | ||
| 1585 | 'nolet' => FALSE, | ||
| 1586 | 'persist' => FALSE, | ||
| 1587 | 'pseudo' => 'hide_complete', # If changed, also set ->pseudoCmdMode | ||
| 1588 | 'redirect' => FALSE, | ||
| 1589 | 'require' => 0, | ||
| 1590 | 'silent' => FALSE, | ||
| 1591 | 'typo' => FALSE, | ||
| 1592 | }, | ||
| 1593 | |||
| 1594 | # List of variables which are expecting to be set by something the user types | ||
| 1595 | # Every item on the list is a LA::Variable to set | ||
| 1596 | inputList => [], | ||
| 1597 | # For statements that interact with Axmud directly, the pseudo command mode to use | ||
| 1598 | # NB If the default value is changed, the corresponding value in ->optionStatementHash | ||
| 1599 | # must also be changed, and so must the help for OPTION statements | ||
| 1600 | # pseudoCmdMode => 'show_all', # Show all client command messages | ||
| 1601 | pseudoCmdMode => 'hide_complete', # Ignore success messages, show errors | ||
| 1602 | # Flag set to TRUE when the parent task's own ->forcedWinFlag is set to TRUE (set to | ||
| 1603 | # FALSE otherwise) | ||
| 1604 | # In 'forced window' mode, the task opens an 'entry' task window before starting to | ||
| 1605 | # execute the script. This script then redirects the output from PRINT statements to | ||
| 1606 | # the task window. This allows the user to run old BASIC scripts - which obviously | ||
| 1607 | # don't know how to open Axmud task windows - in their own window, away from the | ||
| 1608 | # 'main' window | ||
| 1609 | forcedWinFlag => FALSE, | ||
| 1610 | # All Axbasic scripts must have one, and only one, END statement. When | ||
| 1611 | # LA::Statement::end->parse() is run, it checks that this IV is FALSE. If so, it is | ||
| 1612 | # set to TRUE; however, if it was already set to TRUE, we get an error | ||
| 1613 | endStatementFlag => FALSE, | ||
| 1614 | # The name of the profile (matches a key in GA::Session->profHash) which is used by | ||
| 1615 | # ADDTRIG (etc) and DELTRIG (etc) statements. The default value of the IV is 'undef', | ||
| 1616 | # which means 'use the current world profile'. Otherwise, the specified profile is | ||
| 1617 | # used | ||
| 1618 | useProfile => undef, | ||
| 1619 | }; | ||
| 1620 | |||
| 1621 | # Bless the object into existence | ||
| 1622 | bless $self, $class; | ||
| 1623 | |||
| 1624 | # Initialise intrinsic functions | ||
| 1625 | if (! Language::Axbasic::Function::Intrinsic->initialise($self)) { | ||
| 1626 | |||
| 1627 | # This error is fatal | ||
| 1628 | return undef; | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | # Download the specified raw script, if it was specified | ||
| 1632 | if ($rawScriptObj) { | ||
| 1633 | |||
| 1634 | if (! $rawScriptObj->upload($self)) { | ||
| 1635 | |||
| 1636 | # Download failed. Display any error messages | ||
| 1637 | if ($self->errorList) { | ||
| 1638 | |||
| 1639 | $self->terminateExecution(); | ||
| 1640 | } | ||
| 1641 | |||
| 1642 | return undef; | ||
| 1643 | |||
| 1644 | } else { | ||
| 1645 | |||
| 1646 | # Download complete. Remember the name of the raw script and the file path from | ||
| 1647 | # which the script was loaded | ||
| 1648 | $self->ivPoke('name', $rawScriptObj->name); | ||
| 1649 | $self->ivPoke('filePath', $rawScriptObj->filePath); | ||
| 1650 | |||
| 1651 | return $self; | ||
| 1652 | } | ||
| 1653 | |||
| 1654 | } else { | ||
| 1655 | |||
| 1656 | # Don't download a raw script | ||
| 1657 | return $self; | ||
| 1658 | } | ||
| 1659 | } | ||
| 1660 | |||
| 1661 | ################## | ||
| 1662 | # Methods | ||
| 1663 | |||
| 1664 | sub parse { | ||
| 1665 | |||
| 1666 | # Parses the script, looping over the lines and parsing each line in turn | ||
| 1667 | # Can be called independently, in which it serves as a basic syntax checker, or can be | ||
| 1668 | # called by $self->implement, right before the script is executed | ||
| 1669 | # | ||
| 1670 | # Expected arguments | ||
| 1671 | # (none besides $self) | ||
| 1672 | # | ||
| 1673 | # Return values | ||
| 1674 | # 'undef' on improper arguments | ||
| 1675 | # 1 if the script is parsed without an error | ||
| 1676 | |||
| 1677 | my ($self, $check) = @_; | ||
| 1678 | |||
| 1679 | # Local variables | ||
| 1680 | my ($lineObj, $mainSubObj); | ||
| 1681 | |||
| 1682 | # Check for improper arguments | ||
| 1683 | if (defined $check) { | ||
| 1684 | |||
| 1685 | $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_); | ||
| 1686 | # Display the error message immediately, and halt execution | ||
| 1687 | return $self->terminateExecution(); | ||
| 1688 | } | ||
| 1689 | |||
| 1690 | # Only permit parsing of the script once | ||
| 1691 | if ($self->scriptStatus ne 'waiting') { | ||
| 1692 | |||
| 1693 | $self->setDebug('Script already parsed', $self->_objClass . '->parse'); | ||
| 1694 | # Display the error message immediately, and halt execution | ||
| 1695 | return $self->terminateExecution(); | ||
| 1696 | } | ||
| 1697 | |||
| 1698 | # Create the first subroutine (the equivalent of a main() function in many languages). This | ||
| 1699 | # subroutine is implied and doesn't actually appear in the Axbasic code | ||
| 1700 | $mainSubObj = Language::Axbasic::Subroutine->new($self, '*main'); | ||
| 1701 | if (! $mainSubObj) { | ||
| 1702 | |||
| 1703 | $self->setDebug('Can\'t create *main subroutine', $self->_objClass . '->parse'); | ||
| 1704 | # Display the error message immediately, and halt execution | ||
| 1705 | return $self->terminateExecution(); | ||
| 1706 | |||
| 1707 | } else { | ||
| 1708 | |||
| 1709 | # This subroutine is the first one in the stack | ||
| 1710 | $self->ivPush('subStackList', $mainSubObj); | ||
| 1711 | $self->ivPoke('subCount', 1); | ||
| 1712 | |||
| 1713 | $mainSubObj->set_stackPosn(0); | ||
| 1714 | |||
| 1715 | # We keep track of the current subroutine being parsed, but set this IV to 'undef' when | ||
| 1716 | # we're in the implied *main subroutine | ||
| 1717 | $self->ivUndef('currentParseSub'); | ||
| 1718 | } | ||
| 1719 | |||
| 1720 | # Mark the Axbasic script status as 'parsing' (being parsed/implemented), and the execution | ||
| 1721 | # status as 1 (being parsed, not implemented) | ||
| 1722 | $self->ivPoke('scriptStatus', 'parsing'); | ||
| 1723 | $self->ivPoke('executionStatus', 'parse'); | ||
| 1724 | |||
| 1725 | # Execution begins at line 1 | ||
| 1726 | $self->ivPoke('currentLine', 1); | ||
| 1727 | |||
| 1728 | # Parse the script by parsing each line in turn | ||
| 1729 | while ($self->scriptStatus eq 'parsing') { | ||
| 1730 | |||
| 1731 | # Get the LA::Line object which is the next to be parsed | ||
| 1732 | $lineObj = $self->ivShow('lineHash', $self->currentLine); | ||
| 1733 | if (! defined $lineObj) { | ||
| 1734 | |||
| 1735 | $self->setDebug('Missing line object', $self->_objClass . '->parse'); | ||
| 1736 | # Display the error message immediately, and halt execution | ||
| 1737 | return $self->terminateExecution(); | ||
| 1738 | } | ||
| 1739 | |||
| 1740 | # Parse the line | ||
| 1741 | if ($self->executionStatus eq 'finished' || ! defined $lineObj->parse()) { | ||
| 1742 | |||
| 1743 | # Execution has halted, either because the script has finished, or because of an | ||
| 1744 | # error | ||
| 1745 | return $self->terminateExecution(); | ||
| 1746 | } | ||
| 1747 | |||
| 1748 | # Get the next line to be parsed | ||
| 1749 | if (! defined $self->nextLine) { | ||
| 1750 | |||
| 1751 | if (! $self->ivExists('lineHash', ($lineObj->procLineNum + 1))) { | ||
| 1752 | |||
| 1753 | # Parsing is complete. Check there is exactly one END statement in the script, | ||
| 1754 | # and return the result | ||
| 1755 | return $self->checkEndStatements(); | ||
| 1756 | |||
| 1757 | } else { | ||
| 1758 | |||
| 1759 | # Use the line immediately after $lineObj | ||
| 1760 | $self->ivPoke('currentLine', $lineObj->procLineNum + 1); | ||
| 1761 | } | ||
| 1762 | |||
| 1763 | } else { | ||
| 1764 | |||
| 1765 | # $self->nextLine has been set by something, so parse that line on the next loop | ||
| 1766 | $self->ivPoke('currentLine', $self->nextLine); | ||
| 1767 | $self->ivUndef('nextLine'); | ||
| 1768 | } | ||
| 1769 | } | ||
| 1770 | |||
| 1771 | # Parsing is complete. Check there is exactly one END statement in the script, and return | ||
| 1772 | # the result | ||
| 1773 | return $self->checkEndStatements(); | ||
| 1774 | } | ||
| 1775 | |||
| 1776 | sub implement { | ||
| 1777 | |||
| 1778 | # Implements (executes) the Axbasic script | ||
| 1779 | # Once this object has been created (with a call to $self->new), can be called by anything | ||
| 1780 | # to start implementing (executing) the script | ||
| 1781 | # If the script pauses for any reason (usually because it's being run by an Axmud 'Script' | ||
| 1782 | # task), can be called again to resume implementation | ||
| 1783 | # Is also called by GA::Session->taskLoop when a paused script must be resumed | ||
| 1784 | # | ||
| 1785 | # Expected arguments | ||
| 1786 | # (none besides $self) | ||
| 1787 | # | ||
| 1788 | # Return values | ||
| 1789 | # 'undef' on improper arguments, or if the first subroutine can't be created, or if any | ||
| 1790 | # functions called (and any functions they call in turn) return an error or if this | ||
| 1791 | # function is called recursively | ||
| 1792 | # 1 if the script is implemented (executed) without an error or if it gets paused before | ||
| 1793 | # encountering an error | ||
| 1794 | |||
| 1795 | my ($self, $check) = @_; | ||
| 1796 | |||
| 1797 | # Local variables | ||
| 1798 | my ($lineObj, $nextLine, $currentStatement); | ||
| 1799 | |||
| 1800 | # Check for improper arguments | ||
| 1801 | if (defined $check) { | ||
| 1802 | |||
| 1803 | $axmud::CLIENT->writeImproper($self->_objClass . '->implement', @_); | ||
| 1804 | # Display the error message immediately, and halt execution | ||
| 1805 | return $self->terminateExecution(); | ||
| 1806 | } | ||
| 1807 | |||
| 1808 | # If this function is called recursively, do nothing. (Don't return an error; if this | ||
| 1809 | # function is being called by the Script task, we want it to call again on the next task | ||
| 1810 | # loop) | ||
| 1811 | if ($self->implementFlag) { | ||
| 1812 | |||
| 1813 | return undef; | ||
| 1814 | |||
| 1815 | } else { | ||
| 1816 | |||
| 1817 | # Prevent any part of the Axmud code from calling this function recursively; the flag is | ||
| 1818 | # set back to FALSE when this function ends | ||
| 1819 | $self->ivPoke('implementFlag', TRUE); | ||
| 1820 | } | ||
| 1821 | |||
| 1822 | # If this function is being called for the first time (executing the script from the | ||
| 1823 | # start)... | ||
| 1824 | if ($self->scriptStatus eq 'waiting') { | ||
| 1825 | |||
| 1826 | # Parse the script | ||
| 1827 | if (! $self->parse()) { | ||
| 1828 | |||
| 1829 | # Parsing failed - cannot continue | ||
| 1830 | $self->ivPoke('implementFlag', FALSE); | ||
| 1831 | return undef; | ||
| 1832 | } | ||
| 1833 | |||
| 1834 | # The script has had an opportunity to set OPTION SILENT, so we now show a confirmation | ||
| 1835 | if (! $self->ivShow('optionStatementHash', 'silent')) { | ||
| 1836 | |||
| 1837 | $self->session->writeText('AXBASIC: Executing \'' . $self->name . '\''); | ||
| 1838 | } | ||
| 1839 | |||
| 1840 | # Mark the Axbasic script status as 'parsing' (being parsed/implemented), and the | ||
| 1841 | # execution status as 2 (being implemented, not merely parsed) | ||
| 1842 | $self->ivPoke('scriptStatus', 'parsing'); | ||
| 1843 | $self->ivPoke('executionStatus', 'implement'); | ||
| 1844 | |||
| 1845 | # Execution begins at line 1 | ||
| 1846 | $self->ivPoke('currentLine', 1); | ||
| 1847 | $self->ivPoke('nextLine', undef); | ||
| 1848 | $self->ivPoke( | ||
| 1849 | 'nextStatement', | ||
| 1850 | $self->ivShow('lineHash', ($self->currentLine))->firstStatement, | ||
| 1851 | ); | ||
| 1852 | |||
| 1853 | # Empty the stacks (but retain the implied *main subroutine which is always the first | ||
| 1854 | # subroutine in the stack), and set the display column to 0 | ||
| 1855 | $self->ivPoke('subStackList', $self->ivShow('subNameHash', '*main')); | ||
| 1856 | $self->ivPoke('subCount', 0); | ||
| 1857 | $self->ivPoke('column', 0); | ||
| 1858 | |||
| 1859 | # If this function is being called again (resuming execution after a pause)... | ||
| 1860 | } elsif ($self->scriptStatus eq 'paused') { | ||
| 1861 | |||
| 1862 | # Mark the Axbasic script status as 'parsing' (being implemented) | ||
| 1863 | $self->ivPoke('scriptStatus', 'parsing'); | ||
| 1864 | |||
| 1865 | # If this function is being called again (resuming execution after pausing while waiting for | ||
| 1866 | # INPUT) | ||
| 1867 | } elsif ($self->scriptStatus eq 'wait_input') { | ||
| 1868 | |||
| 1869 | # Input has been received. Mark the Axbasic script status as 1 (being implemented) | ||
| 1870 | $self->ivPoke('scriptStatus', 'parsing'); | ||
| 1871 | |||
| 1872 | # If this function is being called again (resuming execution after halting, while waiting | ||
| 1873 | # for the parent task to monitor another task)... | ||
| 1874 | } elsif ($self->scriptStatus eq 'wait_status') { | ||
| 1875 | |||
| 1876 | # The parent task has finished monitoring another task. Mark the Axbasic script status | ||
| 1877 | # as 1 (being implemented) | ||
| 1878 | $self->ivPoke('scriptStatus', 'parsing'); | ||
| 1879 | |||
| 1880 | # Error: called when the Axbasic script status is 'parsing' (script is being parsed or | ||
| 1881 | # implemented) or when its execution status is 'implement' (actually executing the script, | ||
| 1882 | # don't just checking it for errors) | ||
| 1883 | } elsif ($self->scriptStatus eq 'parsing' && $self->executionStatus eq 'implement') { | ||
| 1884 | |||
| 1885 | $self->setDebug( | ||
| 1886 | 'Language::Axbasic::Script->implement called, but script status is already 1', | ||
| 1887 | $self->_objClass . '->implement', | ||
| 1888 | ); | ||
| 1889 | |||
| 1890 | # Display the error message immediately, and halt execution | ||
| 1891 | $self->ivPoke('implementFlag', FALSE); | ||
| 1892 | return $self->terminateExecution(); | ||
| 1893 | |||
| 1894 | # Error: called when execution has already finished (status = 3, 4 or 5) | ||
| 1895 | } else { | ||
| 1896 | |||
| 1897 | $self->setDebug( | ||
| 1898 | 'Language::Axbasic::Script->implement called, but execution already finished', | ||
| 1899 | $self->_objClass . '->implement', | ||
| 1900 | ); | ||
| 1901 | |||
| 1902 | # Display the error message immediately, and halt execution | ||
| 1903 | $self->ivPoke('implementFlag', FALSE); | ||
| 1904 | return $self->terminateExecution(); | ||
| 1905 | } | ||
| 1906 | |||
| 1907 | # When the script is being run from within a task, ->parentTask is set | ||
| 1908 | if ($self->parentTask) { | ||
| 1909 | |||
| 1910 | # Count the number of steps taken (statements executed) during each task loop | ||
| 1911 | $self->ivPoke('stepCount', 0); | ||
| 1912 | } | ||
| 1913 | |||
| 1914 | # Loop over statements for as long as there are statements to execute | ||
| 1915 | do { | ||
| 1916 | |||
| 1917 | if ($self->nextStatement->implement()) { | ||
| 1918 | |||
| 1919 | # On lines with multiple statements, use the next statement on the line if there is | ||
| 1920 | # one (otherwise $self->nextStatement is set to 'undef') | ||
| 1921 | if (defined $self->nextStatement) { | ||
| 1922 | |||
| 1923 | $self->ivPoke('nextStatement', $self->nextStatement->nextStatement); | ||
| 1924 | } | ||
| 1925 | } | ||
| 1926 | |||
| 1927 | if (defined $self->nextStatement) { | ||
| 1928 | |||
| 1929 | # Set the new current line (which might be the same as the old one) | ||
| 1930 | $self->ivPoke('currentLine', $self->nextStatement->lineObj->procLineNum); | ||
| 1931 | |||
| 1932 | } else { | ||
| 1933 | |||
| 1934 | if (defined $self->nextLine) { | ||
| 1935 | |||
| 1936 | # Some other part of the code has specified the new current line | ||
| 1937 | $self->ivPoke('currentLine', $self->nextLine); | ||
| 1938 | $self->ivUndef('nextLine'); | ||
| 1939 | $self->ivPoke( | ||
| 1940 | 'nextStatement', | ||
| 1941 | $self->ivShow('lineHash', ($self->currentLine))->firstStatement, | ||
| 1942 | ); | ||
| 1943 | |||
| 1944 | } elsif ( | ||
| 1945 | $self->scriptStatus eq 'parsing' | ||
| 1946 | || $self->scriptStatus eq 'paused' | ||
| 1947 | || $self->scriptStatus eq 'wait_input' | ||
| 1948 | || $self->scriptStatus eq 'wait_status' | ||
| 1949 | ) { | ||
| 1950 | # Script is at the end of a line | ||
| 1951 | $self->ivPoke('currentLine', $self->currentLine + 1); | ||
| 1952 | $self->ivPoke( | ||
| 1953 | 'nextStatement', | ||
| 1954 | $self->ivShow('lineHash', ($self->currentLine))->firstStatement, | ||
| 1955 | ); | ||
| 1956 | } | ||
| 1957 | } | ||
| 1958 | |||
| 1959 | # If the script is being run by a task (and if the script must periodically be paused | ||
| 1960 | # while waiting for the next task loop), check if it's time to pause (but not if the | ||
| 1961 | # script is already marked as paused/waiting for input or if execution has halted) | ||
| 1962 | if ( | ||
| 1963 | $self->parentTask | ||
| 1964 | && $self->executionStatus ne 'finished' | ||
| 1965 | && $self->scriptStatus ne 'paused' | ||
| 1966 | && $self->scriptStatus ne 'wait_input' | ||
| 1967 | ) { | ||
| 1968 | # Another statement has been executed | ||
| 1969 | $self->ivIncrement('stepCount'); | ||
| 1970 | |||
| 1971 | if ($self->stepMax && $self->stepCount >= $self->stepMax) { | ||
| 1972 | |||
| 1973 | # It's time to pause until the next task loop | ||
| 1974 | $self->ivPoke('scriptStatus', 'paused'); | ||
| 1975 | } | ||
| 1976 | } | ||
| 1977 | |||
| 1978 | # Continue implementing statements until script execution halts, pauses, halts to allow the | ||
| 1979 | # parent task to monitor another task (=6) or pauses while expecting INPUT | ||
| 1980 | } until ( | ||
| 1981 | $self->executionStatus eq 'finished' | ||
| 1982 | || $self->scriptStatus eq 'paused' | ||
| 1983 | || $self->scriptStatus eq 'wait_input' | ||
| 1984 | || $self->scriptStatus eq 'wait_status' | ||
| 1985 | ); | ||
| 1986 | |||
| 1987 | # Implementation complete (or script paused) | ||
| 1988 | $self->ivPoke('implementFlag', FALSE); | ||
| 1989 | |||
| 1990 | if ($self->executionStatus eq 'finished') { | ||
| 1991 | |||
| 1992 | return $self->terminateExecution(); | ||
| 1993 | |||
| 1994 | } else { | ||
| 1995 | |||
| 1996 | return 1; | ||
| 1997 | } | ||
| 1998 | } | ||
| 1999 | |||
| 2000 | sub setError { | ||
| 2001 | |||
| 2002 | # Can be called by any Language::Axbasic:: function whenever it notices an error caused by | ||
| 2003 | # the Axbasic script (errors probably caused by this Perl code should be addressed by | ||
| 2004 | # calling $self->setDebug) | ||
| 2005 | # Creates a LA::Error object to store details of the error, so that all error messages can | ||
| 2006 | # be displayed together when control is passed back to LA::Script | ||
| 2007 | # The calling function should then return 'undef', which trickles back down to | ||
| 2008 | # LA::Script->parse or LA::Script->implement, one of which actually displays the | ||
| 2009 | # error message(s) stored in LA::Script->errorList | ||
| 2010 | # | ||
| 2011 | # Expected arguments | ||
| 2012 | # $errorCode - The error message to display, e.g. 'syntax_error' | ||
| 2013 | # $func - A string describing the function that generated the error (e.g. | ||
| 2014 | # 'Language::Axbasic::Statement->parse') | ||
| 2015 | # | ||
| 2016 | # Optional arguments | ||
| 2017 | # %errorHash - A hash of arguments used to substitute words in $errorCode (see the | ||
| 2018 | # comments in LA::Error; can be an empty hash) | ||
| 2019 | # | ||
| 2020 | # Return values | ||
| 2021 | # 'undef' | ||
| 2022 | |||
| 2023 | my ($self, $errorCode, $func, %errorHash) = @_; | ||
| 2024 | |||
| 2025 | # Local variables | ||
| 2026 | my $errorObj; | ||
| 2027 | |||
| 2028 | # Check for improper arguments | ||
| 2029 | if (! defined $errorCode || ! defined $func) { | ||
| 2030 | |||
| 2031 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setError', @_); | ||
| 2032 | } | ||
| 2033 | |||
| 2034 | # Create an error object and add it to this script object's error list | ||
| 2035 | $errorObj = Language::Axbasic::Error->new( | ||
| 2036 | $self, | ||
| 2037 | 'error', | ||
| 2038 | $errorCode, | ||
| 2039 | $func, | ||
| 2040 | $self->currentLine, | ||
| 2041 | %errorHash, | ||
| 2042 | ); | ||
| 2043 | |||
| 2044 | if ($errorObj) { | ||
| 2045 | |||
| 2046 | $self->ivPush('errorList', $errorObj); | ||
| 2047 | } | ||
| 2048 | |||
| 2049 | # Set status IVs (but only if they haven't been set by a previous error - the status IVs | ||
| 2050 | # only record the first error message received) | ||
| 2051 | if ($self->executionStatus ne 'finished') { | ||
| 2052 | |||
| 2053 | # 5 signifies a Axbasic script error | ||
| 2054 | $self->ivPoke('scriptStatus', 'basic_error'); | ||
| 2055 | # 3 signifies execution has finished | ||
| 2056 | $self->ivPoke('executionStatus', 'finished'); | ||
| 2057 | } | ||
| 2058 | |||
| 2059 | # This return value should trickle all the way down to LA::Script->parse or | ||
| 2060 | # LA::Script->implement, one of which actually displays the error message | ||
| 2061 | return undef; | ||
| 2062 | } | ||
| 2063 | |||
| 2064 | sub setDebug { | ||
| 2065 | |||
| 2066 | # Can be called by any Language::Axbasic:: function whenever it notices an error probably | ||
| 2067 | # caused by the Perl code (errors caused by the Axbasic script should be addressed by | ||
| 2068 | # calling $self->setError) | ||
| 2069 | # Creates a LA::Error object to store details of the error, so that all error messages can | ||
| 2070 | # be displayed together when control is passed back to LA::Script | ||
| 2071 | # The calling function should then return 'undef', which trickles back down to | ||
| 2072 | # LA::Script->parse or LA::Script->implement, one of which actually displays the | ||
| 2073 | # error message(s) stored in LA::Script->errorList | ||
| 2074 | # | ||
| 2075 | # Expected arguments | ||
| 2076 | # $errorCode - The error message to display, e.g. 'syntax_error' | ||
| 2077 | # $func - A string describing the function that generated the error (e.g. | ||
| 2078 | # 'Axbasic::Statement->parse') | ||
| 2079 | # | ||
| 2080 | # Optional arguments | ||
| 2081 | # %errorHash - A hash of arguments used to substitute words in $errorCode (see the | ||
| 2082 | # comments in LA::Error; can be an empty hash) | ||
| 2083 | # | ||
| 2084 | # Return values | ||
| 2085 | # 'undef' | ||
| 2086 | |||
| 2087 | my ($self, $errorCode, $func, %errorHash) = @_; | ||
| 2088 | |||
| 2089 | # Local variables | ||
| 2090 | my $errorObj; | ||
| 2091 | |||
| 2092 | # Check for improper arguments | ||
| 2093 | if (! defined $errorCode || ! defined $func) { | ||
| 2094 | |||
| 2095 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setDebug', @_); | ||
| 2096 | } | ||
| 2097 | |||
| 2098 | # Create an error object and add it to this script object's error list | ||
| 2099 | $errorObj = Language::Axbasic::Error->new( | ||
| 2100 | $self, | ||
| 2101 | 'debug', | ||
| 2102 | $errorCode, | ||
| 2103 | $func, | ||
| 2104 | $self->currentLine, | ||
| 2105 | %errorHash, | ||
| 2106 | ); | ||
| 2107 | |||
| 2108 | if ($errorObj) { | ||
| 2109 | |||
| 2110 | $self->ivPush('errorList', $errorObj); | ||
| 2111 | } | ||
| 2112 | |||
| 2113 | # Set status IVs (but only if they haven't been set by a previous error - the status IVs | ||
| 2114 | # only record the first error message received) | ||
| 2115 | if ($self->executionStatus ne 'finished') { | ||
| 2116 | |||
| 2117 | # 6 signifies a probably Perl code error | ||
| 2118 | $self->ivPoke('scriptStatus', 'perl_error'); | ||
| 2119 | # 3 signifies execution has finished | ||
| 2120 | $self->ivPoke('executionStatus', 'finished'); | ||
| 2121 | } | ||
| 2122 | |||
| 2123 | # This return value should trickle all the way down to LA::Script->parse or | ||
| 2124 | # LA::Script->implement, one of which actually displays the error message | ||
| 2125 | return undef; | ||
| 2126 | } | ||
| 2127 | |||
| 2128 | sub checkEndStatements { | ||
| 2129 | |||
| 2130 | # Called by $self->parse | ||
| 2131 | # Check that there is exactly one END statement in the Axbasic script | ||
| 2132 | # (Multiple END statements are picked up by LA::Statement::end->parse, so we don't need to | ||
| 2133 | # check for that possibility) | ||
| 2134 | # | ||
| 2135 | # Expected arguments | ||
| 2136 | # (none besides $self) | ||
| 2137 | # | ||
| 2138 | # Return values | ||
| 2139 | # 'undef' on improper arguments or if there are no END statements in the script | ||
| 2140 | # 1 otherwise | ||
| 2141 | |||
| 2142 | my ($self, $check) = @_; | ||
| 2143 | |||
| 2144 | # Check for improper arguments | ||
| 2145 | if (defined $check) { | ||
| 2146 | |||
| 2147 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkEndStatements', @_); | ||
| 2148 | } | ||
| 2149 | |||
| 2150 | if (! $self->endStatementFlag) { | ||
| 2151 | |||
| 2152 | # Because the call to this function might be the last thing that $self->parse does, if | ||
| 2153 | # there's an error, we have to call ->terminateExecution ourselves | ||
| 2154 | $self->setError( | ||
| 2155 | 'Axbasic script does not contain an END statement', | ||
| 2156 | $self->_objClass . '->checkEndStatements', | ||
| 2157 | ); | ||
| 2158 | |||
| 2159 | return $self->terminateExecution(); | ||
| 2160 | |||
| 2161 | } else { | ||
| 2162 | |||
| 2163 | return 1; | ||
| 2164 | } | ||
| 2165 | } | ||
| 2166 | |||
| 2167 | sub terminateExecution { | ||
| 2168 | |||
| 2169 | # Called by $self->parse or $self->implement after parsing/implementation halts, perhaps | ||
| 2170 | # because the script has finished naturally, or perhaps because of an error | ||
| 2171 | # | ||
| 2172 | # Expected arguments | ||
| 2173 | # (none besides $self) | ||
| 2174 | # | ||
| 2175 | # Return values | ||
| 2176 | # 'undef' on improper arguments, or if execution doesn't appear to have been halted, or if | ||
| 2177 | # execution halts after an error | ||
| 2178 | # 1 if execution halts successfully | ||
| 2179 | |||
| 2180 | my ($self, $check) = @_; | ||
| 2181 | |||
| 2182 | # Local variables | ||
| 2183 | my ( | ||
| 2184 | $errorFlag, | ||
| 2185 | @msgList, @errorObjList, | ||
| 2186 | ); | ||
| 2187 | |||
| 2188 | # Check for improper arguments | ||
| 2189 | if (defined $check) { | ||
| 2190 | |||
| 2191 | return $axmud::CLIENT->writeImproper($self->_objClass . '->terminateExecution', @_); | ||
| 2192 | } | ||
| 2193 | |||
| 2194 | # If any interfaces were created with the ADDTRIG, ADDALIAS, ADDMACRO, ADDTIMER or ADDHOOK | ||
| 2195 | # statements, and if OPTION PERSIST has not been set, then all those interfaces must be | ||
| 2196 | # deleted | ||
| 2197 | $self->destroyOwnInterfaces(); | ||
| 2198 | |||
| 2199 | # Close all file channels which are open | ||
| 2200 | foreach my $channelObj ($self->ivValues('fileChannelHash')) { | ||
| 2201 | |||
| 2202 | close $channelObj->fileHandle; | ||
| 2203 | } | ||
| 2204 | |||
| 2205 | # Check that execution really has halted | ||
| 2206 | if ($self->executionStatus ne 'finished') { | ||
| 2207 | |||
| 2208 | # Because the call to this function might be the last thing that $self->parse or | ||
| 2209 | # $self->implement does, if there's an error, we have to use the Axmud error function | ||
| 2210 | return $self->setError( | ||
| 2211 | 'Axbasic ->executionStatus not set to \'finished\' after execution halts', | ||
| 2212 | $self->_objClass . '->terminateExecution', | ||
| 2213 | ); | ||
| 2214 | |||
| 2215 | } elsif ( | ||
| 2216 | $self->scriptStatus eq 'waiting' || $self->scriptStatus eq 'parsing' | ||
| 2217 | || $self->scriptStatus eq 'paused' || $self->scriptStatus eq 'wait_input' | ||
| 2218 | ) { | ||
| 2219 | # (Likewise) | ||
| 2220 | return $self->setError( | ||
| 2221 | 'Axbasic ->scriptStatus not set to correct value after execution halts', | ||
| 2222 | $self->_objClass . '->terminateExecution', | ||
| 2223 | ); | ||
| 2224 | } | ||
| 2225 | |||
| 2226 | # Compile a list of messages to display, @msgList | ||
| 2227 | if ( | ||
| 2228 | $self->scriptStatus eq 'basic_error' | ||
| 2229 | || $self->scriptStatus eq 'perl_error' | ||
| 2230 | || $self->scriptStatus eq 'wait_status' | ||
| 2231 | || $self->scriptStatus eq 'wait_active' | ||
| 2232 | || $self->scriptStatus eq 'wait_not_active' | ||
| 2233 | ) { | ||
| 2234 | # There were errors. Import the error list. Unless ->allErrorsFlag has been set to TRUE, | ||
| 2235 | # we only display the first error generated | ||
| 2236 | @errorObjList = $self->errorList; | ||
| 2237 | if (! $self->allErrorsFlag && @errorObjList > 1) { | ||
| 2238 | |||
| 2239 | @errorObjList = ($errorObjList[0]); | ||
| 2240 | } | ||
| 2241 | |||
| 2242 | foreach my $errorObj (@errorObjList) { | ||
| 2243 | |||
| 2244 | my ( | ||
| 2245 | $category, $errorCode, $lineObj, | ||
| 2246 | %errorHash, | ||
| 2247 | ); | ||
| 2248 | |||
| 2249 | $category = $errorObj->category; | ||
| 2250 | $errorCode = $errorObj->errorCode; | ||
| 2251 | %errorHash = $errorObj->errorHash; | ||
| 2252 | |||
| 2253 | # If any of the words in $errorCode are in capitals, they are meant to be keys in | ||
| 2254 | # %errorHash which should be substituted for the corresponding values | ||
| 2255 | # (NB This algorithm will still work if the keys aren't in capitals) | ||
| 2256 | if (%errorHash) { | ||
| 2257 | |||
| 2258 | foreach my $key (keys %errorHash) { | ||
| 2259 | |||
| 2260 | if ($errorCode =~ m/$key/) { | ||
| 2261 | |||
| 2262 | my $value = $errorHash{$key}; | ||
| 2263 | $errorCode =~ s/$key/$value/; | ||
| 2264 | } | ||
| 2265 | } | ||
| 2266 | } | ||
| 2267 | |||
| 2268 | # For 'error' messages (but not 'debug' messages)... | ||
| 2269 | if ($errorObj->category eq 'error') { | ||
| 2270 | |||
| 2271 | # For error messages caused by the Axbasic script, the message is in the form | ||
| 2272 | # of a string like 'lots_of_words_separated_by_underlines' | ||
| 2273 | # Convert $errorCode (a string like 'syntax_error') into a message in English (a | ||
| 2274 | # string like 'Syntax error') | ||
| 2275 | $errorCode =~ s/_/ /g; | ||
| 2276 | $errorCode = uc(substr($errorCode, 0, 1)) . substr($errorCode, 1); | ||
| 2277 | } | ||
| 2278 | |||
| 2279 | # If the error was caused by a certain line in the Axbasic script, add the line to | ||
| 2280 | # the error message | ||
| 2281 | if (defined $errorObj->line) { | ||
| 2282 | |||
| 2283 | # Get the LA::Line object for the line on which the error occurred | ||
| 2284 | $lineObj = $self->ivShow('lineHash', $errorObj->line); | ||
| 2285 | if ($lineObj) { | ||
| 2286 | |||
| 2287 | if ($self->executionMode eq 'line_num') { | ||
| 2288 | |||
| 2289 | # For primitive code, use the primitive line number | ||
| 2290 | $errorCode .= ', line #' . $lineObj->primLineNum; | ||
| 2291 | |||
| 2292 | } elsif ($self->executionMode eq 'no_line_num') { | ||
| 2293 | |||
| 2294 | # Otherwise use the line number in the raw (unprocessed) script stored | ||
| 2295 | # in LA::Script | ||
| 2296 | $errorCode .= ', line ' . $lineObj->origLineNum; | ||
| 2297 | } | ||
| 2298 | } | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | # Add the error message to the list to be displayed | ||
| 2302 | if ($errorObj->category eq 'error') { | ||
| 2303 | |||
| 2304 | push (@msgList, 'AXBASIC: ERROR: ' . $errorCode); | ||
| 2305 | |||
| 2306 | } elsif ($errorObj->category eq 'debug') { | ||
| 2307 | |||
| 2308 | push (@msgList, 'AXBASIC: DEBUG: ' . $errorCode); | ||
| 2309 | if ($lineObj) { | ||
| 2310 | |||
| 2311 | push (@msgList, ' Line: ' . $lineObj->lineText); | ||
| 2312 | } | ||
| 2313 | } | ||
| 2314 | } | ||
| 2315 | } | ||
| 2316 | |||
| 2317 | # Add the final message to @msgList | ||
| 2318 | if (@msgList) { | ||
| 2319 | |||
| 2320 | $errorFlag = TRUE; | ||
| 2321 | |||
| 2322 | if ($self->allErrorsFlag) { | ||
| 2323 | |||
| 2324 | if (@msgList == 1) { | ||
| 2325 | |||
| 2326 | push ( | ||
| 2327 | @msgList, | ||
| 2328 | 'AXBASIC: Execution of \'' . $self->name . '\' halted (1 error)', | ||
| 2329 | ); | ||
| 2330 | |||
| 2331 | } else { | ||
| 2332 | |||
| 2333 | push ( | ||
| 2334 | @msgList, | ||
| 2335 | 'AXBASIC: Execution of \'' . $self->name . '\' halted (' . @msgList | ||
| 2336 | . ' errors)', | ||
| 2337 | ); | ||
| 2338 | } | ||
| 2339 | |||
| 2340 | } else { | ||
| 2341 | |||
| 2342 | push (@msgList, 'AXBASIC: Execution of \'' . $self->name . '\' halted'); | ||
| 2343 | } | ||
| 2344 | |||
| 2345 | } elsif (! $self->ivShow('optionStatementHash', 'silent')) { | ||
| 2346 | |||
| 2347 | push (@msgList, 'AXBASIC: Execution of \'' . $self->name . '\' complete'); | ||
| 2348 | } | ||
| 2349 | |||
| 2350 | # If the most recent PRINT statement terminated with a comma or semicolon, the first message | ||
| 2351 | # in @msgList may be appended to the end of it | ||
| 2352 | if ($self->column != 0) { | ||
| 2353 | |||
| 2354 | # Prepend a newline character to get around this problem | ||
| 2355 | $self->session->writeText(' '); | ||
| 2356 | } | ||
| 2357 | |||
| 2358 | # Display the contents of @msgList | ||
| 2359 | foreach my $msg (@msgList) { | ||
| 2360 | |||
| 2361 | $self->session->writeText($msg); | ||
| 2362 | } | ||
| 2363 | |||
| 2364 | if ($errorFlag) { | ||
| 2365 | return undef; | ||
| 2366 | } else { | ||
| 2367 | return 1; | ||
| 2368 | } | ||
| 2369 | } | ||
| 2370 | |||
| 2371 | sub download { | ||
| 2372 | |||
| 2373 | # Called by LA::RawScript->upload, which is in turn called by $self->new | ||
| 2374 | # Stores the processed script in this object's IVs | ||
| 2375 | # | ||
| 2376 | # Expected arguments | ||
| 2377 | # $lineCount - Number of lines in the processed script | ||
| 2378 | # $executionMode - Stored as $self->executionMode | ||
| 2379 | # $lineHashRef - Reference to a hash, containing the lines of the processed script | ||
| 2380 | # $primHashRef - In scripts with primitive line numbers, reference to a hash which | ||
| 2381 | # converts those line numbers (e.g. 20 in '20 GOTO 10') into the line | ||
| 2382 | # number of the processed script (stored in $lineHashRef.) An empty | ||
| 2383 | # hash for scripts without line numbers | ||
| 2384 | # | ||
| 2385 | # Return values | ||
| 2386 | # 'undef' on improper arguments | ||
| 2387 | # 1 otherwise | ||
| 2388 | |||
| 2389 | my ($self, $lineCount, $executionMode, $lineHashRef, $primHashRef, $check) = @_; | ||
| 2390 | |||
| 2391 | # Check for improper arguments | ||
| 2392 | if ( | ||
| 2393 | ! defined $lineCount || ! defined $executionMode || ! defined $lineHashRef | ||
| 2394 | || ! defined $primHashRef || defined $check | ||
| 2395 | ) { | ||
| 2396 | return $axmud::CLIENT->writeImproper($self->_objClass . '->download', @_); | ||
| 2397 | } | ||
| 2398 | |||
| 2399 | # Update IVs | ||
| 2400 | $self->ivPoke('lineCount', $lineCount); | ||
| 2401 | $self->ivPoke('executionMode', $executionMode); | ||
| 2402 | $self->ivPoke('lineHash', %$lineHashRef); | ||
| 2403 | $self->ivPoke('primLineHash', %$primHashRef); | ||
| 2404 | |||
| 2405 | return 1; | ||
| 2406 | } | ||
| 2407 | |||
| 2408 | sub destroyOwnInterfaces { | ||
| 2409 | |||
| 2410 | # Called by $self->terminateExecution or by the parent task (if there is one) when the task | ||
| 2411 | # itself has to stop | ||
| 2412 | # Destroys any independent interfaces created with the ADDTRIG, ADDALIAS, ADDMACRO, ADDTIMER | ||
| 2413 | # and ADDHOOK statements, if the interfaces still exist (unless OPTION PERSIST has been | ||
| 2414 | # specified) | ||
| 2415 | # Also destroys any interfaces created with the SETTRIG (etc) and WAITTRIG (etc) statements, | ||
| 2416 | # regardless of whether OPTION PERSIST has been specified | ||
| 2417 | # | ||
| 2418 | # Expected arguments | ||
| 2419 | # (none besides $self) | ||
| 2420 | # | ||
| 2421 | # Return values | ||
| 2422 | # 'undef' on improper arguments | ||
| 2423 | # 1 otherwise | ||
| 2424 | |||
| 2425 | my ($self, $check) = @_; | ||
| 2426 | |||
| 2427 | # Local variables | ||
| 2428 | my @list; | ||
| 2429 | |||
| 2430 | # Check for improper arguments | ||
| 2431 | if (defined $check) { | ||
| 2432 | |||
| 2433 | return $axmud::CLIENT->writeImproper($self->_objClass . '->destroyOwnInterfaces', @_); | ||
| 2434 | } | ||
| 2435 | |||
| 2436 | # Destroy independent interfaces, if allowed | ||
| 2437 | if ( | ||
| 2438 | ! $self->ivExists('optionStatementHash', 'persist') | ||
| 2439 | || ! $self->ivShow('optionStatementHash', 'persist') | ||
| 2440 | ) { | ||
| 2441 | @list = $self->indepInterfaceList; | ||
| 2442 | if (@list) { | ||
| 2443 | |||
| 2444 | do { | ||
| 2445 | my ($name, $profile, $category, $cmd); | ||
| 2446 | |||
| 2447 | $name = shift @list; | ||
| 2448 | $profile = shift @list; | ||
| 2449 | $category = shift @list; | ||
| 2450 | |||
| 2451 | # Delete the interface | ||
| 2452 | $self->session->pseudoCmd( | ||
| 2453 | 'delete' . $category . ' ' . $name . ' -d ' . $profile, | ||
| 2454 | $self->pseudoCmdMode, | ||
| 2455 | ); | ||
| 2456 | |||
| 2457 | } until (! @list); | ||
| 2458 | } | ||
| 2459 | } | ||
| 2460 | |||
| 2461 | # Destroy dependent interfaces | ||
| 2462 | foreach my $interfaceName ($self->depInterfaceList) { | ||
| 2463 | |||
| 2464 | my ($obj, $string); | ||
| 2465 | |||
| 2466 | # If the interface still exists... | ||
| 2467 | if ($self->session->ivExists('interfaceHash', $interfaceName)) { | ||
| 2468 | |||
| 2469 | # Get the interface object | ||
| 2470 | $obj = $self->session->ivShow('interfaceHash', $interfaceName); | ||
| 2471 | # Cannot use ;deletetrigger for dependent interfaces, so we must remove it | ||
| 2472 | # directly | ||
| 2473 | $self->session->removeInterface($obj); | ||
| 2474 | } | ||
| 2475 | } | ||
| 2476 | |||
| 2477 | # Empty the lists - if the Axbasic script has a parent task, this function might be called | ||
| 2478 | # twice | ||
| 2479 | $self->ivEmpty('indepInterfaceList'); | ||
| 2480 | $self->ivEmpty('depInterfaceList'); | ||
| 2481 | # Reset the two accompanying IVs, just to be sure | ||
| 2482 | $self->ivUndef('indepInterfaceName'); | ||
| 2483 | $self->ivUndef('depInterfaceName'); | ||
| 2484 | |||
| 2485 | return 1; | ||
| 2486 | } | ||
| 2487 | |||
| 2488 | sub returnCurrentSub { | ||
| 2489 | |||
| 2490 | # Can be called by anything | ||
| 2491 | # Returns the blessed reference of the current subroutine/function (if none have been called | ||
| 2492 | # yet, it's the '*main' subroutine) | ||
| 2493 | # Actually, returns the last entry in $self->subStackList | ||
| 2494 | # | ||
| 2495 | # Expected arguments | ||
| 2496 | # (none besides $self) | ||
| 2497 | # | ||
| 2498 | # Return values | ||
| 2499 | # 'undef' on improper arguments or if $self->subStackList is empty (should never happen) | ||
| 2500 | # Otherwise returns the blessed reference to the subroutine/function object | ||
| 2501 | |||
| 2502 | my ($self, $check) = @_; | ||
| 2503 | |||
| 2504 | # Check for improper arguments | ||
| 2505 | if (defined $check) { | ||
| 2506 | |||
| 2507 | return $axmud::CLIENT->writeImproper($self->_objClass . '->returnCurrentSub', @_); | ||
| 2508 | } | ||
| 2509 | |||
| 2510 | if (! $self->subStackList) { | ||
| 2511 | |||
| 2512 | # There is no current subroutine or function (this should never happen) | ||
| 2513 | return undef; | ||
| 2514 | |||
| 2515 | } else { | ||
| 2516 | |||
| 2517 | return $self->ivIndex('subStackList', $self->ivLast('subStackList')); | ||
| 2518 | } | ||
| 2519 | } | ||
| 2520 | |||
| 2521 | sub pushSubStack { | ||
| 2522 | |||
| 2523 | # Can be called by anything | ||
| 2524 | # Adds a new subroutine/function to the top of the subroutine/function stack | ||
| 2525 | # In $self->executionMode 'no_line_num' (no line numbers), adds a LA::Subroutine | ||
| 2526 | # In $self->executionMode 'line_num' (primitive line numbers), not used | ||
| 2527 | # | ||
| 2528 | # Expected arguments | ||
| 2529 | # $obj - The object to add | ||
| 2530 | # | ||
| 2531 | # Return values | ||
| 2532 | # 'undef' on improper arguments | ||
| 2533 | # 1 otherwise | ||
| 2534 | |||
| 2535 | my ($self, $obj, $check) = @_; | ||
| 2536 | |||
| 2537 | # Check for improper arguments | ||
| 2538 | if (! defined $obj || defined $check) { | ||
| 2539 | |||
| 2540 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pushSubStack', @_); | ||
| 2541 | } | ||
| 2542 | |||
| 2543 | $self->ivPush('subStackList', $obj); | ||
| 2544 | $self->ivIncrement('subCount'); | ||
| 2545 | |||
| 2546 | return 1; | ||
| 2547 | } | ||
| 2548 | |||
| 2549 | sub popSubStack { | ||
| 2550 | |||
| 2551 | # Can be called by anything | ||
| 2552 | # Removes a new subroutine/function from the top of the subroutine/function stack | ||
| 2553 | # In $self->executionMode 'no_line_num' (no line numbers), removes a LA::Subroutine | ||
| 2554 | # In $self->executionMode 'line_num' (primitive line numbers), not used | ||
| 2555 | # | ||
| 2556 | # Expected arguments | ||
| 2557 | # (none besides $self) | ||
| 2558 | # | ||
| 2559 | # Return values | ||
| 2560 | # 'undef' on improper arguments or if $self->subStackList is empty (should never happen) | ||
| 2561 | # The object at the top of the stack, otherwise | ||
| 2562 | |||
| 2563 | my ($self, $check) = @_; | ||
| 2564 | |||
| 2565 | # Check for improper arguments | ||
| 2566 | if (defined $check) { | ||
| 2567 | |||
| 2568 | return $axmud::CLIENT->writeImproper($self->_objClass . '->popSubStack', @_); | ||
| 2569 | } | ||
| 2570 | |||
| 2571 | $self->ivDecrement('subCount'); | ||
| 2572 | return $self->ivPop('subStackList'); | ||
| 2573 | } | ||
| 2574 | |||
| 2575 | sub setInputData { | ||
| 2576 | |||
| 2577 | # Called by the parent task's ->entryCallback method | ||
| 2578 | # For every item of data the user types in the entry box (while waiting for an Axbasic INPUT | ||
| 2579 | # statement), this function is called once to set the relevant variable | ||
| 2580 | # | ||
| 2581 | # Expected arguments | ||
| 2582 | # $value - The value to assign a variable | ||
| 2583 | # | ||
| 2584 | # Return values | ||
| 2585 | # 'undef' on improper arguments, or if the variable doesn't exist, or if | ||
| 2586 | # $self->inputList (a list of variables awaiting input data) is empty, or if an | ||
| 2587 | # error is generated while setting the variable | ||
| 2588 | # 1 otherwise | ||
| 2589 | |||
| 2590 | my ($self, $value, $check) = @_; | ||
| 2591 | |||
| 2592 | # Local variables | ||
| 2593 | my $varObj; | ||
| 2594 | |||
| 2595 | # Check for improper arguments | ||
| 2596 | if (! defined $value || defined $check) { | ||
| 2597 | |||
| 2598 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setInputData', @_); | ||
| 2599 | } | ||
| 2600 | |||
| 2601 | # Check that we're expecting some input data. This function shouldn't be called when | ||
| 2602 | # $self->inputList is empty | ||
| 2603 | if (! $self->inputList) { | ||
| 2604 | |||
| 2605 | # Just ignore the typed value | ||
| 2606 | return undef; | ||
| 2607 | } | ||
| 2608 | |||
| 2609 | # Set the variable | ||
| 2610 | $varObj = $self->ivShift('inputList')->variable; | ||
| 2611 | $varObj->set($value); | ||
| 2612 | |||
| 2613 | if ($self->errorList) { | ||
| 2614 | |||
| 2615 | # Setting the variable generated an error, so we have to halt | ||
| 2616 | return $self->terminateExecution(); | ||
| 2617 | |||
| 2618 | } else { | ||
| 2619 | |||
| 2620 | # Variable set successfully | ||
| 2621 | return 1; | ||
| 2622 | } | ||
| 2623 | } | ||
| 2624 | |||
| 2625 | sub interfaceNotification { | ||
| 2626 | |||
| 2627 | # Called by the parent task's ->triggerNotifySeen (etc) when one of the dependent interfaces | ||
| 2628 | # created by a SETTRIG (etc) fires | ||
| 2629 | # Creates a LA::Notification object to store details of the fired interface, so that the | ||
| 2630 | # script can retrieve them when it's ready | ||
| 2631 | # | ||
| 2632 | # The format of arguments supplied by different GA::Task::Script functions is as follows: | ||
| 2633 | # | ||
| 2634 | # ->triggerNotifySeen: (line_of_text, group_string_list) | ||
| 2635 | # | ||
| 2636 | # line_of_text: The line of text sent by the world which caused the trigger to fire | ||
| 2637 | # group_string_list: A list of group substrings from the pattern match (the equivalent | ||
| 2638 | # of @_) | ||
| 2639 | # | ||
| 2640 | # ->aliasNotifySeen | ||
| 2641 | # | ||
| 2642 | # world_cmd: The world command which caused the alias to fire | ||
| 2643 | # group_string_list: A list of group substrings from the pattern match (the equivalent | ||
| 2644 | # of @_) | ||
| 2645 | # | ||
| 2646 | # ->macroNotifySeen | ||
| 2647 | # | ||
| 2648 | # keycode_string: The keycode string (combination of keypresses, e.g. 'ctrl + f1' | ||
| 2649 | # which caused the macro to fire | ||
| 2650 | # empty_list: An empty list | ||
| 2651 | # | ||
| 2652 | # ->timerNotifySeen | ||
| 2653 | # | ||
| 2654 | # session_time: The value of GA::Session->sessionTime when the timer fired (and that | ||
| 2655 | # caused the timer to fire) | ||
| 2656 | # | ||
| 2657 | # other_time: For timers whose stimulus is an interval, the time (matches | ||
| 2658 | # GA::Session->sessionTime) at which the timer was due to fire. This value will be | ||
| 2659 | # less than or the same as session_time. For timers whose stimulus is a clock time | ||
| 2660 | # (in the form HH:MM firing once a day, or 99:MM firing once an hour, at MM | ||
| 2661 | # minutes past the hour), the stimulus itself | ||
| 2662 | # | ||
| 2663 | # ->hookNotifySeen | ||
| 2664 | # | ||
| 2665 | # hook_event: The hook event which caused the hook to fire | ||
| 2666 | # | ||
| 2667 | # hook_var, hook_val: Zero, one or two items of additional data for this hook event. | ||
| 2668 | # The number of items depends on the hook event | ||
| 2669 | # | ||
| 2670 | # Expected arguments | ||
| 2671 | # $interfaceObj - The active interface that fired | ||
| 2672 | # $fireBecause - A scalar describing why the interface fired | ||
| 2673 | # | ||
| 2674 | # Optional arguments | ||
| 2675 | # @dataList - A list of additional data, supplied by the interface when it | ||
| 2676 | # fired (may be an empty list) | ||
| 2677 | # | ||
| 2678 | # Return values | ||
| 2679 | # 'undef' on improper arguments or if the LA::Notification object can't be created | ||
| 2680 | # 1 otherwise | ||
| 2681 | |||
| 2682 | my ($self, $interfaceObj, $fireBecause, @dataList) = @_; | ||
| 2683 | |||
| 2684 | # Local variables | ||
| 2685 | my $obj; | ||
| 2686 | |||
| 2687 | # Check for improper arguments | ||
| 2688 | if (! defined $interfaceObj || ! defined $fireBecause) { | ||
| 2689 | |||
| 2690 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interfaceNotification', @_); | ||
| 2691 | } | ||
| 2692 | |||
| 2693 | # For triggers and aliases, @fireDataList (if it is populated at all) contains the whole | ||
| 2694 | # matching line of text/world command, followed by any substrings. Remove the first | ||
| 2695 | # element, leaving us with the substrings | ||
| 2696 | if ( | ||
| 2697 | ($interfaceObj->category eq 'trigger' || $interfaceObj->category eq 'alias') | ||
| 2698 | && @dataList | ||
| 2699 | ) { | ||
| 2700 | shift @dataList; | ||
| 2701 | } | ||
| 2702 | |||
| 2703 | # Create a LA::Notification object to store the information about the fired interface | ||
| 2704 | $obj = Language::Axbasic::Notification->new( | ||
| 2705 | $self, | ||
| 2706 | $interfaceObj, | ||
| 2707 | $fireBecause, | ||
| 2708 | @dataList, | ||
| 2709 | ); | ||
| 2710 | |||
| 2711 | if (! $obj) { | ||
| 2712 | |||
| 2713 | return undef; | ||
| 2714 | |||
| 2715 | } else { | ||
| 2716 | |||
| 2717 | # Add this LA::Notification to the end of the script's list | ||
| 2718 | $self->ivPush('notificationList', $obj); | ||
| 2719 | # If the list was empty, make the first notification in the list, the current one | ||
| 2720 | if ($self->currentNotification == -1) { | ||
| 2721 | |||
| 2722 | $self->ivPoke('currentNotification', 0); | ||
| 2723 | } | ||
| 2724 | |||
| 2725 | return 1; | ||
| 2726 | } | ||
| 2727 | } | ||
| 2728 | |||
| 2729 | sub updateInterfaces { | ||
| 2730 | |||
| 2731 | # Called by the parent task, when it is paused and waiting for an interface to fire before | ||
| 2732 | # resuming | ||
| 2733 | # Causes this LA::Script to update its IVs to remove the interface | ||
| 2734 | # | ||
| 2735 | # Expected arguments | ||
| 2736 | # $interfaceName - The name of the interface to remove | ||
| 2737 | # | ||
| 2738 | # Return values | ||
| 2739 | # 'undef' on improper arguments | ||
| 2740 | # 1 otherwise | ||
| 2741 | |||
| 2742 | my ($self, $interfaceName, $check) = @_; | ||
| 2743 | |||
| 2744 | # Local variables | ||
| 2745 | my (@ifaceList, @newList); | ||
| 2746 | |||
| 2747 | # Check for improper arguments | ||
| 2748 | if (! defined $interfaceName || defined $check) { | ||
| 2749 | |||
| 2750 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateInterfaces', @_); | ||
| 2751 | } | ||
| 2752 | |||
| 2753 | @ifaceList = $self->depInterfaceList; | ||
| 2754 | foreach my $name (@ifaceList) { | ||
| 2755 | |||
| 2756 | my $obj = $self->session->ivShow('interfaceHash', $name); | ||
| 2757 | |||
| 2758 | if ($obj && $obj->name ne $interfaceName) { | ||
| 2759 | |||
| 2760 | push (@newList, $obj->name); | ||
| 2761 | } | ||
| 2762 | } | ||
| 2763 | |||
| 2764 | $self->ivPoke('depInterfaceList', @newList); | ||
| 2765 | |||
| 2766 | # Update the accompanying IV, if necessary | ||
| 2767 | if ( | ||
| 2768 | defined $self->depInterfaceName | ||
| 2769 | && $self->depInterfaceName eq $interfaceName | ||
| 2770 | ) { | ||
| 2771 | $self->ivUndef('depInterfaceName'); | ||
| 2772 | } | ||
| 2773 | |||
| 2774 | return 1; | ||
| 2775 | } | ||
| 2776 | |||
| 2777 | ################## | ||
| 2778 | # Accessors - set | ||
| 2779 | |||
| 2780 | sub set_column { | ||
| 2781 | |||
| 2782 | # Returns 'undef' on improper arguments | ||
| 2783 | # Returns 1 on success | ||
| 2784 | |||
| 2785 | my ($self, $column, $check) = @_; | ||
| 2786 | |||
| 2787 | # Check for improper arguments | ||
| 2788 | if (! defined $column || defined $check) { | ||
| 2789 | |||
| 2790 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_column', @_); | ||
| 2791 | } | ||
| 2792 | |||
| 2793 | # Update IVs | ||
| 2794 | $self->ivPoke('column', $column); | ||
| 2795 | |||
| 2796 | return 1; | ||
| 2797 | } | ||
| 2798 | |||
| 2799 | sub set_currentNotification { | ||
| 2800 | |||
| 2801 | # Returns 'undef' on improper arguments | ||
| 2802 | # Returns 1 on success | ||
| 2803 | |||
| 2804 | my ($self, $number, $check) = @_; | ||
| 2805 | |||
| 2806 | # Check for improper arguments | ||
| 2807 | if (! defined $number || defined $check) { | ||
| 2808 | |||
| 2809 | return $axmud::CLIENT->writeImproper( | ||
| 2810 | $self->_objClass . '->set_currentNotification', | ||
| 2811 | @_, | ||
| 2812 | ); | ||
| 2813 | } | ||
| 2814 | |||
| 2815 | # Update IVs | ||
| 2816 | $self->ivPoke('currentNotification', $number); | ||
| 2817 | |||
| 2818 | return 1; | ||
| 2819 | } | ||
| 2820 | |||
| 2821 | sub rmv_currentNotification { | ||
| 2822 | |||
| 2823 | # Returns 'undef' on improper arguments | ||
| 2824 | # Returns 1 on success | ||
| 2825 | |||
| 2826 | my ($self, $check) = @_; | ||
| 2827 | |||
| 2828 | # Check for improper arguments | ||
| 2829 | if (defined $check) { | ||
| 2830 | |||
| 2831 | return $axmud::CLIENT->writeImproper( | ||
| 2832 | $self->_objClass . '->rmv_currentNotification', | ||
| 2833 | @_, | ||
| 2834 | ); | ||
| 2835 | } | ||
| 2836 | |||
| 2837 | # Update IVs | ||
| 2838 | $self->ivSplice('notificationList', $self->currentNotification, 1); | ||
| 2839 | |||
| 2840 | return 1; | ||
| 2841 | } | ||
| 2842 | |||
| 2843 | sub inc_currentNotification { | ||
| 2844 | |||
| 2845 | # Returns 'undef' on improper arguments | ||
| 2846 | # Returns 1 on success | ||
| 2847 | |||
| 2848 | my ($self, $number, $check) = @_; | ||
| 2849 | |||
| 2850 | # Check for improper arguments | ||
| 2851 | if (! defined $number || defined $check) { | ||
| 2852 | |||
| 2853 | return $axmud::CLIENT->writeImproper( | ||
| 2854 | $self->_objClass . '->inc_currentNotification', | ||
| 2855 | @_, | ||
| 2856 | ); | ||
| 2857 | } | ||
| 2858 | |||
| 2859 | # Update IVs | ||
| 2860 | $self->ivIncrement('currentNotification'); | ||
| 2861 | |||
| 2862 | return 1; | ||
| 2863 | } | ||
| 2864 | |||
| 2865 | sub set_currentParseSub { | ||
| 2866 | |||
| 2867 | # Returns 'undef' on improper arguments | ||
| 2868 | # Returns 1 on success | ||
| 2869 | |||
| 2870 | my ($self, $obj, $check) = @_; | ||
| 2871 | |||
| 2872 | # Check for improper arguments | ||
| 2873 | if (defined $check) { | ||
| 2874 | |||
| 2875 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_currentParseSub', @_); | ||
| 2876 | } | ||
| 2877 | |||
| 2878 | # Update IVs | ||
| 2879 | $self->ivPoke('currentParseSub', $obj); | ||
| 2880 | |||
| 2881 | return 1; | ||
| 2882 | } | ||
| 2883 | |||
| 2884 | sub set_declareMode { | ||
| 2885 | |||
| 2886 | # Returns 'undef' on improper arguments | ||
| 2887 | # Returns 1 on success | ||
| 2888 | |||
| 2889 | my ($self, $mode, $check) = @_; | ||
| 2890 | |||
| 2891 | # Check for improper arguments | ||
| 2892 | if (! defined $mode || defined $check) { | ||
| 2893 | |||
| 2894 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_declareMode', @_); | ||
| 2895 | } | ||
| 2896 | |||
| 2897 | # Update IVs | ||
| 2898 | $self->ivPoke('declareMode', $mode); | ||
| 2899 | |||
| 2900 | return 1; | ||
| 2901 | } | ||
| 2902 | |||
| 2903 | sub set_depInterfaceName { | ||
| 2904 | |||
| 2905 | # Returns 'undef' on improper arguments | ||
| 2906 | # Returns 1 on success | ||
| 2907 | |||
| 2908 | my ($self, $name, $check) = @_; | ||
| 2909 | |||
| 2910 | # Check for improper arguments | ||
| 2911 | if (defined $check) { | ||
| 2912 | |||
| 2913 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_depInterfaceName', @_); | ||
| 2914 | } | ||
| 2915 | |||
| 2916 | # Update IVs | ||
| 2917 | $self->ivPoke('depInterfaceName', $name); | ||
| 2918 | |||
| 2919 | return 1; | ||
| 2920 | } | ||
| 2921 | |||
| 2922 | sub set_depInterfaceList { | ||
| 2923 | |||
| 2924 | # Returns 'undef' on improper arguments | ||
| 2925 | # Returns 1 on success | ||
| 2926 | |||
| 2927 | my ($self, @list) = @_; | ||
| 2928 | |||
| 2929 | # (No improper arguments to check - @list can be empty) | ||
| 2930 | |||
| 2931 | $self->ivPoke('depInterfaceList', @list); | ||
| 2932 | |||
| 2933 | return 1; | ||
| 2934 | } | ||
| 2935 | |||
| 2936 | sub push_depInterfaceList { | ||
| 2937 | |||
| 2938 | # Returns 'undef' on improper arguments | ||
| 2939 | # Returns 1 on success | ||
| 2940 | |||
| 2941 | my ($self, $obj, $check) = @_; | ||
| 2942 | |||
| 2943 | # Check for improper arguments | ||
| 2944 | if (! defined $obj || defined $check) { | ||
| 2945 | |||
| 2946 | return $axmud::CLIENT->writeImproper($self->_objClass . '->push_depInterfaceList', @_); | ||
| 2947 | } | ||
| 2948 | |||
| 2949 | # Update IVs | ||
| 2950 | $self->ivPush('depInterfaceList', $obj); | ||
| 2951 | |||
| 2952 | return 1; | ||
| 2953 | } | ||
| 2954 | |||
| 2955 | sub set_endStatementFlag { | ||
| 2956 | |||
| 2957 | # Returns 'undef' on improper arguments | ||
| 2958 | # Returns 1 on success | ||
| 2959 | |||
| 2960 | my ($self, $flag, $check) = @_; | ||
| 2961 | |||
| 2962 | # Check for improper arguments | ||
| 2963 | if (! defined $flag || defined $check) { | ||
| 2964 | |||
| 2965 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_endStatementFlag', @_); | ||
| 2966 | } | ||
| 2967 | |||
| 2968 | if ($flag) { | ||
| 2969 | $self->ivPoke('endStatementFlag', TRUE); | ||
| 2970 | } else { | ||
| 2971 | $self->ivPoke('endStatementFlag', FALSE); | ||
| 2972 | } | ||
| 2973 | |||
| 2974 | return 1; | ||
| 2975 | } | ||
| 2976 | |||
| 2977 | sub set_executionStatus { | ||
| 2978 | |||
| 2979 | # Returns 'undef' on improper arguments | ||
| 2980 | # Returns 1 on success | ||
| 2981 | |||
| 2982 | my ($self, $status, $check) = @_; | ||
| 2983 | |||
| 2984 | # Check for improper arguments | ||
| 2985 | if (! defined $status || defined $check) { | ||
| 2986 | |||
| 2987 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_executionStatus', @_); | ||
| 2988 | } | ||
| 2989 | |||
| 2990 | # Update IVs | ||
| 2991 | $self->ivPoke('executionStatus', $status); | ||
| 2992 | |||
| 2993 | return 1; | ||
| 2994 | } | ||
| 2995 | |||
| 2996 | sub add_fileChannel { | ||
| 2997 | |||
| 2998 | # Returns 'undef' on improper arguments | ||
| 2999 | # Returns 1 on success | ||
| 3000 | |||
| 3001 | my ($self, $obj, $check) = @_; | ||
| 3002 | |||
| 3003 | # Check for improper arguments | ||
| 3004 | if (! defined $obj || defined $check) { | ||
| 3005 | |||
| 3006 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_fileChannel', @_); | ||
| 3007 | } | ||
| 3008 | |||
| 3009 | # Update IVs | ||
| 3010 | $self->ivAdd('fileChannelHash', $obj->channel, $obj); | ||
| 3011 | |||
| 3012 | return 1; | ||
| 3013 | } | ||
| 3014 | |||
| 3015 | sub del_fileChannel { | ||
| 3016 | |||
| 3017 | # Returns 'undef' on improper arguments | ||
| 3018 | # Returns 1 on success | ||
| 3019 | |||
| 3020 | my ($self, $obj, $check) = @_; | ||
| 3021 | |||
| 3022 | # Check for improper arguments | ||
| 3023 | if (! defined $obj || defined $check) { | ||
| 3024 | |||
| 3025 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_fileChannel', @_); | ||
| 3026 | } | ||
| 3027 | |||
| 3028 | # Update IVs | ||
| 3029 | $self->ivDelete('fileChannelHash', $obj->channel); | ||
| 3030 | |||
| 3031 | return 1; | ||
| 3032 | } | ||
| 3033 | |||
| 3034 | sub set_forcedWinFlag { | ||
| 3035 | |||
| 3036 | # Returns 'undef' on improper arguments | ||
| 3037 | # Returns 1 on success | ||
| 3038 | |||
| 3039 | my ($self, $flag, $check) = @_; | ||
| 3040 | |||
| 3041 | # Check for improper arguments | ||
| 3042 | if (! defined $flag || defined $check) { | ||
| 3043 | |||
| 3044 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_forcedWinFlag', @_); | ||
| 3045 | } | ||
| 3046 | |||
| 3047 | if ($flag) { | ||
| 3048 | $self->ivPoke('forcedWinFlag', TRUE); | ||
| 3049 | } else { | ||
| 3050 | $self->ivPoke('forcedWinFlag', FALSE); | ||
| 3051 | } | ||
| 3052 | |||
| 3053 | return 1; | ||
| 3054 | } | ||
| 3055 | |||
| 3056 | sub add_funcName { | ||
| 3057 | |||
| 3058 | # Returns 'undef' on improper arguments | ||
| 3059 | # Returns 1 on success | ||
| 3060 | |||
| 3061 | my ($self, $name, $obj, $check) = @_; | ||
| 3062 | |||
| 3063 | # Check for improper arguments | ||
| 3064 | if (! defined $name || ! defined $obj || defined $check) { | ||
| 3065 | |||
| 3066 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_funcName', @_); | ||
| 3067 | } | ||
| 3068 | |||
| 3069 | # Update IVs | ||
| 3070 | $self->ivAdd('funcNameHash', $name, $obj); | ||
| 3071 | |||
| 3072 | return 1; | ||
| 3073 | } | ||
| 3074 | |||
| 3075 | sub add_globalArray { | ||
| 3076 | |||
| 3077 | # Returns 'undef' on improper arguments | ||
| 3078 | # Returns 1 on success | ||
| 3079 | |||
| 3080 | my ($self, $name, $obj, $check) = @_; | ||
| 3081 | |||
| 3082 | # Check for improper arguments | ||
| 3083 | if (! defined $name || ! defined $obj || defined $check) { | ||
| 3084 | |||
| 3085 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_globalArray', @_); | ||
| 3086 | } | ||
| 3087 | |||
| 3088 | # Update IVs | ||
| 3089 | $self->ivAdd('globalArrayHash', $name, $obj); | ||
| 3090 | |||
| 3091 | return 1; | ||
| 3092 | } | ||
| 3093 | |||
| 3094 | sub push_globalDataList { | ||
| 3095 | |||
| 3096 | # Returns 'undef' on improper arguments | ||
| 3097 | # Returns 1 on success | ||
| 3098 | |||
| 3099 | my ($self, $expression, $check) = @_; | ||
| 3100 | |||
| 3101 | # Check for improper arguments | ||
| 3102 | if (! defined $expression || defined $check) { | ||
| 3103 | |||
| 3104 | return $axmud::CLIENT->writeImproper($self->_objClass . '->push_globalDataList', @_); | ||
| 3105 | } | ||
| 3106 | |||
| 3107 | # Update IVs | ||
| 3108 | $self->ivPush('globalDataList', $expression); | ||
| 3109 | |||
| 3110 | return 1; | ||
| 3111 | } | ||
| 3112 | |||
| 3113 | sub add_globalScalar { | ||
| 3114 | |||
| 3115 | # Returns 'undef' on improper arguments | ||
| 3116 | # Returns 1 on success | ||
| 3117 | |||
| 3118 | my ($self, $name, $obj, $check) = @_; | ||
| 3119 | |||
| 3120 | # Check for improper arguments | ||
| 3121 | if (! defined $name || ! defined $obj || defined $check) { | ||
| 3122 | |||
| 3123 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_globalScalar', @_); | ||
| 3124 | } | ||
| 3125 | |||
| 3126 | # Update IVs | ||
| 3127 | $self->ivAdd('globalScalarHash', $name, $obj); | ||
| 3128 | |||
| 3129 | return 1; | ||
| 3130 | } | ||
| 3131 | |||
| 3132 | sub push_gosubStackList { | ||
| 3133 | |||
| 3134 | # Returns 'undef' on improper arguments | ||
| 3135 | # Returns 1 on success | ||
| 3136 | |||
| 3137 | my ($self, $obj, $check) = @_; | ||
| 3138 | |||
| 3139 | # Check for improper arguments | ||
| 3140 | if (! defined $obj || defined $check) { | ||
| 3141 | |||
| 3142 | return $axmud::CLIENT->writeImproper($self->_objClass . '->push_gosubStackList', @_); | ||
| 3143 | } | ||
| 3144 | |||
| 3145 | # Update IVs | ||
| 3146 | $self->ivPush('gosubStackList', $obj); | ||
| 3147 | |||
| 3148 | return 1; | ||
| 3149 | } | ||
| 3150 | |||
| 3151 | sub pop_gosubStackList { | ||
| 3152 | |||
| 3153 | # Returns 'undef' on improper arguments | ||
| 3154 | # Returns the popped value on success (or 'undef' if the list is empty) | ||
| 3155 | |||
| 3156 | my ($self, $check) = @_; | ||
| 3157 | |||
| 3158 | # Check for improper arguments | ||
| 3159 | if (defined $check) { | ||
| 3160 | |||
| 3161 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pop_gosubStackList', @_); | ||
| 3162 | } | ||
| 3163 | |||
| 3164 | # Update IVs | ||
| 3165 | return $self->ivPop('gosubStackList'); | ||
| 3166 | } | ||
| 3167 | |||
| 3168 | sub set_indepInterfaceName { | ||
| 3169 | |||
| 3170 | # Returns 'undef' on improper arguments | ||
| 3171 | # Returns 1 on success | ||
| 3172 | |||
| 3173 | my ($self, $name, $check) = @_; | ||
| 3174 | |||
| 3175 | # Check for improper arguments | ||
| 3176 | if (defined $check) { | ||
| 3177 | |||
| 3178 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_indepInterfaceName', @_); | ||
| 3179 | } | ||
| 3180 | |||
| 3181 | # Update IVs | ||
| 3182 | $self->ivPoke('indepInterfaceName', $name); | ||
| 3183 | |||
| 3184 | return 1; | ||
| 3185 | } | ||
| 3186 | |||
| 3187 | sub set_indepInterfaceList { | ||
| 3188 | |||
| 3189 | # Returns 'undef' on improper arguments | ||
| 3190 | # Returns 1 on success | ||
| 3191 | |||
| 3192 | my ($self, @list) = @_; | ||
| 3193 | |||
| 3194 | # (No improper arguments to check - @list can be empty) | ||
| 3195 | |||
| 3196 | $self->ivPoke('indepInterfaceList', @list); | ||
| 3197 | |||
| 3198 | return 1; | ||
| 3199 | } | ||
| 3200 | |||
| 3201 | sub push_indepInterfaceList { | ||
| 3202 | |||
| 3203 | # Returns 'undef' on improper arguments | ||
| 3204 | # Returns 1 on success | ||
| 3205 | |||
| 3206 | my ($self, $name, $profName, $category, $check) = @_; | ||
| 3207 | |||
| 3208 | # Check for improper arguments | ||
| 3209 | if (! defined $name || ! defined $profName || ! defined $category || defined $check) { | ||
| 3210 | |||
| 3211 | return $axmud::CLIENT->writeImproper( | ||
| 3212 | $self->_objClass . '->push_indepInterfaceList', | ||
| 3213 | @_, | ||
| 3214 | ); | ||
| 3215 | } | ||
| 3216 | |||
| 3217 | # Update IVs | ||
| 3218 | $self->ivPush('indepInterfaceList', $name, $profName, $category); | ||
| 3219 | |||
| 3220 | return 1; | ||
| 3221 | } | ||
| 3222 | |||
| 3223 | sub push_inputList { | ||
| 3224 | |||
| 3225 | # Returns 'undef' on improper arguments | ||
| 3226 | # Returns 1 on success | ||
| 3227 | |||
| 3228 | my ($self, $lvalue, $check) = @_; | ||
| 3229 | |||
| 3230 | # Check for improper arguments | ||
| 3231 | if (! defined $lvalue || defined $check) { | ||
| 3232 | |||
| 3233 | return $axmud::CLIENT->writeImproper($self->_objClass . '->push_inputList', @_); | ||
| 3234 | } | ||
| 3235 | |||
| 3236 | # Update IVs | ||
| 3237 | $self->ivPush('inputList', $lvalue); | ||
| 3238 | |||
| 3239 | return 1; | ||
| 3240 | } | ||
| 3241 | |||
| 3242 | sub set_inputList { | ||
| 3243 | |||
| 3244 | # Returns 'undef' on improper arguments | ||
| 3245 | # Returns 1 on success | ||
| 3246 | |||
| 3247 | my ($self, @list) = @_; | ||
| 3248 | |||
| 3249 | # (No improper arguments to check - @list can be empty) | ||
| 3250 | |||
| 3251 | $self->ivPoke('inputList', @list); | ||
| 3252 | |||
| 3253 | return 1; | ||
| 3254 | } | ||
| 3255 | |||
| 3256 | sub set_nextLine { | ||
| 3257 | |||
| 3258 | # Returns 'undef' on improper arguments | ||
| 3259 | # Returns 1 on success | ||
| 3260 | |||
| 3261 | my ($self, $number, $check) = @_; | ||
| 3262 | |||
| 3263 | # Check for improper arguments | ||
| 3264 | if (! defined $number || defined $check) { | ||
| 3265 | |||
| 3266 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_nextLine', @_); | ||
| 3267 | } | ||
| 3268 | |||
| 3269 | # Update IVs | ||
| 3270 | $self->ivPoke('nextLine', $number); | ||
| 3271 | |||
| 3272 | return 1; | ||
| 3273 | } | ||
| 3274 | |||
| 3275 | sub set_nextStatement { | ||
| 3276 | |||
| 3277 | # Returns 'undef' on improper arguments | ||
| 3278 | # Returns 1 on success | ||
| 3279 | |||
| 3280 | my ($self, $obj, $check) = @_; | ||
| 3281 | |||
| 3282 | # Check for improper arguments | ||
| 3283 | if (defined $check) { | ||
| 3284 | |||
| 3285 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_nextStatement', @_); | ||
| 3286 | } | ||
| 3287 | |||
| 3288 | # Update IVs | ||
| 3289 | $self->ivPoke('nextStatement', $obj); | ||
| 3290 | |||
| 3291 | return 1; | ||
| 3292 | } | ||
| 3293 | |||
| 3294 | sub add_optionStatement { | ||
| 3295 | |||
| 3296 | # Returns 'undef' on improper arguments | ||
| 3297 | # Returns 1 on success | ||
| 3298 | |||
| 3299 | my ($self, $key, $value, $check) = @_; | ||
| 3300 | |||
| 3301 | # Check for improper arguments | ||
| 3302 | if (! defined $key || defined $check) { | ||
| 3303 | |||
| 3304 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_optionStatement', @_); | ||
| 3305 | } | ||
| 3306 | |||
| 3307 | # Update IVs | ||
| 3308 | $self->ivAdd('optionStatementHash', $key, $value); | ||
| 3309 | |||
| 3310 | return 1; | ||
| 3311 | } | ||
| 3312 | |||
| 3313 | sub set_pseudoCmdMode { | ||
| 3314 | |||
| 3315 | # Returns 'undef' on improper arguments | ||
| 3316 | # Returns 1 on success | ||
| 3317 | |||
| 3318 | my ($self, $mode, $check) = @_; | ||
| 3319 | |||
| 3320 | # Check for improper arguments | ||
| 3321 | if (! defined $mode || defined $check) { | ||
| 3322 | |||
| 3323 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_pseudoCmdMode', @_); | ||
| 3324 | } | ||
| 3325 | |||
| 3326 | # Update IVs | ||
| 3327 | $self->ivPoke('set_pseudoCmdMode', $mode); | ||
| 3328 | |||
| 3329 | return 1; | ||
| 3330 | } | ||
| 3331 | |||
| 3332 | sub set_readDataList { | ||
| 3333 | |||
| 3334 | # Returns 'undef' on improper arguments | ||
| 3335 | # Returns 1 on success | ||
| 3336 | |||
| 3337 | my ($self, @list) = @_; | ||
| 3338 | |||
| 3339 | # (No improper arguments to check - @list can be empty) | ||
| 3340 | |||
| 3341 | $self->ivPoke('readDataList', @list); | ||
| 3342 | |||
| 3343 | return 1; | ||
| 3344 | } | ||
| 3345 | |||
| 3346 | sub push_readDataList { | ||
| 3347 | |||
| 3348 | # Returns 'undef' on improper arguments | ||
| 3349 | # Returns 1 on success | ||
| 3350 | |||
| 3351 | my ($self, $expression, $check) = @_; | ||
| 3352 | |||
| 3353 | # Check for improper arguments | ||
| 3354 | if (! defined $expression || defined $check) { | ||
| 3355 | |||
| 3356 | return $axmud::CLIENT->writeImproper($self->_objClass . '->push_readDataList', @_); | ||
| 3357 | } | ||
| 3358 | |||
| 3359 | # Update IVs | ||
| 3360 | $self->ivPush('readDataList', $expression); | ||
| 3361 | |||
| 3362 | return 1; | ||
| 3363 | } | ||
| 3364 | |||
| 3365 | sub shift_readDataList { | ||
| 3366 | |||
| 3367 | # Returns 'undef' on improper arguments | ||
| 3368 | # Returns the shifted value on success (or 'undef' if the list is empty) | ||
| 3369 | |||
| 3370 | my ($self, $check) = @_; | ||
| 3371 | |||
| 3372 | # Check for improper arguments | ||
| 3373 | if (defined $check) { | ||
| 3374 | |||
| 3375 | return $axmud::CLIENT->writeImproper($self->_objClass . '->shift_readDataList', @_); | ||
| 3376 | } | ||
| 3377 | |||
| 3378 | # Update IVs | ||
| 3379 | return $self->ivShift('readDataList'); | ||
| 3380 | } | ||
| 3381 | |||
| 3382 | sub set_scriptStatus { | ||
| 3383 | |||
| 3384 | # Returns 'undef' on improper arguments | ||
| 3385 | # Returns 1 on success | ||
| 3386 | |||
| 3387 | my ($self, $status, $check) = @_; | ||
| 3388 | |||
| 3389 | # Check for improper arguments | ||
| 3390 | if (! defined $status || defined $check) { | ||
| 3391 | |||
| 3392 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scriptStatus', @_); | ||
| 3393 | } | ||
| 3394 | |||
| 3395 | # Update IVs | ||
| 3396 | $self->ivPoke('scriptStatus', $status); | ||
| 3397 | |||
| 3398 | return 1; | ||
| 3399 | } | ||
| 3400 | |||
| 3401 | sub set_stepCount { | ||
| 3402 | |||
| 3403 | # Returns 'undef' on improper arguments | ||
| 3404 | # Returns 1 on success | ||
| 3405 | |||
| 3406 | my ($self, $count, $check) = @_; | ||
| 3407 | |||
| 3408 | # Check for improper arguments | ||
| 3409 | if (! defined $count || defined $check) { | ||
| 3410 | |||
| 3411 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_stepCount', @_); | ||
| 3412 | } | ||
| 3413 | |||
| 3414 | # Update IVs | ||
| 3415 | $self->ivPoke('stepCount', $count); | ||
| 3416 | |||
| 3417 | return 1; | ||
| 3418 | } | ||
| 3419 | |||
| 3420 | sub add_subName { | ||
| 3421 | |||
| 3422 | # Returns 'undef' on improper arguments | ||
| 3423 | # Returns 1 on success | ||
| 3424 | |||
| 3425 | my ($self, $name, $obj, $check) = @_; | ||
| 3426 | |||
| 3427 | # Check for improper arguments | ||
| 3428 | if (! defined $name || ! defined $obj || defined $check) { | ||
| 3429 | |||
| 3430 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_subName', @_); | ||
| 3431 | } | ||
| 3432 | |||
| 3433 | # Update IVs | ||
| 3434 | $self->ivAdd('subNameHash', $name, $obj); | ||
| 3435 | |||
| 3436 | return 1; | ||
| 3437 | } | ||
| 3438 | |||
| 3439 | sub set_task { | ||
| 3440 | |||
| 3441 | # Returns 'undef' on improper arguments | ||
| 3442 | # Returns 1 on success | ||
| 3443 | |||
| 3444 | my ($self, $obj, $check) = @_; | ||
| 3445 | |||
| 3446 | # Check for improper arguments | ||
| 3447 | if (! defined $obj || defined $check) { | ||
| 3448 | |||
| 3449 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_task', @_); | ||
| 3450 | } | ||
| 3451 | |||
| 3452 | # Update IVs | ||
| 3453 | $self->ivPoke('parentTask', $obj); | ||
| 3454 | $self->ivPoke('stepMax', $obj->stepMax); | ||
| 3455 | |||
| 3456 | return 1; | ||
| 3457 | } | ||
| 3458 | |||
| 3459 | sub set_useProfile { | ||
| 3460 | |||
| 3461 | # Returns 'undef' on improper arguments | ||
| 3462 | # Returns 1 on success | ||
| 3463 | |||
| 3464 | my ($self, $name, $check) = @_; | ||
| 3465 | |||
| 3466 | # Check for improper arguments | ||
| 3467 | if (! defined $name || defined $check) { | ||
| 3468 | |||
| 3469 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_useProfile', @_); | ||
| 3470 | } | ||
| 3471 | |||
| 3472 | # Update IVs | ||
| 3473 | $self->ivPoke('useProfile', $name); | ||
| 3474 | |||
| 3475 | return 1; | ||
| 3476 | } | ||
| 3477 | |||
| 3478 | ################## | ||
| 3479 | # Accessors - get | ||
| 3480 | |||
| 3481 | sub session | ||
| 3482 | { $_[0]->{session} } | ||
| 3483 | |||
| 3484 | sub name | ||
| 3485 | { $_[0]->{name} } | ||
| 3486 | sub filePath | ||
| 3487 | { $_[0]->{filePath} } | ||
| 3488 | |||
| 3489 | sub lineHash | ||
| 3490 | { my $self = shift; return %{$self->{lineHash}}; } | ||
| 3491 | sub lineCount | ||
| 3492 | { $_[0]->{lineCount} } | ||
| 3493 | sub currentLine | ||
| 3494 | { $_[0]->{currentLine} } | ||
| 3495 | sub nextLine | ||
| 3496 | { $_[0]->{nextLine} } | ||
| 3497 | sub nextStatement | ||
| 3498 | { $_[0]->{nextStatement} } | ||
| 3499 | |||
| 3500 | sub primLineHash | ||
| 3501 | { my $self = shift; return %{$self->{primLineHash}}; } | ||
| 3502 | |||
| 3503 | sub executionMode | ||
| 3504 | { $_[0]->{executionMode} } | ||
| 3505 | sub allErrorsFlag | ||
| 3506 | { $_[0]->{allErrorsFlag} } | ||
| 3507 | sub implementFlag | ||
| 3508 | { $_[0]->{implementFlag} } | ||
| 3509 | |||
| 3510 | sub keywordList | ||
| 3511 | { my $self = shift; return @{$self->{keywordList}}; } | ||
| 3512 | sub keywordHash | ||
| 3513 | { my $self = shift; return %{$self->{keywordHash}}; } | ||
| 3514 | sub modernKeywordList | ||
| 3515 | { my $self = shift; return @{$self->{modernKeywordList}}; } | ||
| 3516 | sub primKeywordList | ||
| 3517 | { my $self = shift; return @{$self->{primKeywordList}}; } | ||
| 3518 | sub peekPokeList | ||
| 3519 | { my $self = shift; return @{$self->{peekPokeList}}; } | ||
| 3520 | sub weakKeywordHash | ||
| 3521 | { my $self = shift; return %{$self->{weakKeywordHash}}; } | ||
| 3522 | sub equivKeywordHash | ||
| 3523 | { my $self = shift; return %{$self->{equivKeywordHash}}; } | ||
| 3524 | sub clientKeywordList | ||
| 3525 | { my $self = shift; return @{$self->{clientKeywordList}}; } | ||
| 3526 | sub taskKeywordList | ||
| 3527 | { my $self = shift; return @{$self->{taskKeywordList}}; } | ||
| 3528 | sub logicalOpList | ||
| 3529 | { my $self = shift; return @{$self->{logicalOpList}}; } | ||
| 3530 | sub regexHash | ||
| 3531 | { my $self = shift; return %{$self->{regexHash}}; } | ||
| 3532 | sub categoryList | ||
| 3533 | { my $self = shift; return @{$self->{categoryList}}; } | ||
| 3534 | |||
| 3535 | sub scriptStatus | ||
| 3536 | { $_[0]->{scriptStatus} } | ||
| 3537 | sub executionStatus | ||
| 3538 | { $_[0]->{executionStatus} } | ||
| 3539 | |||
| 3540 | sub parentTask | ||
| 3541 | { $_[0]->{parentTask} } | ||
| 3542 | sub stepMax | ||
| 3543 | { $_[0]->{stepMax} } | ||
| 3544 | sub stepCount | ||
| 3545 | { $_[0]->{stepCount} } | ||
| 3546 | |||
| 3547 | sub indepInterfaceList | ||
| 3548 | { my $self = shift; return @{$self->{indepInterfaceList}}; } | ||
| 3549 | sub indepInterfaceName | ||
| 3550 | { $_[0]->{indepInterfaceName} } | ||
| 3551 | sub depInterfaceList | ||
| 3552 | { my $self = shift; return @{$self->{depInterfaceList}}; } | ||
| 3553 | sub depInterfaceName | ||
| 3554 | { $_[0]->{depInterfaceName} } | ||
| 3555 | sub notificationList | ||
| 3556 | { my $self = shift; return @{$self->{notificationList}}; } | ||
| 3557 | sub currentNotification | ||
| 3558 | { $_[0]->{currentNotification} } | ||
| 3559 | |||
| 3560 | sub errorList | ||
| 3561 | { my $self = shift; return @{$self->{errorList}}; } | ||
| 3562 | |||
| 3563 | sub subStackList | ||
| 3564 | { my $self = shift; return @{$self->{subStackList}}; } | ||
| 3565 | sub subCount | ||
| 3566 | { $_[0]->{subCount} } | ||
| 3567 | sub gosubStackList | ||
| 3568 | { my $self = shift; return @{$self->{gosubStackList}}; } | ||
| 3569 | |||
| 3570 | sub subNameHash | ||
| 3571 | { my $self = shift; return %{$self->{subNameHash}}; } | ||
| 3572 | sub funcNameHash | ||
| 3573 | { my $self = shift; return %{$self->{funcNameHash}}; } | ||
| 3574 | sub funcArgHash | ||
| 3575 | { my $self = shift; return %{$self->{funcArgHash}}; } | ||
| 3576 | sub currentParseSub | ||
| 3577 | { $_[0]->{currentParseSub} } | ||
| 3578 | |||
| 3579 | sub column | ||
| 3580 | { $_[0]->{column} } | ||
| 3581 | |||
| 3582 | sub declareMode | ||
| 3583 | { $_[0]->{declareMode} } | ||
| 3584 | sub globalScalarHash | ||
| 3585 | { my $self = shift; return %{$self->{globalScalarHash}}; } | ||
| 3586 | sub globalArrayHash | ||
| 3587 | { my $self = shift; return %{$self->{globalArrayHash}}; } | ||
| 3588 | |||
| 3589 | sub globalDataList | ||
| 3590 | { my $self = shift; return @{$self->{globalDataList}}; } | ||
| 3591 | sub readDataList | ||
| 3592 | { my $self = shift; return @{$self->{readDataList}}; } | ||
| 3593 | |||
| 3594 | sub fileChannelHash | ||
| 3595 | { my $self = shift; return %{$self->{fileChannelHash}}; } | ||
| 3596 | |||
| 3597 | sub optionStatementHash | ||
| 3598 | { my $self = shift; return %{$self->{optionStatementHash}}; } | ||
| 3599 | |||
| 3600 | sub inputList | ||
| 3601 | { my $self = shift; return @{$self->{inputList}}; } | ||
| 3602 | sub pseudoCmdMode | ||
| 3603 | { $_[0]->{pseudoCmdMode} } | ||
| 3604 | sub forcedWinFlag | ||
| 3605 | { $_[0]->{forcedWinFlag} } | ||
| 3606 | sub endStatementFlag | ||
| 3607 | { $_[0]->{endStatementFlag} } | ||
| 3608 | sub useProfile | ||
| 3609 | { $_[0]->{useProfile} } | ||
| 3610 | } | ||
| 3611 | |||
| 3612 | { package Language::Axbasic::Line; | ||
| 3613 | |||
| 3614 | use strict; | ||
| 3615 | use warnings; | ||
| 3616 | # use diagnostics; | ||
| 3617 | |||
| 3618 | use Glib qw(TRUE FALSE); | ||
| 3619 | |||
| 3620 | @Language::Axbasic::Line::ISA = qw( | ||
| 3621 | Language::Axbasic | ||
| 3622 | ); | ||
| 3623 | |||
| 3624 | ################## | ||
| 3625 | # Constructors | ||
| 3626 | |||
| 3627 | sub new { | ||
| 3628 | |||
| 3629 | # Called by LA::RawScript->upload | ||
| 3630 | # The class that handles a single line in the script, which contains one or more statements | ||
| 3631 | # (e.g. FOR A = 1 to 10 : NEXT A) | ||
| 3632 | # (This object has no ->implement method) | ||
| 3633 | # | ||
| 3634 | # Expected arguments | ||
| 3635 | # $scriptObj - Blessed reference to the parent LA::Script | ||
| 3636 | # $lineText - The line itself, e.g. 'FOR A = 1 to 10 : NEXT A' | ||
| 3637 | # $origLineNum - The number of this line in the original, unprocessed script (matches a | ||
| 3638 | # key in LA::RawScript->lineHash) | ||
| 3639 | # $procLineNum - The number of this line in the processed script stored by the parent | ||
| 3640 | # LA::Script (matches a key in LA::Script->lineHash) | ||
| 3641 | # | ||
| 3642 | # Optional arguments | ||
| 3643 | # $primLineNum - (LA::Script->executionMode 'line_num' for primitive line numbering) | ||
| 3644 | # the primitive line number of this line, e.g. '100 goto 50' > 100 | ||
| 3645 | # | ||
| 3646 | # Return values | ||
| 3647 | # 'undef' on improper arguments | ||
| 3648 | # Blessed reference to the newly-created object on success | ||
| 3649 | |||
| 3650 | my ($class, $scriptObj, $lineText, $origLineNum, $procLineNum, $primLineNum, $check) = @_; | ||
| 3651 | |||
| 3652 | # Check for improper arguments | ||
| 3653 | if ( | ||
| 3654 | ! defined $class || ! defined $scriptObj || ! defined $lineText | ||
| 3655 | || ! defined $origLineNum || ! defined $procLineNum || defined $check | ||
| 3656 | ) { | ||
| 3657 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3658 | } | ||
| 3659 | |||
| 3660 | # Setup | ||
| 3661 | my $self = { | ||
| 3662 | _objName => $class, # Name Axbasic objects after their class | ||
| 3663 | _objClass => $class, | ||
| 3664 | _parentFile => undef, # No parent file object | ||
| 3665 | _parentWorld => undef, # No parent file object | ||
| 3666 | _privFlag => TRUE, # All IVs are private | ||
| 3667 | |||
| 3668 | # Perl object components | ||
| 3669 | # ---------------------- | ||
| 3670 | |||
| 3671 | # The parent LA::Script | ||
| 3672 | scriptObj => $scriptObj, | ||
| 3673 | |||
| 3674 | # IVs | ||
| 3675 | # ---- | ||
| 3676 | |||
| 3677 | # The line of text from the script | ||
| 3678 | lineText => $lineText, | ||
| 3679 | # The number of this line in the original, unprocessed script | ||
| 3680 | origLineNum => $origLineNum, | ||
| 3681 | # The number of this line in the processed script | ||
| 3682 | procLineNum => $procLineNum, | ||
| 3683 | # For primitive line numbering - the primitive line number (not related to ->origLineNum | ||
| 3684 | # or ->procLineNum; may be 'undef') | ||
| 3685 | primLineNum => $primLineNum, | ||
| 3686 | |||
| 3687 | # Set by $self->parse - blessed reference of the first LA::Statement on the line. Each | ||
| 3688 | # statement has a ->nextStatement IV which gives us a list of statements in the order | ||
| 3689 | # in which they should be parsed/implemented | ||
| 3690 | firstStatement => undef, | ||
| 3691 | }; | ||
| 3692 | |||
| 3693 | bless $self, $class; | ||
| 3694 | return $self; | ||
| 3695 | } | ||
| 3696 | |||
| 3697 | ################## | ||
| 3698 | # Methods | ||
| 3699 | |||
| 3700 | sub parse { | ||
| 3701 | |||
| 3702 | # Called by LA::Script->parse and LA::Script->implement | ||
| 3703 | # Breaks up a line into statements, then parses the statements in order | ||
| 3704 | # | ||
| 3705 | # Expected arguments | ||
| 3706 | # (none besides $self) | ||
| 3707 | # | ||
| 3708 | # Return values | ||
| 3709 | # 'undef' on improper arguments, or if there is an error | ||
| 3710 | # 1 on success | ||
| 3711 | |||
| 3712 | my ($self, $check) = @_; | ||
| 3713 | |||
| 3714 | # Local variables | ||
| 3715 | my ($tokenGroup, $statement, $oldStatement); | ||
| 3716 | |||
| 3717 | # Check for improper arguments | ||
| 3718 | if (defined $check) { | ||
| 3719 | |||
| 3720 | return $axmud::CLIENT->writeImproper($self->_objClass . '->parse', @_); | ||
| 3721 | } | ||
| 3722 | |||
| 3723 | # Create a token group | ||
| 3724 | $tokenGroup = Language::Axbasic::TokenGroup->new($self->scriptObj, $self->lineText); | ||
| 3725 | if (! defined $tokenGroup) { | ||
| 3726 | |||
| 3727 | return $self->scriptObj->setDebug( | ||
| 3728 | 'Can\'t create token group object', | ||
| 3729 | $self->_objClass . '->parse', | ||
| 3730 | ); | ||
| 3731 | } | ||
| 3732 | |||
| 3733 | # Break the line up into tokens, and store the tokens as a list in the token group (any | ||
| 3734 | # access to the tokens is through the token group's methods) | ||
| 3735 | if (! $tokenGroup->lex()) { | ||
| 3736 | |||
| 3737 | return undef; | ||
| 3738 | } | ||
| 3739 | |||
| 3740 | # Parse statements on this line, one after the other | ||
| 3741 | do { | ||
| 3742 | |||
| 3743 | # Create a statement object, and work out what kind of statement it is ($statement will | ||
| 3744 | # be an object of the subclass LA::Statement::*) | ||
| 3745 | $statement = Language::Axbasic::Statement->new($self->scriptObj, $self, $tokenGroup); | ||
| 3746 | if (! defined $statement) { | ||
| 3747 | |||
| 3748 | return $self->scriptObj->setDebug( | ||
| 3749 | 'Can\'t create statement object', | ||
| 3750 | $self->_objClass . '->parse', | ||
| 3751 | ); | ||
| 3752 | } | ||
| 3753 | |||
| 3754 | # Parse the statement | ||
| 3755 | if (! $statement->parse()) { | ||
| 3756 | |||
| 3757 | return undef; | ||
| 3758 | } | ||
| 3759 | |||
| 3760 | # Build a list of statements in the line. The first statement on the line is stored in | ||
| 3761 | # $self->firstStatement; every subsequent statement is stored in the previous | ||
| 3762 | # statement object's ->nextStatement IV | ||
| 3763 | if (defined $oldStatement) { | ||
| 3764 | |||
| 3765 | $oldStatement->set_nextStatement($statement); | ||
| 3766 | |||
| 3767 | } else { | ||
| 3768 | |||
| 3769 | $self->ivPoke('firstStatement', $statement); | ||
| 3770 | } | ||
| 3771 | |||
| 3772 | $oldStatement = $statement; | ||
| 3773 | |||
| 3774 | # Check the next token in the token group. If there are none, we have finished parsing | ||
| 3775 | # this line. If it's a 'statement_end' token, another statement follows it. If it's | ||
| 3776 | # some other kind of token, it's a syntax error | ||
| 3777 | |||
| 3778 | # If there's a colon at the end of the statement, separating it from the next statement | ||
| 3779 | # on the line, shift the corresponding token out of the token group so that, on the | ||
| 3780 | # next DO..WHILE loop, the first token in the group is the beginning of the next | ||
| 3781 | # statement can be parsed | ||
| 3782 | if (! $tokenGroup->shiftTokenIfCategory('statement_end')) { | ||
| 3783 | |||
| 3784 | # But if there are other kinds of tokens at the end of the statement, it's a syntax | ||
| 3785 | # error | ||
| 3786 | if (! defined $tokenGroup->testStatementEnd()) { | ||
| 3787 | |||
| 3788 | return $self->scriptObj->setError( | ||
| 3789 | 'syntax_error', | ||
| 3790 | $self->_objClass . '->parse', | ||
| 3791 | ); | ||
| 3792 | } | ||
| 3793 | } | ||
| 3794 | |||
| 3795 | } while (! defined $tokenGroup->testStatementEnd()); | ||
| 3796 | |||
| 3797 | # Parsing complete | ||
| 3798 | return 1; | ||
| 3799 | } | ||
| 3800 | |||
| 3801 | ################## | ||
| 3802 | # Accessors - set | ||
| 3803 | |||
| 3804 | ################## | ||
| 3805 | # Accessors - get | ||
| 3806 | |||
| 3807 | sub scriptObj | ||
| 3808 | { $_[0]->{scriptObj} } | ||
| 3809 | |||
| 3810 | sub lineText | ||
| 3811 | { $_[0]->{lineText} } | ||
| 3812 | sub origLineNum | ||
| 3813 | { $_[0]->{origLineNum} } | ||
| 3814 | sub procLineNum | ||
| 3815 | { $_[0]->{procLineNum} } | ||
| 3816 | sub primLineNum | ||
| 3817 | { $_[0]->{primLineNum} } | ||
| 3818 | |||
| 3819 | sub firstStatement | ||
| 3820 | { $_[0]->{firstStatement} } | ||
| 3821 | } | ||
| 3822 | |||
| 3823 | { package Language::Axbasic::Notification; | ||
| 3824 | |||
| 3825 | use strict; | ||
| 3826 | use warnings; | ||
| 3827 | # use diagnostics; | ||
| 3828 | |||
| 3829 | use Glib qw(TRUE FALSE); | ||
| 3830 | |||
| 3831 | @Language::Axbasic::Notification::ISA = qw( | ||
| 3832 | Language::Axbasic | ||
| 3833 | ); | ||
| 3834 | |||
| 3835 | ################## | ||
| 3836 | # Constructors | ||
| 3837 | |||
| 3838 | sub new { | ||
| 3839 | |||
| 3840 | # Called by LA::Script->interfaceNotification | ||
| 3841 | # Whenever an interface created by a SETTRIG (etc) statement fires, information about the | ||
| 3842 | # event is passed to LA::Script->interfaceNotification, which in turn calls this function | ||
| 3843 | # The new LA::Notification object stores information about a single such event, ready for | ||
| 3844 | # the Axbasic script to use when it is ready | ||
| 3845 | # | ||
| 3846 | # Expected arguments | ||
| 3847 | # $scriptObj - Blessed reference to the parent LA::Script | ||
| 3848 | # $interfaceObj - The active interface which has fired | ||
| 3849 | # $fireBecause - A scalar describing why the interface fired (see the comments in | ||
| 3850 | # LA::Script->interfaceNotification for a list of values) | ||
| 3851 | # | ||
| 3852 | # Optional arguments | ||
| 3853 | # @dataList - A list of additional data, supplied by the interface when it | ||
| 3854 | # fired (may be an empty list) | ||
| 3855 | # | ||
| 3856 | # Return values | ||
| 3857 | # 'undef' on improper arguments | ||
| 3858 | # Blessed reference to the newly-created object on success | ||
| 3859 | |||
| 3860 | my ($class, $scriptObj, $interfaceObj, $fireBecause, @dataList) = @_; | ||
| 3861 | |||
| 3862 | if ( | ||
| 3863 | ! defined $class || ! defined $scriptObj || ! defined $interfaceObj | ||
| 3864 | || ! defined $fireBecause | ||
| 3865 | ) { | ||
| 3866 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3867 | } | ||
| 3868 | |||
| 3869 | # Setup | ||
| 3870 | my $self = { | ||
| 3871 | _objName => $class, # Name Axbasic objects after their class | ||
| 3872 | _objClass => $class, | ||
| 3873 | _parentFile => undef, # No parent file object | ||
| 3874 | _parentWorld => undef, # No parent file object | ||
| 3875 | _privFlag => TRUE, # All IVs are private | ||
| 3876 | |||
| 3877 | # Perl object components | ||
| 3878 | # ---------------------- | ||
| 3879 | |||
| 3880 | # The parent LA::Script | ||
| 3881 | scriptObj => $scriptObj, | ||
| 3882 | |||
| 3883 | # IVs | ||
| 3884 | # ---- | ||
| 3885 | |||
| 3886 | # The active interface | ||
| 3887 | interfaceObj => $interfaceObj, | ||
| 3888 | # IVs for quick checking | ||
| 3889 | category => $interfaceObj->category, | ||
| 3890 | number => $interfaceObj->number, | ||
| 3891 | name => $interfaceObj->name, | ||
| 3892 | time => $scriptObj->session->sessionTime, | ||
| 3893 | |||
| 3894 | # A scalar describing why the interface fired (see the comments in | ||
| 3895 | # LA::Script->interfaceNotification for a list of values) | ||
| 3896 | fireBecause => $fireBecause, | ||
| 3897 | # A list of additional data, supplied by the interface when it fired (may be an empty | ||
| 3898 | # list) | ||
| 3899 | dataList => \@dataList, | ||
| 3900 | }; | ||
| 3901 | |||
| 3902 | # Bless the object into existence | ||
| 3903 | bless $self, $class; | ||
| 3904 | return $self; | ||
| 3905 | } | ||
| 3906 | |||
| 3907 | ################## | ||
| 3908 | # Methods | ||
| 3909 | |||
| 3910 | ################## | ||
| 3911 | # Accessors - set | ||
| 3912 | |||
| 3913 | ################## | ||
| 3914 | # Accessors - get | ||
| 3915 | |||
| 3916 | sub scriptObj | ||
| 3917 | { $_[0]->{scriptObj} } | ||
| 3918 | |||
| 3919 | sub interfaceObj | ||
| 3920 | { $_[0]->{interfaceObj} } | ||
| 3921 | sub category | ||
| 3922 | { $_[0]->{category} } | ||
| 3923 | sub number | ||
| 3924 | { $_[0]->{number} } | ||
| 3925 | sub name | ||
| 3926 | { $_[0]->{name} } | ||
| 3927 | sub time | ||
| 3928 | { $_[0]->{time} } | ||
| 3929 | |||
| 3930 | sub fireBecause | ||
| 3931 | { $_[0]->{fireBecause} } | ||
| 3932 | sub dataList | ||
| 3933 | { my $self = shift; return @{$self->{dataList}}; } | ||
| 3934 | } | ||
| 3935 | |||
| 3936 | { package Language::Axbasic::TokenGroup; | ||
| 3937 | |||
| 3938 | use strict; | ||
| 3939 | use warnings; | ||
| 3940 | # use diagnostics; | ||
| 3941 | |||
| 3942 | use Glib qw(TRUE FALSE); | ||
| 3943 | |||
| 3944 | @Language::Axbasic::TokenGroup::ISA = qw( | ||
| 3945 | Language::Axbasic | ||
| 3946 | ); | ||
| 3947 | |||
| 3948 | ################## | ||
| 3949 | # Constructors | ||
| 3950 | |||
| 3951 | sub new { | ||
| 3952 | |||
| 3953 | # Called by LA::Line->parse (which also acts in the place of LA::Line->implement, which | ||
| 3954 | # doesn't exist) or by any other function which wants to convert some text into a list of | ||
| 3955 | # tokens | ||
| 3956 | # | ||
| 3957 | # The class that handles a group of tokens | ||
| 3958 | # Text from a line in the Axbasic script is lexed and turned into Axbasic tokens which are | ||
| 3959 | # stored in this object's ->tokenList | ||
| 3960 | # Any access to these tokens (including creating them) is through this object's methods | ||
| 3961 | # Other classes' ->parse methods will usually eat their way through the tokens in this | ||
| 3962 | # object's ->tokenList until the list is empty | ||
| 3963 | # | ||
| 3964 | # Expected arguments | ||
| 3965 | # $scriptObj - Blessed reference to the parent LA::Script | ||
| 3966 | # | ||
| 3967 | # Optional arguments | ||
| 3968 | # $text - The text to be lexed, e.g. 'FOR A = 1 to 10 : NEXT A' (may be a complete | ||
| 3969 | # line, or a partial line). If not specified, then $self->importTokens | ||
| 3970 | # should be called instead of $self->lex | ||
| 3971 | # | ||
| 3972 | # Return values | ||
| 3973 | # 'undef' on improper arguments | ||
| 3974 | # Blessed reference to the newly-created object on success | ||
| 3975 | |||
| 3976 | my ($class, $scriptObj, $text, $check) = @_; | ||
| 3977 | |||
| 3978 | # Check for improper arguments | ||
| 3979 | if (! defined $class || ! defined $scriptObj || defined $check) { | ||
| 3980 | |||
| 3981 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3982 | } | ||
| 3983 | |||
| 3984 | # Setup | ||
| 3985 | my $self = { | ||
| 3986 | _objName => 'token_group', | ||
| 3987 | _objClass => $class, | ||
| 3988 | _parentFile => undef, # No parent file object | ||
| 3989 | _parentWorld => undef, # No parent file object | ||
| 3990 | _privFlag => TRUE, # All IVs are private | ||
| 3991 | |||
| 3992 | # Perl object components | ||
| 3993 | # ---------------------- | ||
| 3994 | |||
| 3995 | # Blessed reference of the parent LA::Script object | ||
| 3996 | scriptObj => $scriptObj, | ||
| 3997 | |||
| 3998 | # IVs | ||
| 3999 | # --- | ||
| 4000 | |||
| 4001 | # The text to be lexed (if supplied) | ||
| 4002 | text => $text, | ||
| 4003 | # The list of tokens, compiled after lexing, and gradually removed (starting with the | ||
| 4004 | # first token in the list) by calls to this object's methods | ||
| 4005 | tokenList => [], | ||
| 4006 | # Flag set to TRUE if the token group ended with a 'short_comment' token (which was not | ||
| 4007 | # added to ->tokenList) | ||
| 4008 | shortCommentFlag => FALSE, | ||
| 4009 | }; | ||
| 4010 | |||
| 4011 | bless $self, $class; | ||
| 4012 | return $self; | ||
| 4013 | } | ||
| 4014 | |||
| 4015 | ################## | ||
| 4016 | # Methods | ||
| 4017 | |||
| 4018 | sub lex { | ||
| 4019 | |||
| 4020 | # Called by LA::Line->parse (which also acts in the place of LA::Line->implement, which | ||
| 4021 | # doesn't exist) or by any other function which wants to convert some text into a list of | ||
| 4022 | # tokens | ||
| 4023 | # Breaks the line of Axbasic text in $self->text into LA::Token objects and puts them in | ||
| 4024 | # $self->tokenList, in the order in which they were encountered | ||
| 4025 | # Stops lexing at the first '!' token, which means the rest of the line is a comment | ||
| 4026 | # | ||
| 4027 | # Expected arguments | ||
| 4028 | # (none besides $self) | ||
| 4029 | # | ||
| 4030 | # Return values | ||
| 4031 | # 'undef' on improper arguments or if there's an error creating a LA::Token object | ||
| 4032 | # 1 otherwise | ||
| 4033 | |||
| 4034 | my ($self, $check) = @_; | ||
| 4035 | |||
| 4036 | # Local variables | ||
| 4037 | my $token; | ||
| 4038 | |||
| 4039 | # Check for improper arguments | ||
| 4040 | if (defined $check) { | ||
| 4041 | |||
| 4042 | return $axmud::CLIENT->writeImproper($self->_objClass . '->lex', @_); | ||
| 4043 | } | ||
| 4044 | |||
| 4045 | do { | ||
| 4046 | |||
| 4047 | $token = Language::Axbasic::Token->new($self->scriptObj, $self->text); | ||
| 4048 | if (! defined $token) { | ||
| 4049 | |||
| 4050 | return undef; | ||
| 4051 | } | ||
| 4052 | |||
| 4053 | if (! $token->extract()) { | ||
| 4054 | |||
| 4055 | # An invalid token, like 'string' instead of "string" | ||
| 4056 | return $self->scriptObj->setError( | ||
| 4057 | 'syntax_error', | ||
| 4058 | $self->_objClass . '->lex', | ||
| 4059 | ); | ||
| 4060 | |||
| 4061 | return undef; | ||
| 4062 | |||
| 4063 | } else { | ||
| 4064 | |||
| 4065 | if ($token->category eq 'short_comment') { | ||
| 4066 | |||
| 4067 | # ! encountered, meaning that the rest of the line is a comment. Set a flag, so | ||
| 4068 | # that LA::Statement->refine knows this line did contain a valid token | ||
| 4069 | $self->ivPoke('shortCommentFlag', TRUE); | ||
| 4070 | |||
| 4071 | } else { | ||
| 4072 | |||
| 4073 | # LA::Token was able to extract a token from $self->text | ||
| 4074 | # Add the LA::Token object to this object's token list and, on the next loop, | ||
| 4075 | # search for tokens on the remainder of $self->text | ||
| 4076 | $self->ivPush('tokenList', $token); | ||
| 4077 | $self->ivPoke('text', $token->remainText); | ||
| 4078 | } | ||
| 4079 | } | ||
| 4080 | |||
| 4081 | # Continue until there are no tokens left | ||
| 4082 | } until ($self->text eq '' || $token->category eq 'short_comment'); | ||
| 4083 | |||
| 4084 | return 1; | ||
| 4085 | } | ||
| 4086 | |||
| 4087 | sub lookAhead { | ||
| 4088 | |||
| 4089 | # Can be called by anything (all access to tokens is via LA::TokenGroup's methods) | ||
| 4090 | # Returns the first token in the group without removing it from the group, but returns | ||
| 4091 | # 'undef' if there are no more tokens left | ||
| 4092 | # | ||
| 4093 | # Expected arguments | ||
| 4094 | # (none besides $self) | ||
| 4095 | # | ||
| 4096 | # Return values | ||
| 4097 | # 'undef' on improper arguments or if there are no tokens left in $self->tokenList | ||
| 4098 | # Otherwise returns the blessed reference of the token | ||
| 4099 | |||
| 4100 | my ($self, $check) = @_; | ||
| 4101 | |||
| 4102 | # Check for improper arguments | ||
| 4103 | if (defined $check) { | ||
| 4104 | |||
| 4105 | return $axmud::CLIENT->writeImproper($self->_objClass . '->lookAhead', @_); | ||
| 4106 | } | ||
| 4107 | |||
| 4108 | if ($self->tokenList) { | ||
| 4109 | |||
| 4110 | return $self->ivFirst('tokenList'); | ||
| 4111 | |||
| 4112 | } else { | ||
| 4113 | |||
| 4114 | return undef; | ||
| 4115 | } | ||
| 4116 | } | ||
| 4117 | |||
| 4118 | sub shiftToken { | ||
| 4119 | |||
| 4120 | # Can be called by anything (all access to tokens is via LA::TokenGroup's methods) | ||
| 4121 | # Removes the first token in the group and returns its blessed reference, but returns | ||
| 4122 | # 'undef' if there are no more tokens left | ||
| 4123 | # | ||
| 4124 | # Expected arguments | ||
| 4125 | # (none besides $self) | ||
| 4126 | # | ||
| 4127 | # Return values | ||
| 4128 | # 'undef' on improper arguments or if there are no tokens left in $self->tokenList | ||
| 4129 | # Otherwise returns the blessed reference of the removed token | ||
| 4130 | |||
| 4131 | my ($self, $check) = @_; | ||
| 4132 | |||
| 4133 | # Check for improper arguments | ||
| 4134 | if (defined $check) { | ||
| 4135 | |||
| 4136 | return $axmud::CLIENT->writeImproper($self->_objClass . '->shiftToken', @_); | ||
| 4137 | } | ||
| 4138 | |||
| 4139 | if ($self->tokenList) { | ||
| 4140 | |||
| 4141 | return $self->ivShift('tokenList'); | ||
| 4142 | |||
| 4143 | } else { | ||
| 4144 | |||
| 4145 | return undef; | ||
| 4146 | } | ||
| 4147 | } | ||
| 4148 | |||
| 4149 | sub shiftMatchingToken { | ||
| 4150 | |||
| 4151 | # Can be called by anything (all access to tokens is via LA::TokenGroup's methods) | ||
| 4152 | # If the text of the first token in the group (LA::Token->tokenText) matches the specified | ||
| 4153 | # argument (exactly), removes it from the group and returns its blessed reference | ||
| 4154 | # Otherwise returns 'undef' | ||
| 4155 | # | ||
| 4156 | # Expected arguments | ||
| 4157 | # $matchString - The string to match | ||
| 4158 | # | ||
| 4159 | # Return values | ||
| 4160 | # 'undef' on improper arguments, if there are no tokens left in $self->tokenList or if | ||
| 4161 | # the first token doesn't match the specified string | ||
| 4162 | # Otherwise returns the blessed reference of the removed token | ||
| 4163 | |||
| 4164 | my ($self, $matchString, $check) = @_; | ||
| 4165 | |||
| 4166 | # Check for improper arguments | ||
| 4167 | if (! defined $matchString || defined $check) { | ||
| 4168 | |||
| 4169 | return $axmud::CLIENT->writeImproper($self->_objClass . '->shiftMatchingToken', @_); | ||
| 4170 | } | ||
| 4171 | |||
| 4172 | if ($self->tokenList && $self->ivFirst('tokenList')->tokenText eq $matchString) { | ||
| 4173 | |||
| 4174 | return $self->ivShift('tokenList'); | ||
| 4175 | |||
| 4176 | } else { | ||
| 4177 | |||
| 4178 | return undef; | ||
| 4179 | } | ||
| 4180 | } | ||
| 4181 | |||
| 4182 | sub shiftTokenIfCategory { | ||
| 4183 | |||
| 4184 | # Can be called by anything (all access to tokens is via LA::TokenGroup's methods) | ||
| 4185 | # If the first token in the group is of the specified category, removes the token from the | ||
| 4186 | # group and returns its blessed reference | ||
| 4187 | # Otherwise returns 'undef' | ||
| 4188 | # | ||
| 4189 | # Expected arguments | ||
| 4190 | # $category - The category to match | ||
| 4191 | # | ||
| 4192 | # Return values | ||
| 4193 | # 'undef' on improper arguments, if there are no tokens left in $self->tokenList or if | ||
| 4194 | # the first token doesn't match the specified category | ||
| 4195 | # Otherwise returns the blessed reference of the removed token | ||
| 4196 | |||
| 4197 | my ($self, $category, $check) = @_; | ||
| 4198 | |||
| 4199 | # Local variables | ||
| 4200 | my $token; | ||
| 4201 | |||
| 4202 | # Check for improper arguments | ||
| 4203 | if (! defined $category || defined $check) { | ||
| 4204 | |||
| 4205 | return $axmud::CLIENT->writeImproper($self->_objClass . '->shiftTokenIfCategory', @_); | ||
| 4206 | } | ||
| 4207 | |||
| 4208 | if (! $self->tokenList) { | ||
| 4209 | |||
| 4210 | # No tokens left to compare | ||
| 4211 | return undef; | ||
| 4212 | |||
| 4213 | # Because the assignment operator '=' and the relational operator '=' are identical, we need | ||
| 4214 | # special tests for them | ||
| 4215 | } elsif ( | ||
| 4216 | $category eq 'relational_operator' | ||
| 4217 | && $self->ivFirst('tokenList')->category eq 'assignment_operator' | ||
| 4218 | ) { | ||
| 4219 | $token = $self->ivShift('tokenList'); | ||
| 4220 | # Change it from an assignment to a relational operator | ||
| 4221 | $token->ivPoke('category', 'relational_operator'); | ||
| 4222 | $token->set_category('relational_operator'); | ||
| 4223 | |||
| 4224 | return $token; | ||
| 4225 | |||
| 4226 | } elsif ( | ||
| 4227 | $category eq 'assignment_operator' | ||
| 4228 | && $self->ivFirst('tokenList')->category eq 'relational_operator' | ||
| 4229 | ) { | ||
| 4230 | $token = $self->ivShift('tokenList'); | ||
| 4231 | # Change it from an assignment to a relational operator | ||
| 4232 | $token->set_category('assignment_operator'); | ||
| 4233 | |||
| 4234 | return $token; | ||
| 4235 | |||
| 4236 | } elsif ($self->tokenList && $self->ivFirst('tokenList')->category eq $category) { | ||
| 4237 | |||
| 4238 | # Token categories match (exactly) | ||
| 4239 | return $self->ivShift('tokenList'); | ||
| 4240 | |||
| 4241 | } else { | ||
| 4242 | |||
| 4243 | # Token categories don't match at all | ||
| 4244 | return undef; | ||
| 4245 | } | ||
| 4246 | } | ||
| 4247 | |||
| 4248 | sub importTokens { | ||
| 4249 | |||
| 4250 | # Can be called by anything (all access to tokens is via LA::TokenGroup's methods) | ||
| 4251 | # Imports tokens into this group from another group until the other group has no more | ||
| 4252 | # tokens, or until the other group's first token has ->tokenText that matches a specified | ||
| 4253 | # string exactly (in which case, the token is not imported, and remains as the first token | ||
| 4254 | # in the other group) | ||
| 4255 | # | ||
| 4256 | # Expected arguments | ||
| 4257 | # $otherGroup - The other LA::TokenGroup from which to taken tokens | ||
| 4258 | # | ||
| 4259 | # Optional arguments | ||
| 4260 | # @matchList - A list of strings. If any of them match the other group's ->tokenText, | ||
| 4261 | # that ends the process. (If the list is empty, all tokens to the end | ||
| 4262 | # of the group are taken) | ||
| 4263 | # | ||
| 4264 | # Return values | ||
| 4265 | # 'undef' on improper arguments, if there are no tokens left in $otherGroup's token list | ||
| 4266 | # or if the first token in $otherGroup's token list matches a string in @matchList | ||
| 4267 | # exactly | ||
| 4268 | # Otherwise returns the number of tokens imported (which might be 0) | ||
| 4269 | |||
| 4270 | my ($self, $otherGroup, @matchList) = @_; | ||
| 4271 | |||
| 4272 | # Local variables | ||
| 4273 | my ($token, $count); | ||
| 4274 | |||
| 4275 | # Check for improper arguments | ||
| 4276 | if (! defined $otherGroup) { | ||
| 4277 | |||
| 4278 | return $axmud::CLIENT->writeImproper($self->_objClass . '->importTokens', @_); | ||
| 4279 | } | ||
| 4280 | |||
| 4281 | # Import tokens | ||
| 4282 | $count = 0; | ||
| 4283 | do { | ||
| 4284 | |||
| 4285 | $token = undef; | ||
| 4286 | |||
| 4287 | if ($otherGroup->tokenList) { | ||
| 4288 | |||
| 4289 | $token = $otherGroup->ivFirst('tokenList'); | ||
| 4290 | if (defined $token) { | ||
| 4291 | |||
| 4292 | foreach my $matchString (@matchList) { | ||
| 4293 | |||
| 4294 | if ($token->tokenText eq $matchString) { | ||
| 4295 | |||
| 4296 | # Stop importing. Return the number of imported tokens (may be 0) | ||
| 4297 | return $count; | ||
| 4298 | } | ||
| 4299 | } | ||
| 4300 | |||
| 4301 | # Otherwise, import this token | ||
| 4302 | $self->ivPush('tokenList', $token); | ||
| 4303 | $otherGroup->shiftToken(); | ||
| 4304 | $count++; | ||
| 4305 | } | ||
| 4306 | } | ||
| 4307 | |||
| 4308 | } until (! defined $token); | ||
| 4309 | |||
| 4310 | # Return the number of imported tokens (may be 0) | ||
| 4311 | return $count; | ||
| 4312 | } | ||
| 4313 | |||
| 4314 | sub testStatementEnd { | ||
| 4315 | |||
| 4316 | # Tests whether the statement being parsed has finished (ie there are no tokens left in the | ||
| 4317 | # token group, or the first token in the group is a colon) | ||
| 4318 | # | ||
| 4319 | # Expected arguments | ||
| 4320 | # (none besides $self) | ||
| 4321 | # | ||
| 4322 | # Return values | ||
| 4323 | # 'undef' on improper arguments or if the first token in the group isn't a statement | ||
| 4324 | # separator (ie colon) | ||
| 4325 | # 1 if there are no tokens left in the group, or the first token in the group is a | ||
| 4326 | # statement separator | ||
| 4327 | |||
| 4328 | my ($self, $check) = @_; | ||
| 4329 | |||
| 4330 | # Local variables | ||
| 4331 | my $token; | ||
| 4332 | |||
| 4333 | # Check for improper arguments | ||
| 4334 | if (defined $check) { | ||
| 4335 | |||
| 4336 | return $axmud::CLIENT->writeImproper($self->_objClass . '->testStatementEnd', @_); | ||
| 4337 | } | ||
| 4338 | |||
| 4339 | $token = $self->lookAhead(); | ||
| 4340 | if (! $token || $token->category eq 'statement_end') { | ||
| 4341 | |||
| 4342 | # No more tokens left, or we've reached the end of a statement | ||
| 4343 | return 1; | ||
| 4344 | |||
| 4345 | } else { | ||
| 4346 | |||
| 4347 | return undef; | ||
| 4348 | } | ||
| 4349 | } | ||
| 4350 | |||
| 4351 | ################## | ||
| 4352 | # Accessors - set | ||
| 4353 | |||
| 4354 | sub set_tokenList { | ||
| 4355 | |||
| 4356 | # Returns 'undef' on improper arguments | ||
| 4357 | # Returns 1 on success | ||
| 4358 | |||
| 4359 | my ($self, @list) = @_; | ||
| 4360 | |||
| 4361 | # (No improper arguments to check - @list can be empty) | ||
| 4362 | |||
| 4363 | $self->ivPoke('tokenList', @list); | ||
| 4364 | |||
| 4365 | return 1; | ||
| 4366 | } | ||
| 4367 | |||
| 4368 | ################## | ||
| 4369 | # Accessors - get | ||
| 4370 | |||
| 4371 | sub scriptObj | ||
| 4372 | { $_[0]->{scriptObj} } | ||
| 4373 | |||
| 4374 | sub text | ||
| 4375 | { $_[0]->{text} } | ||
| 4376 | sub tokenList | ||
| 4377 | { my $self = shift; return @{$self->{tokenList}}; } | ||
| 4378 | sub shortCommentFlag | ||
| 4379 | { $_[0]->{shortCommentFlag} } | ||
| 4380 | |||
| 4381 | } | ||
| 4382 | |||
| 4383 | { package Language::Axbasic::Token; | ||
| 4384 | |||
| 4385 | use strict; | ||
| 4386 | use warnings; | ||
| 4387 | # use diagnostics; | ||
| 4388 | |||
| 4389 | use Glib qw(TRUE FALSE); | ||
| 4390 | |||
| 4391 | @Language::Axbasic::Token::ISA = qw( | ||
| 4392 | Language::Axbasic | ||
| 4393 | ); | ||
| 4394 | |||
| 4395 | ################## | ||
| 4396 | # Constructors | ||
| 4397 | |||
| 4398 | sub new { | ||
| 4399 | |||
| 4400 | # Called by LA::TokenGroup->lex | ||
| 4401 | # The class that handles a single token. The calling function calls ->new to create the | ||
| 4402 | # LA::Token object, then ->extract to extract the token from the specified Axbasic text, | ||
| 4403 | # leaving a shorter piece of text | ||
| 4404 | # | ||
| 4405 | # Expected arguments | ||
| 4406 | # $scriptObj - Blessed reference to the parent LA::Script | ||
| 4407 | # $text - Some Axbasic text, which may be a complete or partial line | ||
| 4408 | # eg 'FOR A = 1 to 10 : NEXT A' | ||
| 4409 | # | ||
| 4410 | # Return values | ||
| 4411 | # 'undef' on improper arguments | ||
| 4412 | # Blessed reference to the newly-created object on success | ||
| 4413 | |||
| 4414 | my ($class, $scriptObj, $text, $check) = @_; | ||
| 4415 | |||
| 4416 | # Check for improper arguments | ||
| 4417 | if (! defined $class || ! defined $scriptObj || ! defined $text || defined $check) { | ||
| 4418 | |||
| 4419 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 4420 | } | ||
| 4421 | |||
| 4422 | # Setup | ||
| 4423 | my $self = { | ||
| 4424 | _objName => 'token', | ||
| 4425 | _objClass => $class, | ||
| 4426 | _parentFile => undef, # No parent file object | ||
| 4427 | _parentWorld => undef, # No parent file object | ||
| 4428 | _privFlag => TRUE, # All IVs are private | ||
| 4429 | |||
| 4430 | # Perl object components | ||
| 4431 | # ---------------------- | ||
| 4432 | |||
| 4433 | # Blessed reference of the parent LA::Script object | ||
| 4434 | scriptObj => $scriptObj, | ||
| 4435 | |||
| 4436 | # IVs | ||
| 4437 | # --- | ||
| 4438 | |||
| 4439 | # The text from which the token will be extracted - may be a complete or partial line of | ||
| 4440 | # BASIC | ||
| 4441 | text => $text, | ||
| 4442 | # The remaining text in ->text, after the token has been extracted | ||
| 4443 | remainText => undef, | ||
| 4444 | |||
| 4445 | # The extracted text of the token (e.g. 'print' or '$a'), converted to lower case | ||
| 4446 | # (except for string constants), and with leading whitespace removed | ||
| 4447 | tokenText => undef, | ||
| 4448 | # The extracted text of the token, before conversion, and with leading whitespace intact | ||
| 4449 | origTokenText => undef, | ||
| 4450 | # The leading whitespace (don't know why we need it, but still...) | ||
| 4451 | leadSpace => undef, | ||
| 4452 | |||
| 4453 | # The category of this token - one of the elements in ->categoryList | ||
| 4454 | category => undef, | ||
| 4455 | }; | ||
| 4456 | |||
| 4457 | bless $self, $class; | ||
| 4458 | return $self; | ||
| 4459 | } | ||
| 4460 | |||
| 4461 | ################## | ||
| 4462 | # Methods | ||
| 4463 | |||
| 4464 | sub extract { | ||
| 4465 | |||
| 4466 | # Called by LA::TokenGroup->lex | ||
| 4467 | # Extracts a single token from the beginning of $self->text. Reduces text outside of quotes | ||
| 4468 | # strings to lowercase, and saves the results in this object's instance variables, so | ||
| 4469 | # LA::TokenGroup->lex can access them | ||
| 4470 | # | ||
| 4471 | # Expected arguments | ||
| 4472 | # (none besides self) | ||
| 4473 | # | ||
| 4474 | # Return values | ||
| 4475 | # 'undef' on improper arguments, if no token can be extracted from $self->line or if the | ||
| 4476 | # whole of the rest of the line is a comment starting with ! | ||
| 4477 | # 1 otherwise | ||
| 4478 | |||
| 4479 | my ($self, $check) = @_; | ||
| 4480 | |||
| 4481 | # Local variables | ||
| 4482 | my $text; | ||
| 4483 | |||
| 4484 | # Check for improper arguments | ||
| 4485 | if (defined $check) { | ||
| 4486 | |||
| 4487 | return $axmud::CLIENT->writeImproper($self->_objClass . '->extract', @_); | ||
| 4488 | } | ||
| 4489 | |||
| 4490 | # The text from which the token is to be extracted | ||
| 4491 | $text = $self->text; | ||
| 4492 | |||
| 4493 | # Check each category of token in order. (The order is important, because the category | ||
| 4494 | # 'identifier' matches nearly all alphanumeric text) | ||
| 4495 | OUTER: foreach my $category ($self->scriptObj->categoryList) { | ||
| 4496 | |||
| 4497 | my ($regex, $origSpace, $tokenText); | ||
| 4498 | |||
| 4499 | if (! $self->scriptObj->ivExists('regexHash', $category)) { | ||
| 4500 | |||
| 4501 | return $self->scriptObj->setDebug( | ||
| 4502 | 'Missing regex for token category \'' . $category . '\'', | ||
| 4503 | $self->_objClass . '->extract', | ||
| 4504 | ); | ||
| 4505 | } | ||
| 4506 | |||
| 4507 | $regex = $self->scriptObj->ivShow('regexHash', $category); | ||
| 4508 | |||
| 4509 | if ($text =~ s/^(\s*)($regex)//) { | ||
| 4510 | |||
| 4511 | # Found a token matching $category | ||
| 4512 | $origSpace = $1; | ||
| 4513 | $tokenText = $2; | ||
| 4514 | |||
| 4515 | # (Special case: PRINT$ can be used as a variable, but PRINT obviously cannot. | ||
| 4516 | # The $regex picks up the PRINT portion of PRINT$ as a keyword, so we need to | ||
| 4517 | # convert it) | ||
| 4518 | if ($category eq 'keyword' && $text =~ s/^\$//) { | ||
| 4519 | |||
| 4520 | $category = 'identifier'; | ||
| 4521 | $tokenText .= '$'; | ||
| 4522 | } | ||
| 4523 | |||
| 4524 | # Most tokens are case-insensitive | ||
| 4525 | if ($category ne 'string_constant') { | ||
| 4526 | |||
| 4527 | $tokenText = lc($tokenText); | ||
| 4528 | } | ||
| 4529 | |||
| 4530 | # Store details of the token in this object's IVs | ||
| 4531 | $self->ivPoke('origTokenText', $origSpace . $tokenText); | ||
| 4532 | $self->ivPoke('leadSpace', $origSpace); | ||
| 4533 | $self->ivPoke('tokenText', $tokenText); | ||
| 4534 | $self->ivPoke('category', $category); | ||
| 4535 | $self->ivPoke('remainText', $text); | ||
| 4536 | |||
| 4537 | # Stop after finding the first bit of text matching a category of token in | ||
| 4538 | # @categoryList | ||
| 4539 | last OUTER; | ||
| 4540 | } | ||
| 4541 | } | ||
| 4542 | |||
| 4543 | if (! defined $self->category) { | ||
| 4544 | |||
| 4545 | # No tokens found | ||
| 4546 | return undef; | ||
| 4547 | |||
| 4548 | } else { | ||
| 4549 | |||
| 4550 | # Token found | ||
| 4551 | return 1; | ||
| 4552 | } | ||
| 4553 | } | ||
| 4554 | |||
| 4555 | ################## | ||
| 4556 | # Accessors - set | ||
| 4557 | |||
| 4558 | sub set_category { | ||
| 4559 | |||
| 4560 | # Returns 'undef' on improper arguments | ||
| 4561 | # Returns 1 on success | ||
| 4562 | |||
| 4563 | my ($self, $category, $check) = @_; | ||
| 4564 | |||
| 4565 | # Check for improper arguments | ||
| 4566 | if (! defined $category || defined $check) { | ||
| 4567 | |||
| 4568 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_category', @_); | ||
| 4569 | } | ||
| 4570 | |||
| 4571 | # Update IVs | ||
| 4572 | $self->ivPoke('category', $category); | ||
| 4573 | |||
| 4574 | return 1; | ||
| 4575 | } | ||
| 4576 | |||
| 4577 | sub set_tokenText { | ||
| 4578 | |||
| 4579 | # Called by LA::Statement::if->parse to convert an ELSEIF keyword token into an IF | ||
| 4580 | # Returns 'undef' on improper arguments | ||
| 4581 | # Returns 1 on success | ||
| 4582 | |||
| 4583 | my ($self, $tokenText, $check) = @_; | ||
| 4584 | |||
| 4585 | # Check for improper arguments | ||
| 4586 | if (! defined $tokenText || defined $check) { | ||
| 4587 | |||
| 4588 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tokenText', @_); | ||
| 4589 | } | ||
| 4590 | |||
| 4591 | # Update IVs | ||
| 4592 | $self->ivPoke('tokenText', $tokenText); | ||
| 4593 | |||
| 4594 | return 1; | ||
| 4595 | } | ||
| 4596 | |||
| 4597 | ################## | ||
| 4598 | # Accessors - get | ||
| 4599 | |||
| 4600 | sub scriptObj | ||
| 4601 | { $_[0]->{scriptObj} } | ||
| 4602 | |||
| 4603 | sub text | ||
| 4604 | { $_[0]->{text} } | ||
| 4605 | sub remainText | ||
| 4606 | { $_[0]->{remainText} } | ||
| 4607 | |||
| 4608 | sub tokenText | ||
| 4609 | { $_[0]->{tokenText} } | ||
| 4610 | sub origTokenText | ||
| 4611 | { $_[0]->{origTokenText} } | ||
| 4612 | sub leadSpace | ||
| 4613 | { $_[0]->{leadSpace} } | ||
| 4614 | |||
| 4615 | sub category | ||
| 4616 | { $_[0]->{category} } | ||
| 4617 | } | ||
| 4618 | |||
| 4619 | { package Language::Axbasic::FileChannel; | ||
| 4620 | |||
| 4621 | use strict; | ||
| 4622 | use warnings; | ||
| 4623 | # use diagnostics; | ||
| 4624 | |||
| 4625 | use Glib qw(TRUE FALSE); | ||
| 4626 | |||
| 4627 | @Language::Axbasic::FileChannel::ISA = qw( | ||
| 4628 | Language::Axbasic | ||
| 4629 | ); | ||
| 4630 | |||
| 4631 | ################## | ||
| 4632 | # Constructors | ||
| 4633 | |||
| 4634 | sub new { | ||
| 4635 | |||
| 4636 | # Called by LA::Statement::open->implement | ||
| 4637 | # The class that handles a file channel, opened with an OPEN statement and closed with a | ||
| 4638 | # CLOSE statement | ||
| 4639 | # | ||
| 4640 | # Expected arguments | ||
| 4641 | # $scriptObj - Blessed reference to the parent LA::Script | ||
| 4642 | # $channel - The file channel number (an integer, 1 or above) | ||
| 4643 | # $filePath - The file opened for reading/writing | ||
| 4644 | # $fileHandle - The filehandle used to read/write from the file | ||
| 4645 | # $orgType - In Axbasic, always set to 'text' | ||
| 4646 | # $createType - 'new', 'old' or 'newold' | ||
| 4647 | # $accessType - 'outin', 'input' or 'output' | ||
| 4648 | # | ||
| 4649 | # Return values | ||
| 4650 | # 'undef' on improper arguments | ||
| 4651 | # Blessed reference to the newly-created object on success | ||
| 4652 | |||
| 4653 | my ( | ||
| 4654 | $class, $scriptObj, $channel, $filePath, $fileHandle, $orgType, $createType, | ||
| 4655 | $accessType, $check | ||
| 4656 | ) = @_; | ||
| 4657 | |||
| 4658 | # Check for improper arguments | ||
| 4659 | if ( | ||
| 4660 | ! defined $class || ! defined $scriptObj || ! defined $channel || ! defined $filePath | ||
| 4661 | || ! defined $fileHandle || ! defined $orgType || ! defined $createType | ||
| 4662 | || defined $check | ||
| 4663 | ) { | ||
| 4664 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 4665 | } | ||
| 4666 | |||
| 4667 | # Setup | ||
| 4668 | my $self = { | ||
| 4669 | _objName => 'file_channel', | ||
| 4670 | _objClass => $class, | ||
| 4671 | _parentFile => undef, # No parent file object | ||
| 4672 | _parentWorld => undef, # No parent file object | ||
| 4673 | _privFlag => TRUE, # All IVs are private | ||
| 4674 | |||
| 4675 | # Perl object components | ||
| 4676 | # ---------------------- | ||
| 4677 | |||
| 4678 | # Blessed reference of the parent LA::Script object | ||
| 4679 | scriptObj => $scriptObj, | ||
| 4680 | |||
| 4681 | # IVs | ||
| 4682 | # --- | ||
| 4683 | |||
| 4684 | # The file channel number | ||
| 4685 | channel => $channel, | ||
| 4686 | # The file opened for reading/writing | ||
| 4687 | filePath => $filePath, | ||
| 4688 | # The filehandle used to read/write from the file | ||
| 4689 | fileHandle => $fileHandle, | ||
| 4690 | |||
| 4691 | # OPEN statement options | ||
| 4692 | # For 'ORGANIZATION TEXT' (default), set to 'text'. Axbasic does not implement True | ||
| 4693 | # BASIC's 'ORGANIZATION STREAM', 'ORGANIZATION RANDOM', 'ORGANIZATION RECORD' or | ||
| 4694 | # 'ORGANIZATION BYTE' | ||
| 4695 | orgType => $orgType, | ||
| 4696 | # For 'CREATE NEW', 'CREATE OLD' (default) or 'CREATE NEWOLD', set to 'new', 'old' or | ||
| 4697 | # 'newold' | ||
| 4698 | createType => $createType, | ||
| 4699 | # For 'ACCESS OUTIN' (default), 'ACCESS INPUT' or 'ACCESS OUTPUT', set to 'outin', | ||
| 4700 | # 'input' or 'output' | ||
| 4701 | accessType => $accessType, | ||
| 4702 | }; | ||
| 4703 | |||
| 4704 | bless $self, $class; | ||
| 4705 | return $self; | ||
| 4706 | } | ||
| 4707 | |||
| 4708 | ################## | ||
| 4709 | # Methods | ||
| 4710 | |||
| 4711 | ################## | ||
| 4712 | # Accessors - set | ||
| 4713 | |||
| 4714 | ################## | ||
| 4715 | # Accessors - get | ||
| 4716 | |||
| 4717 | sub scriptObj | ||
| 4718 | { $_[0]->{scriptObj} } | ||
| 4719 | |||
| 4720 | sub channel | ||
| 4721 | { $_[0]->{channel} } | ||
| 4722 | sub filePath | ||
| 4723 | { $_[0]->{filePath} } | ||
| 4724 | sub fileHandle | ||
| 4725 | { $_[0]->{fileHandle} } | ||
| 4726 | |||
| 4727 | sub orgType | ||
| 4728 | { $_[0]->{orgType} } | ||
| 4729 | sub createType | ||
| 4730 | { $_[0]->{createType} } | ||
| 4731 | sub accessType | ||
| 4732 | { $_[0]->{accessType} } | ||
| 4733 | } | ||
| 4734 | |||
| 4735 | # Package must return a true value | ||
| 4736 | 1 |