How can I get the "owner" of a method?

solidstate1991 laszloszeremi at
Fri Sep 30 21:11:48 UTC 2022

Let's say I have a class or an interface with a function, and I 
want to pass that to a template to generate another function (in 
this case one that passes it to a scripting engine, and allows it 
to be called from there).

Currently I have the following issues:

1. I have to pass the class/interface type to the template, and I 
cannot find anything about how to solve this issue.
2. It also doesn't work at the moment, as it wants to call the 
member `Func` (name of the template argument) rather than the 
Function described as such. (There's also probably in 
std.functional I don't know about)


extern (C) public int registerDDelegate(alias Func, 
ClassType)(lua_State* state) nothrow
		if(isSomeFunction!(Func)) {
	import std.traits:Parameters, ReturnType;
	Parameters!Func params;
	int stackCounter = 0;
	ClassType c = luaGetFromIndex!ClassType(state, stackCounter);
	try {
		foreach_reverse(ref param; params) {
			param = luaGetFromIndex!(typeof(param))(state, stackCounter);
	} catch (Exception e) {
		luaL_error(state, "Argument type mismatch with D functions!");
	try {
		static if(is(ReturnType!Func == void)) {
			return 0;
		} else static if(is(ReturnType!Func == struct)) {
			auto retVal = c.Func(params);
			static foreach (key ; retVal.tupleof) {
			return cast(int)retVal.tupleof.length;
		} else {
			return 1;
	} catch (Exception e) {
		//luaPushVar(L, null);
		lastLuaToDException = e;
		try {
			luaL_error(state, ("A D function threw: 
		} catch(Exception e) {
			luaL_error(state, "D threw when stringifying exception!");
		return 1;

More information about the Digitalmars-d-learn mailing list