A script language of preemptive scheduling coroutine in single thread

View the Project on GitHub Water-Melon/Melang


Injection is for Object. It allows us to add many properties and methods in any object.

Human {
someone = $Human;

Now, we have a set Human without any property or method, and an object of Human named someone.

So as a human, someone must has age. Let’s add for it.

someone.age = 20;

OK, done. Now 20 will be printed on terminal.

Let’s add a method for someone.


someone.print = printAge;

printAge is a function not object method, but it can be treated as an object method by injection. In a common function, this is nil. So if call printAge directly, interpreter will throw an error.

There is another way to inject properties and methods.

@mln_set_property(object, name, value);

use mln_set_property to inject property or method into an object. Its return value is the same as argument value.

Let’s add a name in someone.

ret = @mln_set_property(someone, 'name', 'Jason');

The output of this piece of code is:


Let’s add a method in someone to print name.

@mln_set_property(someone, 'showName', printName);

Since there is a function for setting property, there will be a function for getting property.

@mln_get_property(object, name);


@mln_print(@mln_get_property(someone, 'name'));

The output is:


But if you try to access a nonexistent property by this function, interperter will throw an error.