On 2013-12-01 2:34 AM, Sönke Ludwig wrote:

Am 01.12.2013 04:14, schrieb Etienne:

I'm writing a Lua D adaptation for Vibe.d to add scripting support. When
requesting data from HDD using loadFrom(path), would there be a function
that yields during a HDD request?

Do you mean loadfile as used for loading a script? In that case I'd
simply ignore HDD I/O as the file size should be small enough for I/O
not to really matter. If it's about loading data from disk from inside a
LUA script, you'd probably have to register your own function for
loading the contents and skip loading the one from the LUA standard
library (or unregister/overwrite it)*.

I just finished adapting this Lua wrapper for D - very useful for quick
debugging huge apps or just doing any runtime routines, it runs in a
vibe.d instance very well. It implements all functions and members of D
Classes in a lua interpreter like this:

Lua["varname"] = new SomeDClass();

https://github.com/JakobOvrum/LuaD/pull/60

e.g

import luad.all;

static void panic(LuaState lua, in char[] error)
{

throw new Exception(error);

}

struct Contact
{

string forename, surname;
string email;
uint number;

}

Contact[] fromFile(in char[] path)
{

auto lua = new LuaState;
Contact[] contacts;

lua["Contact"] = (Contact c)
{
	contacts ~= c;
};

lua.doFile(path);

lua.setPanicHandler(&panic);

lua.doString(`function sum(n)	return (n*n - n)/2;  end

		local s = 0
		for i=1,100 do
			s = s + i
			assert(sum(i) == s, "Case "..i.." failed: expected "..s.." but got 

"..sum(i).." instead.")

end`);

return contacts;

}

void index(HTTPServerRequest req, HTTPServerResponse res)
{

Contact[] phonebook = fromFile("contacts.lua");

 res.render!("index.dt", req, phonebook);

}

contacts.lua :

Contact
{

forename = "Foo";
surname = "Bar";

email = "foobar@example.com";
number = 123456789;

}

Contact
{

forename = "John";
surname = "Smith";

email = "johnsmith@elpmaxe.moc";
number = 987654321;

}