Mercurial Hosting > luan
changeset 39:e5bcb1eeafc1
change naming convention
git-svn-id: https://luan-java.googlecode.com/svn/trunk@40 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 20 Dec 2012 02:54:06 +0000 |
parents | 30fcb4fb0f76 |
children | e3624b7cd603 |
files | src/luan/lib/BasicLib.java src/luan/tools/CmdLine.java |
diffstat | 2 files changed, 40 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/lib/BasicLib.java Thu Dec 20 02:43:37 2012 +0000 +++ b/src/luan/lib/BasicLib.java Thu Dec 20 02:54:06 2012 +0000 @@ -23,21 +23,24 @@ public static void register(LuaState lua) { LuaTable global = lua.global(); global.put( "_G", global ); - add( global, "getmetatable", LuaState.class, Object.class ); + add( global, "do_file", LuaState.class, String.class ); + add( global, "get_metatable", LuaState.class, Object.class ); add( global, "ipairs", LuaTable.class ); add( global, "load", LuaState.class, String.class ); - add( global, "loadfile", LuaState.class, String.class ); + add( global, "load_file", LuaState.class, String.class ); add( global, "pairs", LuaTable.class ); add( global, "print", LuaState.class, new Object[0].getClass() ); - add( global, "rawequal", Object.class, Object.class ); - add( global, "rawget", LuaTable.class, Object.class ); - add( global, "rawlen", Object.class ); - add( global, "rawset", LuaTable.class, Object.class, Object.class ); - add( global, "setmetatable", LuaTable.class, LuaTable.class ); - add( global, "tonumber", Object.class, Integer.class ); - add( global, "tostring", LuaState.class, Object.class ); + add( global, "raw_equal", Object.class, Object.class ); + add( global, "raw_get", LuaTable.class, Object.class ); + add( global, "raw_len", Object.class ); + add( global, "raw_set", LuaTable.class, Object.class, Object.class ); + add( global, "set_metatable", LuaTable.class, LuaTable.class ); + add( global, "to_number", Object.class, Integer.class ); + add( global, "to_string", LuaState.class, Object.class ); add( global, "type", Object.class ); global.put( "_VERSION", Lua.version ); + + add( global, "make_standard", LuaState.class ); } private static void add(LuaTable t,String method,Class<?>... parameterTypes) { @@ -48,6 +51,20 @@ } } + public static void make_standard(LuaState lua) { + LuaTable global = lua.global(); + global.put( "dofile", global.get("do_file") ); + global.put( "getmetatable", global.get("get_metatable") ); + global.put( "loadfile", global.get("load_file") ); + global.put( "rawequal", global.get("raw_equal") ); + global.put( "rawget", global.get("raw_get") ); + global.put( "rawlen", global.get("raw_len") ); + global.put( "rawset", global.get("raw_set") ); + global.put( "setmetatable", global.get("set_metatable") ); + global.put( "tonumber", global.get("to_number") ); + global.put( "tostring", global.get("to_string") ); + } + public static void print(LuaState lua,Object... args) throws LuaException { for( int i=0; i<args.length; i++ ) { if( i > 0 ) @@ -87,13 +104,13 @@ } - public static LuaFunction loadfile(LuaState lua,String fileName) throws LuaException,IOException { + public static LuaFunction load_file(LuaState lua,String fileName) throws LuaException,IOException { String src = fileName==null ? readAll(new InputStreamReader(System.in)) : read(new File(fileName)); return load(lua,src); } - public static Object[] dofile(LuaState lua,String fileName) throws LuaException,IOException { - return loadfile(lua,fileName).call(lua); + public static Object[] do_file(LuaState lua,String fileName) throws LuaException,IOException { + return load_file(lua,fileName).call(lua); } private static class TableIter { @@ -158,29 +175,29 @@ return new LuaJavaFunction(nextArrayIter,ai); } - public static LuaTable getmetatable(LuaState lua,Object obj) { + public static LuaTable get_metatable(LuaState lua,Object obj) { return lua.getMetatable(obj); } - public static LuaTable setmetatable(LuaTable table,LuaTable metatable) { + public static LuaTable set_metatable(LuaTable table,LuaTable metatable) { table.setMetatable(metatable); return table; } - public static boolean rawequal(Object v1,Object v2) { + public static boolean raw_equal(Object v1,Object v2) { return v1 == v2 || v1 != null && v1.equals(v2); } - public static Object rawget(LuaTable table,Object index) { + public static Object raw_get(LuaTable table,Object index) { return table.get(index); } - public static LuaTable rawset(LuaTable table,Object index,Object value) { + public static LuaTable raw_set(LuaTable table,Object index,Object value) { table.put(index,value); return table; } - public static int rawlen(Object v) throws LuaException { + public static int raw_len(Object v) throws LuaException { if( v instanceof String ) { String s = (String)v; return s.length(); @@ -189,14 +206,14 @@ LuaTable t = (LuaTable)v; return t.length(); } - throw new LuaException( "bad argument #1 to 'rawlen' (table or string expected)" ); + throw new LuaException( "bad argument #1 to 'raw_len' (table or string expected)" ); } - public static LuaNumber tonumber(Object e,Integer base) { + public static LuaNumber to_number(Object e,Integer base) { return Lua.toNumber(e,base); } - public static String tostring(LuaState lua,Object v) throws LuaException { + public static String to_string(LuaState lua,Object v) throws LuaException { return lua.toString(v); } }
--- a/src/luan/tools/CmdLine.java Thu Dec 20 02:43:37 2012 +0000 +++ b/src/luan/tools/CmdLine.java Thu Dec 20 02:54:06 2012 +0000 @@ -47,7 +47,7 @@ } } else if( arg.equals("-") ) { try { - BasicLib.dofile(lua,null); + BasicLib.do_file(lua,null); } catch(LuaException e) { System.err.println(e.getMessage()); System.exit(-1); @@ -71,7 +71,7 @@ } lua.global().put("arg",argsTable); try { - LuaFunction fn = BasicLib.loadfile(lua,file); + LuaFunction fn = BasicLib.load_file(lua,file); fn.call(lua,varArgs); } catch(LuaException e) { // System.err.println(e.getMessage());