// from another unit: // lua_CFunction = function(l: plua_State): integer; stdcall; type TGVLuaFunction = lua_Cfunction; TGVLua = class [...] function PopStackFunction(): TGVLuaFunction; function GetFunction(aStructStackIndex: Integer; aFieldName: String): TGVLuaFunction; [...] end; function TGVLua.PopStackFunction(): TGVLuaFunction; begin Result := lua_tocfunction(FLua.FState, -1); // lua_tocfunction() returns a value of type lua_CFunction (TGVLuaFunction) Pop(1); end; function TGVLua.GetFunction(aStructStackIndex: Integer; aFieldName: String): TGVLuaFunction; begin lua_pushstring(FState, PChar(aFieldName)); lua_gettable(FState, aStructStackIndex); // the above sets up the Lua stack with the value, and the below retrieves it. Result := PopStackFunction; // [Error]: Incompatible types: 'Calling conventions differ' on PopStackFunction. end;