Mercurial Hosting > luan
diff src/luan/modules/Utils.java @ 1420:225808b90cee
options handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 26 Oct 2019 22:21:09 -0600 |
parents | 002152af497a |
children | 471ef3e6a84e |
line wrap: on
line diff
--- a/src/luan/modules/Utils.java Fri Oct 25 22:12:06 2019 -0600 +++ b/src/luan/modules/Utils.java Sat Oct 26 22:21:09 2019 -0600 @@ -97,29 +97,29 @@ } - public static String removeString(Map map,String key) throws LuanException { - Object val = map.remove(key); + public static String removeString(LuanTable options,String key) throws LuanException { + Object val = options.remove(key); if( val!=null && !(val instanceof String) ) throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); return (String)val; } - public static String removeRequiredString(Map map,String key) throws LuanException { - String s = removeString(map,key); + public static String removeRequiredString(LuanTable options,String key) throws LuanException { + String s = removeString(options,key); if( s==null ) throw new LuanException( "parameter '"+key+"' is required" ); return s; } - public static Number removeNumber(Map map,String key) throws LuanException { - Object val = map.remove(key); + public static Number removeNumber(LuanTable options,String key) throws LuanException { + Object val = options.remove(key); if( val!=null && !(val instanceof Number) ) throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); return (Number)val; } - public static Integer removeInteger(Map map,String key) throws LuanException { - Object val = map.remove(key); + public static Integer removeInteger(LuanTable options,String key) throws LuanException { + Object val = options.remove(key); if( val==null ) return null; Integer i = Luan.asInteger(val); @@ -130,37 +130,37 @@ return i; } - public static LuanTable removeTable(Map map,String key) throws LuanException { - Object val = map.remove(key); + public static LuanTable removeTable(LuanTable options,String key) throws LuanException { + Object val = options.remove(key); if( val!=null && !(val instanceof LuanTable) ) throw new LuanException( "parameter '"+key+"' must be a table but is a "+Luan.type(val) ); return (LuanTable)val; } - public static Boolean removeBoolean(Map map,String key) throws LuanException { - Object val = map.remove(key); + public static Boolean removeBoolean(LuanTable options,String key) throws LuanException { + Object val = options.remove(key); if( val!=null && !(val instanceof Boolean) ) throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); return (Boolean)val; } - public static LuanFunction removeFunction(Map map,String key) throws LuanException { - Object val = map.remove(key); + public static LuanFunction removeFunction(LuanTable options,String key) throws LuanException { + Object val = options.remove(key); if( val!=null && !(val instanceof LuanFunction) ) throw new LuanException( "parameter '"+key+"' must be a function but is a "+Luan.type(val) ); return (LuanFunction)val; } - public static LuanFunction removeRequiredFunction(Map map,String key) throws LuanException { - LuanFunction fn = removeFunction(map,key); + public static LuanFunction removeRequiredFunction(LuanTable options,String key) throws LuanException { + LuanFunction fn = removeFunction(options,key); if( fn==null ) throw new LuanException( "parameter '"+key+"' is required" ); return fn; } - public static void checkEmpty(Map map) throws LuanException { - if( !map.isEmpty() ) - throw new LuanException( "unrecognized options: "+map ); + public static void checkEmpty(LuanTable options) throws LuanException { + if( !options.isEmpty() ) + throw new LuanException( "unrecognized options: "+options.asMap() ); } }