Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct conversions with private/internal members (fix #95) #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions luad/all.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ module luad.all;
public import luad.base, luad.table, luad.lfunction, luad.dynamic, luad.state, luad.lmodule;

public import luad.conversions.functions : LuaVariableReturn, variableReturn;
public import luad.conversions.structs : internal;
16 changes: 12 additions & 4 deletions luad/conversions/structs.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import luad.c.all;

import luad.stack;

private template isInternal(string field)
enum internal;

private template isInternal(T, string field)
{
enum isInternal = field.length >= 2 && field[0..2] == "__";
import std.traits : hasUDA;
enum isInternal = hasUDA!(mixin("T."~field), internal) || field.length >= 2 && field[0..2] == "__";
}

//TODO: ignore static fields, post-blits, destructors, etc?
Expand All @@ -24,7 +27,8 @@ void pushStruct(T)(lua_State* L, ref T value) if (is(T == struct))

foreach(field; __traits(allMembers, T))
{
static if(!isInternal!field &&
static if(__traits(getProtection, mixin("T."~field))=="public" &&
!isInternal!(T, field) &&
field != "this" &&
field != "opAssign")
{
Expand Down Expand Up @@ -53,7 +57,11 @@ void fillStruct(T)(lua_State* L, int idx, ref T s) if(is(T == struct))
{
foreach(field; __traits(allMembers, T))
{
static if(field != "this" && !isInternal!(field))
static if(
field != "this"
&& __traits(getProtection, mixin("T."~field))=="public"
&& !isInternal!(T, field)
)
{
static if(__traits(getOverloads, T, field).length == 0)
{
Expand Down