Skip to content
/ Mana Public

A scripting language for game AI and gameplay logic, built around the Actor Model. Each character is defined as an actor with explicit actions and message-based interactions, making complex behavior easy to design, reason about, and extend.

License

Notifications You must be signed in to change notification settings

shun126/Mana

Repository files navigation

Actor-oriented scripting language Mana

Issues, Discussions, Wiki, DeepWiki, Doxygen

This scripting language was developed with the aim of developing a character's action using actor model. You can implement the execution engine easily into your computer game program.

What Mana code looks like

actor Mother
{
    int mFlag;
    action initialize
    {
        mFlag = 0;
    }
    action main
    {
        print("Hi");
        request(1, Child->talk);
    }
}

actor Child
{
    action update
    {
        int i;
    }
    action talk
    {
        print("Hi");
    }
}

Namespaces and action references

Use namespace blocks to group actors, and using to import namespace paths or actor symbols. Action references use ->, while :: is reserved for namespace qualification.

namespace Game::AI
{
    actor Enemy
    {
        action think
        {
        }
    }
}

using Game::AI;

actor Controller
{
    action main
    {
        request(1, Enemy->think);
    }
}

Installing

Requirements

Any Linux Distribution

  • cd to <download_path>\compiler
  • make

Building with Cygwin

Building with MSVC

  • Set the path to bison in the environment variable GNU_BISON_BIN, and the path to flex in GNU_FLEX_BIN.
  • Install Microsoft Visual C++ 2022 Community (should work with other versions).
  • Run "Vistual Studio 2022 Command Prompt" from the "Visual Studio 2022" start menu.
  • Open mana.sln

Running Sample

mana sample/sample.mn

How to Use

When you specify the source file at runtime, it will compile and execute it.

mana source_file

If you specify the -o option, it will output the compiled binary file.

mana source_file -o binary_file

If you specify the --execute option, it will execute the binary file.

mana --execute binary_file
mana -e binary_file

How to Embed the Virtual Machine

  1. Copy the runner directory to your preferred location in your project.
  2. Add #include "runner/Mana.h" to your code.
  3. Create the VM class and load the program.
  4. Tick the VM.
auto vm = std::make_shared<mana::VM>();
vm->LoadPlugins(".");
vm->LoadProgram(path);
// Tick
while (vm->Run())
    ;

Binding native code

Register C-style callbacks or bind methods on existing C++ objects to the same native entry points in Mana scripts.

// Plain function binding
vm->RegisterFunction("nativeFunction", &NativeFunction);

// Bind a member function that matches mana::VM::ExternalFunctionType
auto instance = std::make_shared<MyPlugin>();
vm->RegisterMemberFunction("pluginCallback", instance, &MyPlugin::OnCall);

License

MIT License

👀 See also

Author

ko-fi

About

A scripting language for game AI and gameplay logic, built around the Actor Model. Each character is defined as an actor with explicit actions and message-based interactions, making complex behavior easy to design, reason about, and extend.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project