Re: Fallbacks in Euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message
Ekhnat0n said...

Please David,
Explain me in simple words what fallbacks are...

In Lua, the core datatype is a table - a dictionary of key/value pairs.

A metatable in Lua is a regular table with the addition of key/value pairs. These values are ordinarily not accessible, except with the special methods setmetatable( table, function ) and getmetatable( table ).

When Lua performs an operation on a table that then fails, it checks to see if there is an overloaded function in the metatable. If there is, the operation is performed using function in the metatable.

Here are the keys that Lua supports. Be aware that not all of these map to operations in Euphoria, and there are operations that Euphoria supports that don't have equivalents in Lua:

  • __index
  • __newindex
  • __mode
  • __call
  • __metatable
  • __tostring
  • __gc
  • __unm
  • __add
  • __sub
  • __mul
  • __div
  • __pow
  • __concat
  • __eq

Additionally, there are "raw" routines for accessing Lua tables without triggering the fallback behavior.

For more details, Google is your friend.

Mapping this to Euphoria requires a number of low-level modifications, including:

  1. Associate metatable data with a sequence.
  2. Determine what Euphoria opcodes map to actions.
  3. Modify the failure behavior to call the metatable fallback if it exists.

- David

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu