Skip to content

Commit dccf240

Browse files
committed
Added @noscript
1 parent 67883d7 commit dccf240

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

luad/base.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import luad.stack;
55

66
import std.c.string : strlen;
77

8+
9+
// shall we declare the attributes here?
10+
struct noscript {}
11+
12+
813
/**
914
* Enumerates all Lua types.
1015
*/

luad/conversions/helpers.d

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import luad.all;
1111
import core.memory;
1212

1313
import std.traits;
14+
import std.typetuple;
1415

1516
package:
1617

@@ -133,7 +134,7 @@ template skipMember(T, string member)
133134
__traits(getProtection, __traits(getMember, T, member)) != "public")
134135
enum skipMember = true;
135136
else
136-
enum skipMember = false;
137+
enum skipMember = hasAttribute!(__traits(getMember, T, member), noscript) >= 0;
137138
}
138139

139140
template returnsRef(F...)
@@ -144,6 +145,41 @@ template returnsRef(F...)
144145
enum returnsRef = false;
145146
}
146147

148+
template hasAttribute(alias x, alias attr)
149+
{
150+
template typeImpl(int i, A...)
151+
{
152+
static if(A.length == 0)
153+
enum typeImpl = -1;
154+
else static if(is(A[0]))
155+
enum typeImpl = is(A[0] == attr) ? i : typeImpl!(i+1, A[1..$]);
156+
else
157+
enum typeImpl = is(typeof(A[0]) == attr) ? i : typeImpl!(i+1, A[1..$]);
158+
}
159+
template valImpl(int i, A...)
160+
{
161+
static if(A.length == 0)
162+
enum valImpl = -1;
163+
else static if(is(A[0]) || !is(typeof(A[0]) : typeof(attr)))
164+
enum valImpl = valImpl!(i+1, A[1..$]);
165+
else
166+
enum valImpl = A[0] == attr ? i : valImpl!(i+1, A[1..$]);
167+
}
168+
static if(is(attr))
169+
enum hasAttribute = typeImpl!(0, __traits(getAttributes, x));
170+
else
171+
enum hasAttribute = valImpl!(0, __traits(getAttributes, x));
172+
}
173+
174+
template getAttribute(alias x, size_t i)
175+
{
176+
alias Attrs = TypeTuple!(__traits(getAttributes, x));
177+
static if(is(Attrs[i]))
178+
alias getAttribute = TypeTuple!(Attrs[i]);
179+
else
180+
enum getAttribute = TypeTuple!(Attrs[i]);
181+
}
182+
147183

148184
void pushGetter(T, string member)(lua_State* L)
149185
{

0 commit comments

Comments
 (0)