Code Monkey home page Code Monkey logo

flecs-luajit's Introduction

flecs-luajit

Introduction

A LuaJIT script host for the flecs entity component system. Keep in mind that the project is under development and the API might change unexpectedly.

Example

First the flecs module has to be imported and initialised

#include <flecs-luajit/module_base.h>
#include <flecs.h>

int main(void) {
    ecs_world_t* world = ecs_init();

    ECS_IMPORT(world, FlecsLuajitBase);
    ecs_luajit_init(world);

    ecs_luajit_run(world, &(ecs_luajit_run_desc_t) {
        .script = { .name = "example.lua" },
    });

    ecs_progress(world, 0.0f);
    return ecs_fini(world);
}

An example.lua script that imitates the example in the flecs readme

local flecs = require 'flecs'
local world = flecs.world

local ffi = require 'ffi'
ffi.cdef('typedef struct { ecs_f32_t x, y; } Position, Velocity;')

local Position = world:component {
    entity = world:entity { name = 'Position', symbol = 'Position' },
}

local Velocity = world:component {
    entity = world:entity { name = 'Velocity', symbol = 'Velocity' },
}

local e = world:entity { name = 'Bob' }
world:set(e, Position, { x = 10, y = 20 })
world:set(e, Velocity, { x = 1, y = 2 })

function Move(iter)
    for _, p, v in iter:each() do
        p.x = p.x + v.x
        p.y = p.y + v.y
    end
end

world:system {
    entity = world:entity {
        name = 'Move',
        add = { flecs.pair(flecs.g.DependsOn, flecs.g.OnUpdate) },
    },
    query = { filter = { expr = "Position, [in] Velocity" } },
    callback = 'Move',
}

Note that to make this example work with a multithreaded ecs_world_t one has to make some modifications to the Lua script. A more elaborate example can be found in the example directory.

Compatibility

The following table shows the compatibility of different versions of flecs-luajit with those of flecs

flecs-luajit flecs
master v3.1.3
v0.1.0 v3.1.3

Building

For now only linux is supported but windows support will come shortly. The project can be built using the meson build system. E.g.

meson build
meson compile -C build

To run the example application

./build/example/example

flecs-luajit's People

Contributors

sro5h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

dseeni adevald

flecs-luajit's Issues

meson cant find luajit even though its installed

error meson is giving

Found CMake: /usr/bin/cmake (3.28.3)
Run-time dependency luajit found: NO (tried pkgconfig and cmake)

meson.build:52:8: ERROR: Dependency "luajit" not found, tried pkgconfig and cmake

luajit is also installed to /usr/bin/luajit, but meson cant find it, even though it found cmake in the same location

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.