Skip to content

jkingstonc/pluto-lang-3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation


What is Pluto3D?

Pluto3D is an interpreted language for use inside of Unity3D. Have you ever wanted your own programming language inside of your computer game? Pluto3D was built just for that!


Simplicity

Pluto was developed to be simple to use, all you have to do to run your code is create a new instance of a pluto runtime and give it your code as a string!

    PlutoRuntime runtime = new PlutoRuntime();
        runtime.compile(program);

Customization

Pluto supports native code extensions, this allows you to make Pluto do anything you want inside of Unity. Say you want Pluto to create a game object when the user calls a custom function, Pluto can do it!


Safety

Using Pluto is the safest way of allowing access to a scripting langauge in game, typically runtime C# methods always expose the underlying structure of the engine, causing a serious vunerability issue. Pluto only exposes the structure that you want to expose.


Usage

This outlines the basics of using Pluto3D inside of Unity

PlutoRuntime

First create a PlutoRuntime in a script in your project

PlutoRuntime runtime = new PlutoRuntime();

Write your code!

Then write your code! This could be on a canvas, inside C#, from a file... anywhere! Example...

import "unity.Debug"
debug::print("Hello Unity Console!")
# This code prints "Hello Unity Console" to the Console... duh

Compile

Simply compile the code!

runtime.compile( your code here! );

Native extensions... The most important Part

To make the interpreter actually do something you want, like instantiate a cube, you need to create a native extension. To do so, add a new script to a gameobject in game, that extends UnityCallable. Then ensure you provide a setup() override and a Callable class instance. An example to insantiate a prefab is below, this is called whenever the user calls the function spawn_block() in Pluto3D code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestCallable : UnityCallable
{
    public GameObject myPrefab;

    public override void setup()
    {
	this.name = "spawn_block";
	this.callable = new TestFunc(myPrefab);
    }

    private class TestFunc : Callable
    {
	GameObject myPrefab;

	public TestFunc(GameObject myPrefab)
	{
	    this.myPrefab = myPrefab;
	}
	public int args()
	{
	    return 1;
	}
	public object call(Interpreter interpreter, List<object> args)
	{
	    Instantiate(this.myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
	    return null;
	}
    }
}

This new native function is now automatically loaded into any runtime you create! (Remember to attach this class to a gameobject in game)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages