Skip to content

Commit 1dc35ec

Browse files
committed
local cruft
1 parent d7c1846 commit 1dc35ec

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

luad/conversions/enums.d

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@ string getEnumFromValue(Enum)(Enum value)
7878
return null;
7979
}
8080

81+
/+ TODO: I'd quite like to support bitfields too...
82+
uint getBitfieldValue(Enum)(const(char)[] flags)
83+
{
84+
uint value;
85+
foreach(token; flags.splitter('|').map!(a => a.strip).filter!(a => !a.empty))
86+
{
87+
Enum val = getEnumValue!Enum(token);
88+
if(val != cast(Enum)-1)
89+
value |= val;
90+
}
91+
return value;
92+
}
93+
94+
string getBitfieldFromValue(Enum)(uint bits)
95+
{
96+
string bitfield;
97+
foreach(i; 0..32)
98+
{
99+
uint bit = 1 << i;
100+
if(!(bits & bit))
101+
continue;
102+
103+
string key = getEnumFromValue(cast(Enum)bit);
104+
if(key)
105+
{
106+
if(!bitfield)
107+
bitfield = key;
108+
else
109+
bitfield = bitfield ~ "|" ~ key;
110+
}
111+
}
112+
return bitfield;
113+
}
114+
+/
115+
81116
void pushEnum(T)(lua_State* L, T value) if (is(T == enum))
82117
{
83118
string key = getEnumFromValue(value);

luad/state.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public:
9999
}
100100

101101
/// The underlying $(D lua_State) pointer for interfacing with C.
102-
@property lua_State* state() nothrow pure @safe
102+
@property inout(lua_State)* state() inout nothrow pure @safe
103103
{
104104
return L;
105105
}

0 commit comments

Comments
 (0)