JakobOvrum/LuaD

Lua global print value is nil

Closed this issue · 2 comments

When attempting to print from Lua the result is an error:

luad.error.LuaError: [string "print("Hello")"]:1: attempt to call global 'print'
(a nil value)

import luad.all;

import std.stdio;


void main() {
   auto lua = new LuaState;

   lua.doString("print(\"Hello\")");
}

You need to call .openLibs before using the standard library:

auto lua = new LuaState;
lua.openLibs();
lua.doString(`print("Hello")`);

(Also note how wysiwyg strings are useful with doString)

Thought I might have been doing something wrong. Thank you for the fast turn around.