-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathXLuaLibInternal.java
More file actions
91 lines (76 loc) · 2.68 KB
/
Copy pathXLuaLibInternal.java
File metadata and controls
91 lines (76 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
import org.luaj.vm2.lib.OneArgFunction;
import org.luaj.vm2.lib.VarArgFunction;
import org.luaj.vm2.lib.ZeroArgFunction;
import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaString;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaThread;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.LoadState;
import org.luaj.vm2.UpValue;
import org.luaj.vm2.Varargs;
/**
*
* @author Justin
*/
public class XLuaLibInternal {
public static class RegCall extends VarArgFunction {
protected String _func = "";
protected int _funcGroup = 0;
protected int _minParams = 0;
RegCall (String func, int funcGroup, int minParams) {
_func = func;
_funcGroup = funcGroup;
_minParams = minParams;
}
public Varargs invoke (Varargs args) {
XLuaState state = XLuaGlobal.Get().GetStateByState(LuaThread.getGlobals());
if (state == null) {
return null;
}
int actualParams = args.narg();
if (actualParams < _minParams) {
error("Function " + _func + " expected " + _minParams + " parameters, got " + actualParams);
return null;
}
return state.stack.CallMMFFunction(_func, _funcGroup, state._G, args);
}
}
public static class ErrorHandler extends OneArgFunction {
public LuaValue call (LuaValue arg) {
XLuaState state = XLuaGlobal.Get().GetStateByState(LuaThread.getGlobals());
if (state == null) {
return NIL;
}
String message = arg.tojstring();
String bt = "";
// Manually raise errors depending on XLua settings
Iterator<XLuaObject> iter = state.rdList.iterator();
while (iter.hasNext()) {
XLuaObject lm = iter.next();
if (lm != null) {
if (lm.useBacktrace) {
// Let's be lazy about backtrace calculations
if (bt.isEmpty()) {
//vm.pushinteger(1);
// db_errorfb();
//bt = vm.tostring(1);
}
lm.raiseError(bt + XLuaState.newline);
} else {
lm.raiseError(message + XLuaState.newline);
}
}
}
return LuaValue.valueOf(message);
}
}
}