Mercurial Hosting > luan
comparison src/luan/interp/LuaStateImpl.java @ 36:2a35154aec14
implement more basic lib functions
git-svn-id: https://luan-java.googlecode.com/svn/trunk@37 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 18 Dec 2012 09:53:42 +0000 |
parents | 0cdc1da466ee |
children | 8a57ebfdfd78 |
comparison
equal
deleted
inserted
replaced
35:e51906de0f11 | 36:2a35154aec14 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.Lua; | |
3 import luan.LuaState; | 4 import luan.LuaState; |
4 import luan.LuaTable; | 5 import luan.LuaTable; |
5 import luan.LuaFunction; | 6 import luan.LuaFunction; |
7 import luan.LuaException; | |
6 | 8 |
7 | 9 |
8 final class LuaStateImpl implements LuaState { | 10 final class LuaStateImpl implements LuaState { |
9 private final LuaTable global = new LuaTable(); | 11 private final LuaTable global = new LuaTable(); |
10 | 12 |
11 @Override public LuaTable global() { | 13 @Override public LuaTable global() { |
12 return global; | 14 return global; |
13 } | 15 } |
14 | 16 |
17 @Override public String toString(Object obj) throws LuaException { | |
18 LuaFunction fn = Utils.getHandlerFunction("__tostring",obj); | |
19 if( fn != null ) | |
20 return Lua.checkString( Utils.first( fn.call(this,obj) ) ); | |
21 if( obj == null ) | |
22 return "nil"; | |
23 return obj.toString(); | |
24 } | |
15 | 25 |
16 private static class Frame { | 26 private static class Frame { |
17 final Frame previousFrame; | 27 final Frame previousFrame; |
18 final LuaClosure closure; | 28 final LuaClosure closure; |
19 final Object[] stack; | 29 final Object[] stack; |