Skip to content

SrMordred/reloaded

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReloadeD

ReloadeD is a simple library for live code reloading based on dynamic libraries.

ReloadeD is on experimental stage and have been tested only on windows.

Show And Tell

ReloadeD works with a simple Host application, and a Client Library.

//HOST APPLICATION

struct Data
{
    int value;
}

void main()
{
    import reloaded : Reloaded;
    import std.stdio : writeln;

    Reloaded script;
    Data userdata;
    /*
    Load the library, and pass the data that will be shared between HOST and CLIENT.
    */
    script.load("path/lib.dll", userdata );

    /*
    update() will call the method with same name at the client side and will reload the library when it changes automatically(and will call load()/unload() when necessary).
    */

    //In case of client crash, code resumes from here. Optional
    mixin ReloadedCrashReturn;

    while(true)
    {
        script.update();
        //see the data changed by the client here
        writeln(data);
    }
}

The client can be used with 5 functions:

void init(void*) and void uninit(void*)

Will be called on the first lib load and when the host is destroyed(or you change the lib path). It receive the userdata;

void load(void*) and void unload(void*)

Will be called once every time the client changes. It receive the userdata;

void update()

Can be called at will on the host side (normally inside a loop).

ReloadeD will work even if you don´t declare all possible functions.

Note that you don´t need ReloadeD module on the client side so you can reload dynamic libraries from any language :)

mixin ReloadedCrashReturn; (Optional)

This will create a returning point (using setjpm/longjmp) from where the program will resume if the code in the client side crash.

//CLIENT LIBRARY

import core.sys.windows.dll;
import core.stdc.stdio : printf;
mixin SimpleDllMain;

extern(C):

//Same struct declared on Host
struct Data
{
    int x;
    int y;
}

Data* userdata;

void load( void* _userdata )
{
    printf("load\n");
    //capture data coming from Host.
    userdata = cast(Data*) _userdata;
}
void unload(void* userdata){
    printf("unload\n");
}
void init(void* userdata){
    printf("init\n");
}
void uninit(void* userdata){
    printf("uninit\n");
}
void update()
{
    //change value here, recompile and see the changes on the host side :)
    userdata.value = 10;
}

ReloadeD was inspired by cr.h.

License

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:

The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A Simple DLang Live Code Reloading.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages