Git Product home page Git Product logo

Morfuse

Introduction

Morfuse is a scripting engine library: it has its own script language. It is a script engine inspired from Ritual’s ÜberTools for Quake III and Medal of Honor: Allied Assault (it can parse scripts from the last one). This script engine targets games primarily.

Building

Requirements

Windows

Linux

  • Flex and Bison

  • CMake (at least 3.13)

  • A compiler that supports C++17 and has no issue with the standard (clang-12 is the most liked)

Configure and compile

Windows

  • Download the latest version of Winflexbison from here: https://github.com/lexxmark/winflexbison/releases and extract it somewhere

  • (Checkout morfuse and) create a cmake directory inside the project’s directory (can be named anything) and cd into it

  • Configure with CMake, assuming that you have a compiler installed/present in %PATH%:

cmake -DFLEX_EXECUTABLE="<path to winflexbison>\win_flex.exe" -DBISON_EXECUTABLE="<path to winflexbison>\win_bison.exe" -DFLEX_INCLUDE_DIR="<path to winflexbison>\flex_bison\" -DCMAKE_BUILD_TYPE=Release ..\
  • Build & install:

cmake --build . --config Release
cmake --install . --config Release

Linux (Ubuntu)

  • Install required tools (CMake, clang-12, ninja-build, flex, bison and libfl-dev for Flex):

apt install -y cmake make clang-12 lld-12 ninja-build flex bison libfl-dev
  • (Checkout morfuse and) create a cmake directory inside the project’s directory (can be named anything) and cd into it

  • Configure with CMake:

cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..\
  • Build and install:

ninja
cmake --install . --config Release

Using the library externally

Since it’s CMake and cross-platform, you can use it with your CMake project! Just define morfuse_DIR to the path of the installed library and call find_package(morfuse). The include directory will be set in morfuse_INCLUDE_DIR

Example code

#include <morfuse/Script/Context.h>
#include <morfuse/Common/membuf.h>

#include <iostream>

const char sampleScript[] =
"main:\n"
"local.string = \"Hello, world!\"\n"
"println local.string\n"
"end";

int main()
{
	// This example only cover the execution of script

	mfuse::ScriptContext context;
	// Set the stream to use for 'Output'.
	// The script above will call println which will use the 'Output' level
	context.GetOutputInfo().SetOutputStream(mfuse::outputLevel_e::Output, &std::cout);

	mfuse::ScriptMaster& director = context.GetDirector();

	// Instantiate a memory buffer stream (implementation of std::istream)
	// It will be used to read and parse the script from a memory buffer.
	mfuse::imemstream membuf(sampleScript, sizeof(sampleScript));

	// This will parse and compile the script into a program buffer (opcodes) that the interpreter will execute
	// The parser will read the script using the buffer above
	const mfuse::ProgramScript* const script = director.GetProgramScript("example", membuf);

	// This will create a thread that will execute the ProgramScript instance above
	// labels define the position at which threads will start
	// If no label is specified (second parameter), the thread starts at position 0 by default
	//
	// If the thread has finished executing, then this method will return null, otherwise, in the case of a wait, it will return an object of the thread
	director.ExecuteThread(script);

	// Output:
	// Hello, world!
	//

	return 0;
}

There is no real documentation yet but it would be nice to have one. Feel free to contribute if you’re interested in this script engine!

General features

Those are obvious but still worth mentioning:

  • Cross-platform (Linux, Windows, x86, x64, ARM, PowerPC, etc…​)

  • Ability to create classes and methods to be used by scripts

  • Pausable/Resumable threads

  • Dynamic variables

  • Script can be executed with parameters through C code, C code can easily retrieve return values from thread

  • Target list, something like $entity_name.some_var = 1

morfuse's Projects

morfuse icon morfuse

Morfuse script system is an experimental cross-platform game script engine.

sexec icon sexec

Execute morfuse scripts using command-line

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.