Skip to content

Commit

Permalink
Added codegen, code reformatting, deprecated system.d
Browse files Browse the repository at this point in the history
  • Loading branch information
ichordev committed Mar 3, 2023
1 parent bafaec0 commit d13d7f2
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 336 deletions.
6 changes: 5 additions & 1 deletion .gitignore
@@ -1,3 +1,7 @@
lib
dub.selections.json
.dub
.dub
dscanner.ini
*.kate-swp
.directory
.DS_Store
7 changes: 4 additions & 3 deletions dub.sdl
@@ -1,8 +1,9 @@
name "bindbc-loader"
description "Cross-platform shared library loader usable in -betterC mode."
description "Cross-platform shared library loader usable with BetterC."
homepage ""
license "Boost"
authors "Mike Parker"
authors "Aya Partridge" "Mike Parker"

targetType "staticLibrary"
targetPath "lib"
targetName "BindBC_Loader"
Expand All @@ -14,4 +15,4 @@ configuration "noBC" {

configuration "yesBC" {
dflags "-betterC"
}
}
57 changes: 57 additions & 0 deletions source/bindbc/loader/codegen.d
@@ -0,0 +1,57 @@
/+
+ Copyright 2022 – 2023 Aya Partridge
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+/
module bindbc.loader.codegen;

enum LoadMsg{
success,
noLibrary,
badLibrary,
}

enum makeDynloadFns = (string name, string libNames, string[] bindModules) nothrow pure @safe{
string dynloadFns = `
private SharedLib lib;
@nogc nothrow{
void unload`~name~`(){ if(lib != invalidHandle) lib.unload(); }
bool is`~name~`Loaded(){ return lib != invalidHandle; }
LoadMsg load`~name~`(){
enum libNamesCT = `~libNames~`;
const(char)[][libNamesCT.length] libNames = libNamesCT;
LoadMsg ret;
foreach(name; libNames){
ret = load`~name~`(name.ptr);
if(ret == LoadMsg.success) break;
}
return ret;
}
LoadMsg load`~name~`(const(char)* libName){
lib = bindbc.loader.load(libName);
if(lib == invalidHandle){
return LoadMsg.noLibrary;
}
auto errCount = errorCount();
`;

foreach(mod; bindModules){
dynloadFns ~= "\n\t"~mod~".bindModuleSymbols(lib);";
}

dynloadFns ~= `
if(errCount != errorCount()) return LoadMsg.badLibrary;
return LoadMsg.success;
}
}`;

return dynloadFns;
};
20 changes: 11 additions & 9 deletions source/bindbc/loader/package.d
@@ -1,11 +1,13 @@

// Copyright 2018 - 2021 Michael D. Parker
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

/+
+ Copyright 2023 – 2023 Aya Partridge
+ Copyright 2018 - 2021 Michael D. Parker
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+/
module bindbc.loader;

public
import bindbc.loader.sharedlib,
bindbc.loader.system;
public import
bindbc.loader.sharedlib,
bindbc.loader.codegen,
bindbc.loader.system;

0 comments on commit d13d7f2

Please sign in to comment.