Luny Tanks – The Code Is Lua! :)

I ported Unity Learn’s Tanks! project to Luny. It’s a major milestone for Luny – the Lua solution for Unity.

The Code Is Lua, Literally!

You read that right: Lua, not lava!

The demo runs Lua code!😀

In the browser!!😃

At a whopping 200+ fps!!!😄

Play the web demo! You can also try the Windows x64 build (IL2CPP) if you trust my authoritah. Both are development builds.

Runtime Script Editor

Just for demonstration purposes, I added a runtime script editor that enables you to edit the FireShell function at runtime:

I provided a template that you can quickly comment in some lines to create a multi-shot!

Note: You can Ctrl+A to select all text, then use Ctrl+C/Ctrl+V to copy/paste it to and from a text editor of your choice. If you create a compile error, it’ll show up at the bottom. If there’s a runtime error, it’ll pop up the ingame error console while playing.

Compiling A Lua String

This is the code that compiles the user’s TMP_InputField script – the above FireShell() script:

	public Boolean CompileUserScript(String script)
	{
		var success = false;

		try
		{
			Luny.Singleton.Lua.DoString(script, "FireShell.lua");
			success = true;
		}
		catch (Exception e)
		{
			m_ErrorText.text = e.Message;
		}

		return success;
	}

Never mind the Singleton. I’ll make it so that you can have multiple Lua states.

The Lua Scripts

Here are the (most important) Lua scripts that make the game tick .. or ‘track’. Original C# comments and logic flow left mostly intact:

IDE Support for Lua

For most IDEs there’s at least one plugin that enables Lua support with syntax highlighting, autocompletion, error checking and more.

See the following list, ordered by how well each IDE works with and understands Unity:

  1. Lua extensions for Rider
  2. ..
  3. ..
  4. ….
  5. ..
  6. Lua extensions for Visual Studio
  7. Lua extensions for Visual Studio Code

I currently use SumnekoLua but haven’t tried others yet.

Next Step

I will create automated bindings of the Unity API so you can experience programming Unity in Lua in full!

This will likely take me another month or two. Maybe more. But then it’s going to be ready for release!

Join my Patreon to not miss out!

CodeSmile

CodeSmile

Game Engineer and Code Composer since 1999

Leave a Reply

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