Coder Social home page Coder Social logo

Comments (5)

pangweiwei avatar pangweiwei commented on July 30, 2024

All codes that access lua state should move to LoadLuaComplete callback, can not call member of luaState following init.

from slua.

pangweiwei avatar pangweiwei commented on July 30, 2024

code like this will work fine:

Lua.init(null,()=>{
Lua.luaState.doString("someUncaughtException()", "chunkName");
}
,false);

from slua.

paiboonpa avatar paiboonpa commented on July 30, 2024

@pangweiwei

Sorry for the wrong example. I think I should attached the whole project here:

http://levelup.in.th/TestLua.zip

It's not that the code is working before lua init is completed. Please extract the project and open the scene Main in your example. I modified Main.cs and main.txt to test this out. Now, foo function looked like this:

function foo(a,b,c)
print(h.j)
return a,b,c,"slua"
end

This will force an exception. Next, I edited errorReport() in LuaState.cs and comment out Debug.LogError(LuaDLL.lua_tostring(L, -1))

With this, there will be nothing left to report an error. I'm also not sure if I should hack the code to throw an exception instead of Debug.LogError or not because it may break the code.

If you asked me why I do not use Application.logMessageReceived to receive an error from Debug.LogError, it's because I want to handle the exception separate from other Debug.LogError in the application. For example, I want to show an error to user when lua do something wrong with different error message from other error. That's why I want try catch to be able to catch exception to work on my own error handling.

from slua.

pangweiwei avatar pangweiwei commented on July 30, 2024

I think you could modify doBuffer function like:

public bool doBuffer(byte[] bytes, string fn, out object ret)
{
ret = null;
int errfunc = LuaObject.pushTry(L);
if (LuaDLL.luaL_loadbuffer(L, bytes, bytes.Length, fn) == 0)
{
if (LuaDLL.lua_pcall(L, 0, LuaDLL.LUA_MULTRET, errfunc) != 0)
{
goto err;
}
LuaDLL.lua_remove(L, errfunc); // pop error function
ret = topObjects(errfunc - 1);
return true;
}
err:
string err = LuaDLL.lua_tostring(L, -1);
LuaDLL.lua_pop(L, 2);
throw new Exception(err);
}

from slua.

paiboonpa avatar paiboonpa commented on July 30, 2024

It threw an Exception now but it's empty string in
string err = LuaDLL.lua_tostring(L, -1);

However, I can use it with old Debug.LogError in errorReport(). Thank you very much!

from slua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.