@@ -12,6 +12,7 @@ public class ExprTranslation {
1212
1313 public static final String TYPE_ID = "__typeId__" ;
1414 public static final String WURST_SUPERTYPES = "__wurst_supertypes" ;
15+ private static final String WURST_ABORT_THREAD_SENTINEL = "__wurst_abort_thread" ;
1516
1617 public static LuaExpr translate (ImAlloc e , LuaTranslator tr ) {
1718 ImClass c = e .getClazz ().getClassDef ();
@@ -51,7 +52,7 @@ public static LuaExpr translate(ImFuncRef e, LuaTranslator tr) {
5152 LuaAst .LuaExprFunctionCall (tr .luaFunc .getFor (e .getFunc ()), LuaAst .LuaExprlist (LuaAst .LuaExprVarAccess (tempDots )))))
5253 ),
5354// LuaAst.LuaLiteral("function(err) " + errorFuncName(tr) + "(tostring(err)) end")
54- LuaAst .LuaLiteral ("function(err) xpcall(function() " + callErrorFunc (tr , "tostring(err)" ) + " end, function(err2) BJDebugMsg(\" error reporting error: \" .. tostring(err2)) BJDebugMsg(\" while reporting: \" .. tostring(err)) end) end" )
55+ LuaAst .LuaLiteral ("function(err) if err == \" " + WURST_ABORT_THREAD_SENTINEL + " \" then return end xpcall(function() " + callErrorFunc (tr , "tostring(err)" ) + " end, function(err2) if err2 == \" " + WURST_ABORT_THREAD_SENTINEL + " \" then return end BJDebugMsg(\" error reporting error: \" .. tostring(err2)) BJDebugMsg(\" while reporting: \" .. tostring(err)) end) end" )
5556 // unfortunately BJDebugMsg(debug.traceback()) is not working
5657 )
5758 ),
@@ -73,6 +74,12 @@ private static String callErrorFunc(LuaTranslator tr, String msg) {
7374
7475 public static LuaExpr translate (ImFunctionCall e , LuaTranslator tr ) {
7576 LuaFunction f = tr .luaFunc .getFor (e .getFunc ());
77+ if ("I2S" .equals (f .getName ()) && isIntentionalThreadAbortCall (e )) {
78+ return LuaAst .LuaExprFunctionCallByName ("error" , LuaAst .LuaExprlist (
79+ LuaAst .LuaExprStringVal (WURST_ABORT_THREAD_SENTINEL ),
80+ LuaAst .LuaExprIntVal ("0" )
81+ ));
82+ }
7683 if (f .getName ().equals (ImTranslator .$DEBUG_PRINT )) {
7784 f .setName ("BJDebugMsg" );
7885 } else if (f .getName ().equals ("I2S" )) {
@@ -81,6 +88,27 @@ public static LuaExpr translate(ImFunctionCall e, LuaTranslator tr) {
8188 return LuaAst .LuaExprFunctionCall (f , tr .translateExprList (e .getArguments ()));
8289 }
8390
91+ private static boolean isIntentionalThreadAbortCall (ImFunctionCall e ) {
92+ if (e .getArguments ().size () != 1 ) {
93+ return false ;
94+ }
95+ ImExpr arg = e .getArguments ().get (0 );
96+ if (!(arg instanceof ImOperatorCall )) {
97+ return false ;
98+ }
99+ ImOperatorCall op = (ImOperatorCall ) arg ;
100+ if (op .getOp () != WurstOperator .DIV_INT ) {
101+ return false ;
102+ }
103+ if (op .getArguments ().size () != 2 ) {
104+ return false ;
105+ }
106+ ImExpr left = op .getArguments ().get (0 );
107+ ImExpr right = op .getArguments ().get (1 );
108+ return (left instanceof ImIntVal && ((ImIntVal ) left ).getValI () == 1 )
109+ && (right instanceof ImIntVal && ((ImIntVal ) right ).getValI () == 0 );
110+ }
111+
84112 public static LuaExpr translate (ImInstanceof e , LuaTranslator tr ) {
85113 return
86114 LuaAst .LuaExprFunctionCall (tr .instanceOfFunction , LuaAst .LuaExprlist (
0 commit comments