comparison website/src/manual.html.luan @ 502:d3183a330ff5

improve the __index metamethod to work with any type; simplify luan_proxy to eliminate base;
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 May 2015 17:57:20 -0600
parents 598123096772
children 92c3d22745b8
comparison
equal deleted inserted replaced
501:f26485a3692c 502:d3183a330ff5
341 <p> 341 <p>
342 Here are the events: 342 Here are the events:
343 343
344 <ul> 344 <ul>
345 345
346 <li><b>"add": </b> 346 <li><p><b>"add": </b>
347 the <tt>+</tt> operation. 347 the <tt>+</tt> operation.
348 348
349 If any operand for an addition is a table, 349 If any operand for an addition is a table,
350 Luan will try to call a metamethod. 350 Luan will try to call a metamethod.
351 First, Luan will check the first operand (even if it is valid). 351 First, Luan will check the first operand (even if it is valid).
358 is the result of the operation. 358 is the result of the operation.
359 Otherwise, 359 Otherwise,
360 it raises an error. 360 it raises an error.
361 </li> 361 </li>
362 362
363 <li><b>"sub": </b> 363 <li><p><b>"sub": </b>
364 the <tt>-</tt> operation. 364 the <tt>-</tt> operation.
365 365
366 Behavior similar to the "add" operation. 366 Behavior similar to the "add" operation.
367 </li> 367 </li>
368 368
369 <li><b>"mul": </b> 369 <li><p><b>"mul": </b>
370 the <tt>*</tt> operation. 370 the <tt>*</tt> operation.
371 371
372 Behavior similar to the "add" operation. 372 Behavior similar to the "add" operation.
373 </li> 373 </li>
374 374
375 <li><b>"div": </b> 375 <li><p><b>"div": </b>
376 the <tt>/</tt> operation. 376 the <tt>/</tt> operation.
377 377
378 Behavior similar to the "add" operation. 378 Behavior similar to the "add" operation.
379 </li> 379 </li>
380 380
381 <li><b>"mod": </b> 381 <li><p><b>"mod": </b>
382 the <tt>%</tt> operation. 382 the <tt>%</tt> operation.
383 383
384 Behavior similar to the "add" operation. 384 Behavior similar to the "add" operation.
385 </li> 385 </li>
386 386
387 <li><b>"pow": </b> 387 <li><p><b>"pow": </b>
388 the <tt>^</tt> (exponentiation) operation. 388 the <tt>^</tt> (exponentiation) operation.
389 389
390 Behavior similar to the "add" operation. 390 Behavior similar to the "add" operation.
391 </li> 391 </li>
392 392
393 <li><b>"unm": </b> 393 <li><p><b>"unm": </b>
394 the <tt>-</tt> (unary minus) operation. 394 the <tt>-</tt> (unary minus) operation.
395 395
396 Behavior similar to the "add" operation. 396 Behavior similar to the "add" operation.
397 </li> 397 </li>
398 398
399 <li><b>"concat": </b> 399 <li><p><b>"concat": </b>
400 the <tt>..</tt> (concatenation) operation. 400 the <tt>..</tt> (concatenation) operation.
401 401
402 Behavior similar to the "add" operation. 402 Behavior similar to the "add" operation.
403 </li> 403 </li>
404 404
405 <li><b>"len": </b> 405 <li><p><b>"len": </b>
406 the <tt>#</tt> (length) operation. 406 the <tt>#</tt> (length) operation.
407 407
408 If there is a metamethod, 408 If there is a metamethod,
409 Luan calls it with the object as argument, 409 Luan calls it with the object as argument,
410 and the result of the call 410 and the result of the call
413 If there is no metamethod but the object is a table, 413 If there is no metamethod but the object is a table,
414 then Luan uses the table length operation (see <a href="#length">The Length Operator</a>). 414 then Luan uses the table length operation (see <a href="#length">The Length Operator</a>).
415 Otherwise, Luan raises an error. 415 Otherwise, Luan raises an error.
416 </li> 416 </li>
417 417
418 <li><b>"eq": </b> 418 <li><p><b>"eq": </b>
419 the <tt>==</tt> (equal) operation. 419 the <tt>==</tt> (equal) operation.
420 420
421 Behavior similar to the "add" operation, 421 Behavior similar to the "add" operation,
422 except that Luan will try a metamethod only when the values 422 except that Luan will try a metamethod only when the values
423 being compared are both tables 423 being compared are both tables
424 and they are not primitively equal. 424 and they are not primitively equal.
425 The result of the call is always converted to a boolean. 425 The result of the call is always converted to a boolean.
426 </li> 426 </li>
427 427
428 <li><b>"lt": </b> 428 <li><p><b>"lt": </b>
429 the <tt>&lt;</tt> (less than) operation. 429 the <tt>&lt;</tt> (less than) operation.
430 430
431 Behavior similar to the "add" operation. 431 Behavior similar to the "add" operation.
432 The result of the call is always converted to a boolean. 432 The result of the call is always converted to a boolean.
433 </li> 433 </li>
434 434
435 <li><b>"le": </b> 435 <li><p><b>"le": </b>
436 the <tt>&lt;=</tt> (less equal) operation. 436 the <tt>&lt;=</tt> (less equal) operation.
437 437
438 Unlike other operations, 438 Unlike other operations,
439 The less-equal operation can use two different events. 439 The less-equal operation can use two different events.
440 First, Luan looks for the "<tt>__le</tt>" metamethod in both operands, 440 First, Luan looks for the "<tt>__le</tt>" metamethod in both operands,
444 assuming that <tt>a &lt;= b</tt> is equivalent to <tt>not (b &lt; a)</tt>. 444 assuming that <tt>a &lt;= b</tt> is equivalent to <tt>not (b &lt; a)</tt>.
445 As with the other comparison operators, 445 As with the other comparison operators,
446 the result is always a boolean. 446 the result is always a boolean.
447 </li> 447 </li>
448 448
449 <li><b>"index": </b> 449 <li><p><b>"index": </b>
450 The indexing access <tt>table[key]</tt>. 450 The indexing access <tt>table[key]</tt>.
451 451
452 This event happens 452 This event happens
453 when <tt>key</tt> is not present in <tt>table</tt>. 453 when <tt>key</tt> is not present in <tt>table</tt>.
454 The metamethod is looked up in <tt>table</tt>. 454 The metamethod is looked up in <tt>table</tt>.
455 455
456 456
457 <p> 457 <p>
458 Despite the name, 458 Despite the name,
459 the metamethod for this event can be either a function or a table. 459 the metamethod for this event can be any type.
460 If it is a function, 460 If it is a function,
461 it is called with <tt>table</tt> and <tt>key</tt> as arguments. 461 it is called with <tt>table</tt> and <tt>key</tt> as arguments.
462 If it is a table, 462 Otherwise
463 the final result is the result of indexing this table with <tt>key</tt>. 463 the final result is the result of indexing this metamethod object with <tt>key</tt>.
464 (This indexing is regular, not raw, 464 (This indexing is regular, not raw,
465 and therefore can trigger another metamethod.) 465 and therefore can trigger another metamethod if the metamethod object is a table.)
466 </li> 466 </li>
467 467
468 <li><b>"new_index": </b> 468 <li><p><b>"new_index": </b>
469 The indexing assignment <tt>table[key] = value</tt>. 469 The indexing assignment <tt>table[key] = value</tt>.
470 470
471 Like the index event, 471 Like the index event,
472 this event happens when 472 this event happens when
473 when <tt>key</tt> is not present in <tt>table</tt>. 473 when <tt>key</tt> is not present in <tt>table</tt>.
491 (If necessary, 491 (If necessary,
492 the metamethod itself can call <a href="#Luan.raw_set"><tt>raw_set</tt></a> 492 the metamethod itself can call <a href="#Luan.raw_set"><tt>raw_set</tt></a>
493 to do the assignment.) 493 to do the assignment.)
494 </li> 494 </li>
495 495
496 <li><b>"call": </b> 496 <li><p><b>"call": </b>
497 The call operation <tt>func(args)</tt>. 497 The call operation <tt>func(args)</tt>.
498 498
499 This event happens when Luan tries to call a table. 499 This event happens when Luan tries to call a table.
500 The metamethod is looked up in <tt>func</tt>. 500 The metamethod is looked up in <tt>func</tt>.
501 If present, 501 If present,