Jump to content




[Language] Luva v1.12 - Compiles to Lua


  • You cannot reply to this topic
62 replies to this topic

#61 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 21 March 2016 - 09:41 AM

View PostDetective_Smith, on 20 March 2016 - 02:18 PM, said:

Well, the compiled output is pure Lua, so it is possible to use it in places outside of ComputerCraft, such as for LÖVE.
Also, can you give an example of the custom keyword thing you're thinking about?

EDIT: Also, I've made arithmetic and binary assignment operators a bit more useful:
local x, y, = 10, 20
x, y += 30
// The above is translated into x, y = x + 30, y + 30
// Can be used with any amount of vars, and with things such as *=, >>=, &=, .=, etc
But I need to compile in CC, right?
About custom keywords I meant like adding interfaces, delegates, events etc. Or generics or other things I want through an API

Edited by Konlab, 21 March 2016 - 09:41 AM.


#62 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 21 March 2016 - 10:02 AM

I think that you only need to compile in Lua.

#63 Antelux

  • Members
  • 295 posts
  • LocationSomewhere in the middle of nowhere.

Posted 21 March 2016 - 09:20 PM

The only thing it really uses from CC is the fs and term APIs. But, that's only if you use the Luva.lua file (From github).
Using the other two files, Lexer.lua and Compiler.lua, should be fine in a standard Lua environment as far as I know.

Also:

View PostKonlab, on 21 March 2016 - 09:41 AM, said:

About custom keywords I meant like adding interfaces, delegates, events etc. Or generics or other things I want through an API

I don't really think interfaces are needed, as, if you were to have this C# example (found here):
using System;

public interface IGenerate
{
	int Generate();
}

// Dependencies
public class KnownNumber : IGenerate
{
	public int Generate()
	{
		return 5;
	}  
}

public class SecretNumber : IGenerate
{
	public int Generate()
	{
		return new Random().Next(0, 10);
	}
}

class Game
{
	public Game(IGenerate generator)
	{
		Console.WriteLine(generator.Generate())
	}
}

new Game(new SecretNumber());
new Game(new KnownNumber());

You could just make it become:
local SecretNumber = [Generate: function() { return math.random(0, 10) }]
local KnownNumber = [Generate: function() { return 5 }]

local class Game(generator: table) {
	 private function init {
		  guard type(generator.Generate) == "function" else { error("Table must have a Generate function!") }
		  print(generator.Generate())
	 }
}

Game(SecretNumber)
Game(KnownNumber)

Events (or Delegates):
local class Event {
	 private:
		  subscribers = []
		  subs = 0

	 public static:
		  function add(f: function) {
			   subs++; subscribers[subs] = f; return subs
		  }

		  function rem(n: number) {
			   if n == subs { subs-- }; subscribers[n] = nil
		  }

		  function clr {
			   for i = 1, subs { subscribers[i] = nil }; subs = 0
		  }

	 public static metamethod:
		  function add = self.add
		  function sub = self.sub
		  function call(...) {
			   for i = 1, subs { subscribers[i](...) }
		  }
}

I also feel as if Generics aren't really needed either, since type specification is optional in Luva.
Feel free to call me out if my examples or something I said here is wrong or something, since I don't really use interfaces, delegates, etc.

Edited by Detective_Smith, 21 March 2016 - 09:33 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users