Skip to content
Open
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
42 changes: 42 additions & 0 deletions source/lumars/state.d
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,15 @@ struct LuaState
import std.conv : to;
import std.traits : isNumeric, isDynamicArray, isAssociativeArray, isDelegate, isPointer, isFunction,
PointerTarget, KeyType, ValueType, FieldNameTuple, TemplateOf, TemplateArgsOf;

static if (__traits(compiles, value is null))
{
if (value is null)
{
lua_pushnil(this.handle);
return;
}
}

static if(is(T == typeof(null)) || is(T == LuaNil))
lua_pushnil(this.handle);
Expand Down Expand Up @@ -1040,6 +1049,39 @@ struct LuaState
lua.pop(1);
}

unittest
{
string str = null;
auto lua = LuaState(null);

lua.globalTable["a"] = str;
lua.doString("assert(a == nil)");

lua.globalTable["b"] = "";
lua.doString("assert(b == '')");

class C {}
C c = null;
lua.globalTable["c"] = c;
lua.doString("assert(c == nil)");

string[int] d;
lua.globalTable["d"] = d;
lua.doString("assert(d == nil)");

int[] e;
lua.globalTable["e"] = e;
lua.doString("assert(e == nil)");

int function() f;
lua.globalTable["f"] = f;
lua.doString("assert(f == nil)");

int delegate() g;
lua.globalTable["g"] = g;
lua.doString("assert(g == nil)");
}

@nogc
bool next(int index) nothrow
{
Expand Down