diff --git a/source/lumars/state.d b/source/lumars/state.d index 02b9a36..bd96519 100644 --- a/source/lumars/state.d +++ b/source/lumars/state.d @@ -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); @@ -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 {