Giter Site home page Giter Site logo

nodot-1's Introduction

GDExtension Nim Bindings

This project is a work in progress implementation / proof of concept of the Godot 4 GDExtension API.

Note that this is not yet usable for actual development.

What works:

  • Library initialization / deinitialization hooks

  • Bindings of all builtin classes (Variant, Vector2, ...)

    • Construction, deconstruction
    • Methods
    • Properties
    • Index (keyed and positional)
    • Fixed-arity and variadic calls
  • Bindings of all utility functions

    • Fixed-arity and variadic calls
  • Proper Godot classes:

    • Usage if you get a pointer to one
    • Destruction

What does not work:

  • Builtin and Proper classes:

    • Construction of proper classes
    • Memory management (leaks like a sieve except for trivial cases)
    • Most likely some other things that can not be tested as of yet
  • Registering custom classes

Most of the exciting stuff is now blocked on actually understanding who, and when, is responsible for freeing memory and calling destructors (further complicated by the existence of RefCounted) and properly mapping it to Nim. This might be simple or it might be difficult, unfortunately the only canonical source of documentation is godot-cpp which involves mentally parsing and understanding a lot of macro heavy C++ and that is not fun.

How it works:

Two step auto-generation from the included "contrib/extension_api.json"

nimble generateApi

This is also called automatically in the pre-install step.

This generates the following modules:

  • nodot/api: Very high level definitions.
  • nodot/enums: Global enumerations and bitfields.
  • nodot/utility_functions: Utility functions.
  • nodot/builtins/types/* (except variant): Builtin class type
  • nodot/builtins/* (except variant): Builtin class procs
  • nodot/classes/types/*: Godot Classes
  • nodot/classes/*: Godot Classes

Most methods are stubbed with various Macros that implement the actual glue on end-compile, i.e.

proc lerp*(self: Vector2; to: Vector2; weight: float64): Vector2
  {.gd_builtin_method(Vector2, 4250033116).}

These do the job of caching the various function pointers and converting the arguments and are implemented in the nodot/gdffi module.

Usage Example (Proof of Concept)

# If not specified, entry point defaults to "gdext_init"
godotHooks(GDEXTENSION_INITIALIZATION_SCENE):
  # Called for every initialization level
  initialize(level):
    if level == GDEXTENSION_INITIALIZATION_SCENE:
      echo "Hello World from Godot"

      # Dumping some random information for now
      var os: OS = getSingleton[OS]("OS")

      echo "Processor Name: ", os.get_processor_name()

      let fonts = os.get_system_fonts().newVariant()

      var dir = DirAccess.open("res://".newString())
      var files = dir.get_files().newVariant()

      echo fonts
      echo files

  # Called for every initialization level in reverse order
  deinitialize(level):
    echo "Bye World from Godot!"

nodot-1's People

Contributors

chmod222 avatar

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.