Re: derelict-sdl2 automatically stripping the SDL_ prefix from names

2018-11-28 Thread unDEFER via Digitalmars-d-learn
Hello, as I know allMembers returns members not recursively. If 
you want to get really all members you need to make recursive 
function. In my program I used the next routine to print all 
members of module:

static void allMembersOfModule(string module_name, bool 

static if (module_name != "object" &&
module_name != __MODULE__)
mixin("import "~module_name~";");

pragma(msg, module_name~":");

foreach(member; __traits(allMembers, mixin(module_name)))
static if (__traits(compiles, mixin(member)) &&
(!__traits(compiles, __traits(getProtection, 
mixin(member))) ||
__traits(getProtection, mixin(member)) != 
"private" &&
__traits(getProtection, mixin(member)) != 

pragma(msg, member);

static if (root || module_name == "std.algorithm" || 
module_name == "std.range")

import std.algorithm.searching: startsWith;

foreach(member; __traits(allMembers, 

static if (__traits(compiles, mixin(member)) &&
mixin(member).stringof.startsWith("module ")) &&

mixin(member).stringof.startsWith("module "))

As I know it worked good. Maybe it helps to you also.

derelict-sdl2 automatically stripping the SDL_ prefix from names

2018-11-26 Thread ProgramGamer via Digitalmars-d-learn


I attempted to use a combination of traits and mixins to 
automatically create aliases of names in SDL2 without the SDL_ 
prefix for convenience. However, I was only able to achieve this 
for functions in the module, and not for types nor enum values. 
How could I go about achieving the desired result? Here is the 
code I'm using in an intermediate "sdl_stripped" module:

import std.regex;
import std.array;
public import derelict.sdl2.sdl;

string StripSDLPrefix() {
auto members = [__traits(allMembers, derelict.sdl2.internal)];
foreach(ref member; members) {
if (member.length > 4 && member[0..4] == "SDL_") {
member = "alias " ~ member[4..$] ~ " = " ~ member ~ 

else {
member = "";
return members.join();


// I added this to print the list of generated names for 
debugging purposes.

static if (false) {
pragma(msg, StripSDLPrefix());