| 976 | } |
| 977 | |
| 978 | LuaDetail::LuaFunctionReturn LuaEngine::contextEval(int handleIndex, String const& lua) { |
| 979 | int stackSize = lua_gettop(m_state); |
| 980 | lua_checkstack(m_state, 2); |
| 981 | |
| 982 | // First, try interpreting the lua as an expression by adding "return", then |
| 983 | // as a statement. This is the same thing the actual lua repl does. |
| 984 | int loadRes = luaL_loadstring(m_state, ("return " + lua).utf8Ptr()); |
| 985 | if (loadRes == LUA_ERRSYNTAX) { |
| 986 | lua_pop(m_state, 1); |
| 987 | loadRes = luaL_loadstring(m_state, lua.utf8Ptr()); |
| 988 | } |
| 989 | handleError(m_state, loadRes); |
| 990 | |
| 991 | pushHandle(m_state, handleIndex); |
| 992 | lua_setupvalue(m_state, -2, 1); |
| 993 | |
| 994 | incrementRecursionLevel(); |
| 995 | int callRes = pcallWithTraceback(m_state, 0, LUA_MULTRET); |
| 996 | decrementRecursionLevel(); |
| 997 | handleError(m_state, callRes); |
| 998 | |
| 999 | int returnValues = lua_gettop(m_state) - stackSize; |
| 1000 | if (returnValues == 0) { |
| 1001 | return LuaDetail::LuaFunctionReturn(); |
| 1002 | } else if (returnValues == 1) { |
| 1003 | return LuaDetail::LuaFunctionReturn(popLuaValue(m_state)); |
| 1004 | } else { |
| 1005 | LuaVariadic<LuaValue> ret(returnValues); |
| 1006 | for (int i = returnValues - 1; i >= 0; --i) |
| 1007 | ret[i] = popLuaValue(m_state); |
| 1008 | return LuaDetail::LuaFunctionReturn(ret); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | LuaValue LuaEngine::contextGetPath(int handleIndex, String path) { |
| 1013 | lua_checkstack(m_state, 2); |
no test coverage detected