Luny Manual Available

I released the first draft of the Luny Manual. This is for v0.3.

The Manual is a Google Document in which you can leave inline comments. Please make use of this feature to leave questions or feedback.

You can also install Luny v0.3 if you’re wanting to try it out. Refer to the manual as to what’s working and what is currently missing and yet to come. Again, I’d love to hear your feedback!

Early Access, kinda

Since Luny v0.3 is obviously an early version, it’s nevertheless my third or fourth rewrite. I’m not actively going to promote it just yet as I feel there’s still fairly big holes that make it far less valuable than I intend it to be.

But I do feel very confident about the overall architecture and API. Whatever is coming now will mostly build-upon and extend what’s already there, and filling the gaps.

Loading Scripts

One area that I wanted to get right, since there’s just so many ways to load a Lua script:

  • Assets
  • StreamingAssets
  • Resources
  • Addressables / Asset Bundles
  • File Paths ie persistent data path

On top of where there’s also the how:

  • Assign Lua Asset in Inspector
  • Load from (relative/absolute/search) paths
  • Load with dofile/loadfile
  • Respect sandbox file I/O restrictions

I think I have all of these combinations covered.

Hot Reload, baby!

I’m particularly happy about the swiftness of Luny’s Hot Reload. I know these C# Hot Reload Assets are, well, pretty hot among some developers. And I share the same pain. I just never bought into these assets.

Perhaps this was due to trying early versions which were pretty limiting, or just not feeling confident about a publisher’s solution that somehow manages to do a partial domain reload, while Unity couldn’t.

What Luny’s Hot Reload can do is:

  • Confidently Hot Reload Lua scripts in the editor, at runtime, even in builds
  • Hot Reload Lua scripts upon save, no need to focus the Editor or App Window
  • Hot Reload instantly – Lua script load, parse, compile happens within 2-3 frames
  • If there’s a syntax error, the previous script keeps running unaffected

Hot Reload for Luny is built from the ground up and due to the simplistic nature of Lua it’s just going to work reliably 100% at all times for all kinds of changes.

There are some things to watch out for, namely: Values in the context table, and global variables retain their values. While local values will be reset.

You also get two events to handle any cleanup and re-initialization:

function context.OnWillReloadScript()
    – file was modified and is about to be reloaded
    – you may want to perform “cleanup” here
end

function context.OnDidLoadScript()
    – file was loaded either initially or due to hot reload
    – you may want to initialize/reset state here
end

Refer to the Luny Manual section on Hot Reload for details.

Unity Event “Messages”

I’m not sure why Unity chose to call Awake, OnEnable, etc “messages”. To me, these are events, or callbacks.

In any case, in Luny scripts all it takes is to implement a Lua function in the context table and use the established event name and arguments:

local context = …
function context.Awake() 
    print(“Awake me up, before you go-go.”) 
end
function context.OnDestroy()
    print(“I’ll be back!”)
end

See the manual section on MonoBehaviour events.

Editor Scripting

What else is cool? Oh, how about editor scripting. You could do Asset and Build Pipeline automation for instance.

This is an area I still need to extend. Right now, every editor script is a ScriptableSingleton type. The basic events, like those found in MonoBehaviour, are going to work. I do want to add more of the commonly used ones as well, something like these:

function context.playModeStateChanged(state)
    print(“Changed to: “ .. state)
end
function context.OnWillCreateAsset(assetPath)
    print(“Creating Asset: “ .. assetPath)
end

See the manual section on Editor events.

Feedback, Please! 🙂

I could list some more things but I’ll leave it at that for now.

I’d be happy to hear your feedback. Leave a comment in the Luny Manual, or down below, or in the Luny support thread on Unity Discussions.

CodeSmile

CodeSmile

Game Engineer and Code Composer since 1999

Leave a Reply

Your email address will not be published. Required fields are marked *