Git Product home page Git Product logo

dsmoke's Introduction

DSMOKE

This is a library for using SMOKE from D. This offers functionality for reading and interacting with SMOKE libraries for executing C++ code through D and for generating D libraries from generated SMOKE libraries.

Quick Start

Check out the code somewhere, with the dstruct code in the same parent directory if you don't have it and use DUB to build the library.

dub build

That's it. This library itself doesn't actually depend on SMOKE or any SMOKE libraries itself. Libraries which link DSMOKE will have to link the relevant SMOKE libraries they wish to use however, and likely the C++ standard library also.

A Direct D Interface to SMOKE

This library contains a module smoke.smoke, which provides an interface to the SMOKE data as it is specified in C++. The C++ data structure is actually a class composed entirely of C-compatible data types, and can thus be used entirely from D by matching the layout of the data, which this module provides as the type Smoke.

The module also provides an extern(C++) interface to a SmokeBinding class, which is needed for handling virtual method calls and deletions in D SMOKE wrapper libraries.

Some Library Declarations Out of the Box

DSMOKE is pretty useless if there aren't any SMOKE libraries out there. DSMOKE provides some function declarations for you out of the box so you can get started quickly. At the moment this is limited to just the module smoke.smokeqt, but there will be more to come.

A Convenient, Less Confusing Data Structure

In addition to the direct access to SMOKE data, this library also provides a data structure which can be used to get information about a SMOKE library in the module smoke.smoke_container named SmokeContainer. This data structure is created by copying data out of the SMOKE library through the Smoke structures into a more convenient and easier to reason about form.

For example, you can get everything you need to know about QtCore and QtGUI like so.

// Link this file with smokebase, smokeqtcore, smokeqtgui, etc.

// Import the Smoke data structure
import smoke.smoke;
// Import declarations for smokeqt library functions.
import smoke.smokeqt;
// Import the container data structure.
import smoke.smoke_container;

immutable(SmokeContainer) loadQtSmokeContainer() {
    // Call the smokeqtcore library function to 'new' the Smoke data.
    init_qtcore_Smoke();
    // We can 'delete' it on scope exit, we copy everything we need safely.
    scope(exit) delete_qtcore_Smoke();
    // We want QtGUI stuff too.
    init_qtgui_Smoke();
    scope(exit) delete_qtgui_Smoke();

    // Create the immutable data structure using these two libraries.
    return SmokeContainer.create(qtcore_Smoke, qtgui_Smoke);
}

void main() {
    import std.stdio;

    // Now we've got everything we need to learn about the library,
    // to generate source files with, etc.
    auto container = loadQtSmokeContainer();

    // Let's write the name of every top level class in the libraries!
    foreach(cls; container.topLevelClassList) {
        writeln(cls.name);
    }
}

A Reference D Code Generator, Too

The primary interest for using a library such as this is to make it possible to generate D bindings to a C++ library. DSMOKE provides a SmokeGenerator object which can be used for this purpose in the module smoke.smoke_generator, which interacts with the SmokeContainer object and lets you insert some configuration options and delegates for tweaking the output.

// Import this too so we can generate code.
import smoke.smoke_generator;

/* ... Write everything for creating a SmokeContainer as before ... */

void main() {
    // Get our data we used in the previous example.
    auto container = loadQtSmokeContainer();

    // Create the generator.
    // WARNING: API subject to change to eventually use the Builder pattern.
    auto generator = SmokeGenerator();

    /* ... Insert configuration options needed, and some WILL be needed ... */

    // Set a module name, which is required.
    generator.moduleName = "dqt";
    // Set the directory for pulling pre-defined files from, some are needed,
    // in particular for defining a SmokeLoader.
    generator.sourceDirectory = "dqt_predefined";

    // Write the output to a given directory.
    generator.writeToDirectory(container, "dqt");
}

Omitting some important details which will differ between different libraries. the above example should be a good starting point for using the SmokeGenerator to build your own D library.

Try It Out, Comment, Contribute, destroy()

Probably missing a few things, that's about it. This library is available for free under a two-clause BSD licence. so feel free to play with it, fork it, submit pull requests for it, print out the source and shout at it, whatever you want.

dsmoke's People

Contributors

w0rp avatar

Watchers

 avatar  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.