Patch 2

  • Moved coroutine scheduler to C#
  • Added support for async C# functions being called (and yielded) from Lua coroutines
  • Added variable arg support for print and spawn helper funcs
  • Massive cleanup pass

Coroutines were being handled in a strange way mostly being managed by Lua code, which was causing some features to be difficult (namely async C# functions being called/yielded from Lua). Lua's C API doesn't allow you to mix and match whether C code or Lua is resuming and yielding coroutines, so it's either all Lua managed or all C# managed - bLua is now all C# managed!

With the change to our management of coroutines, I was able to add support for async C# functions being called (and yielded) from Lua. Example of C# and Lua code working together seamlessly:

static Task<string> WaitDuration(float duration)
{
    Task.Delay(1000); // 1000ms = 1s
    return "Hello world!";
}

function testCoroutine(duration)
    local str = WaitDuration(duration)
    print(str) // After 1 second, will print "Hello world!"
end
local co = coroutine.create(testCoroutine)
coroutine.resume(co)

Added variable args support for print and spawn, previously they were capped at 8 parameters.

A massive cleanup pass also took place, which mostly consolidated similar code, removed unused code, and renamed commonly used developer-facing functions to better match the API of similar plugins and Unity standards. Some notable ones:

  • (bLuaInstance) .ExecBuffer(...) -> .LoadString(...)
  • (bLuaValue) .CastToBool(...)/.Bool -> .ToBool() (this goes for similarly named functions too)
  • (Lua) spawn(...)/wait(...) -> thread.spawn(...)/thread.wait(...)

All of these changes were merged into the main repository in commit d5f206c37203261b9dcb716f75cad7f0697db31a