lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


After the discussion about unified methods, I have copied just the
method table code from the LuaState distribution and put it in a clean
Lua 4.1 Work Beta implementation.

Credit for the method tables implementation goes to Edgar Toernig, who
created the method tables for Sol.  Except for the parser changes and
new VM opcodes, this is 100% Edgar's work.

Documentation can be found in the "Unified Methods" and "Standard
Unified Method Callbacks" sections of
http://www.workspacewhiz.com/Other/LuaState/LuaState.html with the
following differences:

* The LuaState :: operator is now a .> operator, so it more closely
mirrors the regular . table indexing operator.
* The LuaState -> operator is now a :> operator, so it more closely
mirrors the regular : function calling operator.
* Due to parser changes in Lua 4.1 Work Beta (as opposed to Lua 4.1
Alpha), it is no longer possible to:

print(4:>sqrt())

The modified directories can be found here.  Just do a diff of the
original Lua 4.1 Work Beta code and this code to see the small number of
differences.

http://workspacewhiz.com/Other/LuaState/Lua41BetaWorkMethodTables.zip

Changes:
===============================

lauxlib.*:

* Added luaL_openlibintotable() helper function (Sol).

lua.h:

* Added LUA_NTYPES #define. (Sol)
* Added lua_getmethods(). (Sol)
* Added lua_getdefaultmethods(). (Sol)
* Added lua_setmethods(). (Sol)

lapi.c:

* Implements lua_getmethods(). (Sol)
* Implements lua_getdefaultmethods(). (Sol)
* Implements lua_setmethods(). (Sol)

lcode.*:

* Added a case for the new VINDEXEDMETHOD type in luaK_dischargevars().
* Added function luaK_selfmethod().
* Added function luaK_indexedmethod().

ldebug.c:

* Added functions travtable() and travmethods().  (Sol)
* In function getname(), a travmethods() call has been added.  (Sol)

lgc.c:

* Function marktable() has been upgraded to check the methods table.
(Sol)
* markobject() has been upgraded to wander user data's methods.  (Sol)
* checkMbuffer() has been fixed to compile under VC6.

lbaselib.c:

* Added function luaB_methods().  (Sol)
* Default method tables are created.  (Sol)

liolib.c:

* File method table created.  (Sol)

lmathlib.c:

* Number method table created.  (Sol)

lstrlib.c:

* String method table created.  (Sol)

llex.*:

* In luaX_lex(), the cases for a . (period) and : (colon) have been
upgraded
  to check for > (greater than) symbols following.

lobject.h:

* The struct Udata has a Table* methods member added.  (Sol)
* The struct Table has a Table* methods member added.  (Sol)

lopcodes.*:

* Upgraded to handle the new opcodes OP_GETMETHOD and OP_SELFMETHOD.

lparser.c:

* Function luaY_methodsfield() added.
* In primaryexp(), cases for TK_COLONGT and TK_PERIODGT have been added.

lparser.h:

* VINDEXEDMETHOD enum added to expkind.

lstate.c:

* In function f_luaopen(), method tables are built into the global
state.  (Sol)

lstate.h:

* struct global_State has Table* methods[LUA_NTYPES] array added.  (Sol)

lstring.c:

* luaS_newudata() assigns the default userdata method table.  (Sol)

ltable.c:

* luaH_new() assigns the default table method table.  (Sol)
* In function newkey(), settableval() was fixed to compile under VC6.

ltm.*:

* Functions luaT_getmethods() and luaT_setmethods() added.  (Sol)

lvm.c:

* Function luaV_getmethod() added.
* Virtual machine opcodes OP_GETMETHOD and OP_SELFMETHOD implemented.

-Josh