Re: Fallbacks in Euphoria
- Posted by dcuny Jan 12, 2015
- 1458 views
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:
- Associate metatable data with a sequence.
- Determine what Euphoria opcodes map to actions.
- Modify the failure behavior to call the metatable fallback if it exists.
- David