Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.61 KB | None | 0 0
  1. extern(C) int methodWrapper(T, Class)(lua_State* L)
  2. {
  3.     ParameterTypeTuple!T args;
  4.    
  5.     //Check arguments
  6.     int top = lua_gettop(L);
  7.     if(top < args.length + 1)
  8.         argsError(L, top, args.length + 1);
  9.    
  10.     //Assemble method
  11.     T func;
  12.     func.ptr = *cast(void**)luaL_checkudata(L, 1, toStringz(Class.mangleof));
  13.     func.funcptr = cast(typeof(func.funcptr))lua_touserdata(L, lua_upvalueindex(1));
  14.    
  15.     //Assemble arguments
  16.     foreach(i, arg; args)
  17.     {
  18.         //stack indexes start at 1, index 1 is the 'this' reference
  19.         args[i] = getValue!(typeof(arg), typeMismatch)(L, i + 2);
  20.     }
  21.    
  22.     return callFunction!T(L, func, args);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement