Mercurial Hosting > luan
view src/luan/interp/Utils.java @ 35:e51906de0f11
implement metatables
git-svn-id: https://luan-java.googlecode.com/svn/trunk@36 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 18 Dec 2012 07:05:58 +0000 |
parents | |
children | 2a35154aec14 |
line wrap: on
line source
package luan.interp; import luan.Lua; import luan.LuaFunction; import luan.LuaTable; import luan.LuaException; final class Utils { private Utils() {} // never static Object first(Object[] a) { return a.length==0 ? null : a[0]; } static final Object getHandlerObject(String op,Object obj) throws LuaException { LuaTable t = Lua.getMetatable(obj); return t==null ? null : t.get(op); } static final LuaFunction getHandler(String op,Object obj) throws LuaException { Object f = getHandlerObject(op,obj); if( f == null ) return null; return Lua.checkFunction(f); } }