ethanwdp Posted July 14, 2015 Share Posted July 14, 2015 I was trying to make my lua interpreter more convenient; instead of it printing the error to the console and the user having to alt tab over to it, it would just print it to the chat log.Problem: xpcall is not a thing. Neither is load(). Pcall does not return an error, it only returns the status of it.How do I catch the error in this case? I tried storing pcall as a function, example local status, luaError = pcall(thefunctionImusing, and then printing luaError. Problem is that it only prints the first line of the error, which is just kahlua defining the Java path of where it is (which, for lua debugging, is kinda useless).So I tried local status, luaError, luaError2 = pcall(thefunctionImusing, and then printing both luaError and luaError2. And still, no luck. Example of code I'm using to execute: elseif string.match(LMSText, "/lua ") then local LMSTextToLua = string.gsub(LMSText, "/lua ", "") local loadLua = loadstring(LMSTextToLua) if pcall(loadLua) then -- loads it as a protected call, to check for errors. -- since there was no errors, everything is fine and this function is over else -- otherwise, ends the function -- good place to have error-printing thingies here. end end(It's a snippet from a huge function, which is why there's an elseif instead of an if and LMSText isn't defined. LMSText was defined much earlier in the function) When I'm just using normal pcall, everything works fine, except I can't check for errors (which is the entire reason why I'm using pcall) Since kahlua seems to be missing xpcall, is there an alternative I can use? Or am I using xpcall wrong? Edit: Example of code I was using that should work, but with the apparent absence of xpcall isn't working: local LMSTextToLua = string.gsub(LMSText, "/lua ", "") local loadLua = loadstring(LMSTextToLua) function errorHandler(luaError) print( "ERROR:"..luaError) end xpcall(loadLua, errorHandler) Link to comment Share on other sites More sharing options...
RoboMat Posted July 14, 2015 Share Posted July 14, 2015 Have you checked if kahlua implements lua's debugger library? Link to comment Share on other sites More sharing options...
ethanwdp Posted July 14, 2015 Author Share Posted July 14, 2015 Have you checked if kahlua implements lua's debugger library?Not quite sure how.I'm having a poke around the Java as I type. I don't know what I can and can't access, I think I can only access functions in the LuaManager (correct me if I'm wrong) Link to comment Share on other sites More sharing options...
EnigmaGrey Posted July 14, 2015 Share Posted July 14, 2015 http://krkadev.blogspot.ca/2010/06/differences-between-kahlua2-and-lua-51.html Link to comment Share on other sites More sharing options...
RoboMat Posted July 14, 2015 Share Posted July 14, 2015 "Kahlua2 does not include any io or debug library. Some parts of the debug library may be added in the future, but the io library is better left added as a custom extension if necessary. The same thing goes for the os library, which is only partially implemented." Looks like you are out of luck here. Link to comment Share on other sites More sharing options...
ethanwdp Posted July 14, 2015 Author Share Posted July 14, 2015 http://krkadev.blogspot.ca/2010/06/differences-between-kahlua2-and-lua-51.html xpcallKahlua2 doesn't implement xpcall yet, but it might come in the future. "Kahlua2 does not include any io or debug library. Some parts of the debug library may be added in the future, but the io library is better left added as a custom extension if necessary. The same thing goes for the os library, which is only partially implemented."Looks like you are out of luck here.That's troubling...I guess I'll have to stick with having to check the console for errors. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now