Created
February 22, 2017 06:48
-
-
Save philpax/79501f24c22f0b8582252d800bd28dbc to your computer and use it in GitHub Desktop.
Moonshot examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bindings for JC2-MP API | |
extern(Lua): | |
@safe: | |
struct Vector3 | |
{ | |
float x, y, z; | |
Vector3 __add(Vector3 rhs); | |
} | |
struct Rotation | |
{ | |
float x, y, z, w; | |
float yaw, pitch, roll; | |
} | |
struct Color | |
{ | |
ubyte r, g, b; | |
} | |
struct Weapon | |
{ | |
uint id; | |
} | |
final class ServerClass | |
{ | |
public: | |
final: | |
int GetPlayerCount(); | |
Iterator!Player GetPlayers(); | |
} | |
extern ServerClass Server; | |
@property IteratorRange!Player Players()(ServerClass server) | |
{ | |
return IteratorRange!Player(server.GetPlayers()); | |
} | |
final class ChatClass | |
{ | |
public: | |
final: | |
void Broadcast(string message, Color color); | |
} | |
extern ChatClass Chat; | |
enum VehicleSeat | |
{ | |
None = -1, | |
Driver, | |
Passenger, | |
Passenger1, | |
Passenger2, | |
Passenger3, | |
Passenger4, | |
MountedGun1, | |
MountedGun2, | |
RooftopStunt, | |
BellyStunt, | |
ClingFront, | |
ClingBack, | |
ClingHeliFront | |
} | |
final class Player | |
{ | |
public: | |
double GetHealth(); | |
void SetHealth(double health); | |
Vector3 GetPosition(); | |
void SetPosition(Vector3 position); | |
Rotation GetAngle(); | |
void SetAngle(Rotation angle); | |
void EnterVehicle(Vehicle vehicle, VehicleSeat seat); | |
void GiveWeapon(uint slot, Weapon weapon); | |
void SendChatMessage(string message, Color color); | |
void ClearInventory(); | |
string GetName(); | |
bool __eq(Player rhs) const; | |
} | |
final class Vehicle | |
{ | |
public: | |
void Remove(); | |
static Vehicle Create(int id, Vector3 position, Rotation angle); | |
} | |
class EventData | |
{ | |
} | |
class PlayerEvent : EventData | |
{ | |
Player player; | |
} | |
class ClientModuleLoad : PlayerEvent | |
{ | |
} | |
class PlayerChat : PlayerEvent | |
{ | |
string text; | |
} | |
class PlayerSpawn : PlayerEvent | |
{ | |
} | |
class PlayerDeath : PlayerEvent | |
{ | |
Player killer; | |
uint reason; | |
} | |
class PlayerQuit : PlayerEvent | |
{ | |
} | |
class ModuleLoad : EventData | |
{ | |
} | |
class ModuleUnload : EventData | |
{ | |
} | |
class BaseEventManager | |
{ | |
public: | |
final: | |
alias CallbackD = extern(D) bool delegate(EventData); | |
alias CallbackF = extern(D) bool function(EventData); | |
void Subscribe(string name, CallbackD callback); | |
void Subscribe(string name, CallbackF callback); | |
} | |
extern(D) auto AutoSubscribe(EventDataType)(BaseEventManager events, bool function(EventDataType) @safe callback) | |
if (is(EventDataType : EventData)) | |
{ | |
return events.Subscribe(EventDataType.stringof, (EventData e) { | |
return callback(cast(EventDataType)e); | |
}); | |
} | |
final class EventManager : BaseEventManager | |
{ | |
public: | |
} | |
extern EventManager Events; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//!RUNTIME: runtime-jcmpTest.lua | |
import jcmp; | |
@safe: | |
@property Vector3 Position(Player player) | |
{ | |
return player.GetPosition(); | |
} | |
@property void Position(Player player, Vector3 position) | |
{ | |
player.SetPosition(position); | |
} | |
@property Rotation Angle(Player player) | |
{ | |
return player.GetAngle(); | |
} | |
@property void Angle(Player player, Rotation angle) | |
{ | |
player.SetAngle(angle); | |
} | |
bool ChatCommands(jcmp.PlayerChat event) | |
{ | |
switch (event.text) | |
{ | |
case "/up": | |
event.player.Position = event.player.Position + Vector3(0, 100, 0); | |
return false; | |
case "/down": | |
event.player.Position = event.player.Position + Vector3(0, -100, 0); | |
return false; | |
default: | |
return true; | |
} | |
} | |
Vehicle vehicle = null; | |
bool ClientModuleLoad(jcmp.ClientModuleLoad event) | |
{ | |
auto player = event.player; | |
vehicle = Vehicle.Create(2, player.Position, player.Angle); | |
player.EnterVehicle(vehicle, VehicleSeat.Driver); | |
return true; | |
} | |
int main(string[] args) | |
{ | |
Events.AutoSubscribe(&ChatCommands); | |
Events.AutoSubscribe(&ClientModuleLoad); | |
Events.Subscribe("ModuleUnload", (_) { | |
if (vehicle) | |
vehicle.Remove(); | |
return true; | |
}); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- testJcmp.d | |
function _D8testJcmp8PositionFNdNfC4jcmp6PlayerZS4jcmp7Vector3(player) | |
return player:GetPosition() | |
end | |
function _D8testJcmp8PositionFNdNfC4jcmp6PlayerS4jcmp7Vector3Zv(player, position) | |
player:SetPosition(position) | |
end | |
function _D8testJcmp5AngleFNdNfC4jcmp6PlayerZS4jcmp8Rotation(player) | |
return player:GetAngle() | |
end | |
function _D8testJcmp5AngleFNdNfC4jcmp6PlayerS4jcmp8RotationZv(player, angle) | |
player:SetAngle(angle) | |
end | |
function _D8testJcmp12ChatCommandsFNfC4jcmp10PlayerChatZb(event) | |
if event.text == "/up" then | |
_D8testJcmp8PositionFNdNfC4jcmp6PlayerS4jcmp7Vector3Zv(event.player, _D8testJcmp8PositionFNdNfC4jcmp6PlayerZS4jcmp7Vector3(event.player) + Vector3(0, 100, 0)) | |
return false | |
elseif event.text == "/down" then | |
_D8testJcmp8PositionFNdNfC4jcmp6PlayerS4jcmp7Vector3Zv(event.player, _D8testJcmp8PositionFNdNfC4jcmp6PlayerZS4jcmp7Vector3(event.player) + Vector3(0, -100, 0)) | |
return false | |
else | |
return true | |
end | |
end | |
vehicle = nil | |
function _D8testJcmp16ClientModuleLoadFNfC4jcmp16ClientModuleLoadZb(event) | |
local player = event.player | |
vehicle = Vehicle.Create(2, _D8testJcmp8PositionFNdNfC4jcmp6PlayerZS4jcmp7Vector3(player), _D8testJcmp5AngleFNdNfC4jcmp6PlayerZS4jcmp8Rotation(player)) | |
player:EnterVehicle(vehicle, 0) | |
return true | |
end | |
function _Dmain(args) | |
_D4jcmp38__T13AutoSubscribeTC4jcmp10PlayerChatZ13AutoSubscribeFNfC4jcmp16BaseEventManagerPFNfC4jcmp10PlayerChatZbZv(Events, _D8testJcmp12ChatCommandsFNfC4jcmp10PlayerChatZb) | |
_D4jcmp44__T13AutoSubscribeTC4jcmp16ClientModuleLoadZ13AutoSubscribeFNfC4jcmp16BaseEventManagerPFNfC4jcmp16ClientModuleLoadZbZv(Events, _D8testJcmp16ClientModuleLoadFNfC4jcmp16ClientModuleLoadZb) | |
Events:Subscribe("ModuleUnload", function(_) | |
if vehicle then | |
vehicle:Remove() | |
end | |
return true | |
end) | |
return 0 | |
end | |
function _D4jcmp38__T13AutoSubscribeTC4jcmp10PlayerChatZ13AutoSubscribeFNfC4jcmp16BaseEventManagerPFNfC4jcmp10PlayerChatZbZv(events, callback) | |
events:Subscribe("PlayerChat", function(e) | |
return callback(e) | |
end) | |
return | |
end | |
function _D4jcmp44__T13AutoSubscribeTC4jcmp16ClientModuleLoadZ13AutoSubscribeFNfC4jcmp16BaseEventManagerPFNfC4jcmp16ClientModuleLoadZbZv(events, callback) | |
events:Subscribe("ClientModuleLoad", function(e) | |
return callback(e) | |
end) | |
return | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() @safe | |
{ | |
import std.range : iota; | |
import std.algorithm : map, filter, each; | |
10.iota.map!(a => a * a).filter!(a => a > 50).each!print; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- testRanges.d | |
s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result = { | |
init = { | |
current = nil, | |
pastLast = nil, | |
}, | |
construct = function(current, pastLast) | |
local self = __rtDeepCopy(s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result.init) | |
self.current = current | |
self.pastLast = pastLast | |
return self | |
end, | |
__mt = { | |
__index = { | |
__ctor = function(self, current, pastLast) | |
if current < pastLast then | |
assert(_D3std4conv15__T8unsignedTiZ8unsignedFNaNbNiNfiZk(pastLast - current) <= 4294967295) | |
self.current = current | |
self.pastLast = pastLast | |
else | |
self.pastLast = current | |
self.current = self.pastLast | |
end | |
return self | |
end, | |
empty = function(self) | |
assert(self, "null this") | |
return self.current == self.pastLast | |
end, | |
front = function(self) | |
assert(self, "null this") | |
assert(not self:empty()) | |
return self.current | |
end, | |
popFront = function(self) | |
assert(self, "null this") | |
assert(not self:empty()) | |
self.current = (self.current + 1) | |
end, | |
back = function(self) | |
assert(self, "null this") | |
assert(not self:empty()) | |
return self.pastLast - 1 | |
end, | |
popBack = function(self) | |
assert(self, "null this") | |
assert(not self:empty()) | |
self.pastLast = (self.pastLast - 1) | |
end, | |
save = function(self) | |
assert(self, "null this") | |
return self | |
end, | |
opIndex = function(self, n) | |
assert(self, "null this") | |
assert(n < self:length()) | |
return self.current + n | |
end, | |
opSliceMNgFZ = function(self) | |
assert(self, "null this") | |
return self | |
end, | |
opSlice = function(self, lower, upper) | |
assert(self, "null this") | |
assert((upper >= lower) and (upper <= self:length())) | |
return s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(0, 0):__ctor(self.current + lower, self.pastLast - (self:length() - upper)) | |
end, | |
length = function(self) | |
assert(self, "null this") | |
return self.pastLast - self.current | |
end, | |
}, | |
}, | |
} | |
setmetatable(s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result.init, s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result.__mt) | |
setmetatable(s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result, { | |
__call = s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result.construct, | |
}) | |
s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult = { | |
init = { | |
_input = nil, | |
this = nil, | |
}, | |
construct = function(_input, this) | |
local self = __rtDeepCopy(s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult.init) | |
self._input = _input | |
self.this = this | |
return self | |
end, | |
__mt = { | |
__index = { | |
__ctor = function(self, input) | |
self._input = input | |
return self | |
end, | |
empty = function(self) | |
assert(self, "null this") | |
return self._input:empty() | |
end, | |
popFront = function(self) | |
assert(self, "null this") | |
assert(not self:empty(), "Attempting to popFront an empty map.") | |
self._input:popFront() | |
end, | |
front = function(self) | |
assert(self, "null this") | |
assert(not self:empty(), "Attempting to fetch the front of an empty map.") | |
return (function(a) | |
return a * a | |
end)(self._input:front()) | |
end, | |
opIndex = function(self, index) | |
assert(self, "null this") | |
return (function(a) | |
return a * a | |
end)(self._input:opIndex(index)) | |
end, | |
length = function(self) | |
assert(self, "null this") | |
return self._input:length() | |
end, | |
save = function(self) | |
assert(self, "null this") | |
return s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult(s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(0, 0)):__ctor(self._input:save()) | |
end, | |
}, | |
}, | |
} | |
setmetatable(s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult.init, s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult.__mt) | |
setmetatable(s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult, { | |
__call = s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult.construct, | |
}) | |
s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult = { | |
init = { | |
_input = nil, | |
this = nil, | |
}, | |
construct = function(_input, this) | |
local self = __rtDeepCopy(s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult.init) | |
self._input = _input | |
self.this = this | |
return self | |
end, | |
__mt = { | |
__index = { | |
__ctor = function(self, r) | |
self._input = r | |
while not self._input:empty() and not (function(a) | |
return a > 50 | |
end)(self._input:front()) do | |
self._input:popFront() | |
end | |
return self | |
end, | |
opSlice = function(self) | |
assert(self, "null this") | |
return self | |
end, | |
empty = function(self) | |
assert(self, "null this") | |
return self._input:empty() | |
end, | |
popFront = function(self) | |
assert(self, "null this") | |
repeat | |
self._input:popFront() | |
until not (not self._input:empty() and not (function(a) | |
return a > 50 | |
end)(self._input:front())) | |
end, | |
front = function(self) | |
assert(self, "null this") | |
assert(not self:empty(), "Attempting to fetch the front of an empty filter.") | |
return self._input:front() | |
end, | |
save = function(self) | |
assert(self, "null this") | |
return s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult(s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult):__ctor(self._input:save()) | |
end, | |
}, | |
}, | |
} | |
setmetatable(s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult.init, s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult.__mt) | |
setmetatable(s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult, { | |
__call = s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult.construct, | |
}) | |
function _Dmain() | |
--[[stmt import std.range : iota; | |
]] | |
--[[stmt import std.algorithm : map, filter, each; | |
]] | |
_D3std9algorithm9iteration16__T4eachS5printZ233__T4eachTS3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResultZ4eachFNfS3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResultZv(_D3std9algorithm9iteration45__T6filterS3110testRanges4mainFNfZ9__lambda2Z140__T6filterTS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ6filterMFNaNbNiNfS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZS3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult(_D3std9algorithm9iteration42__T3mapS3110testRanges4mainFNfZ9__lambda1Z51__T3mapTS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ3mapMFNaNbNiNfS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult(_D3std5range11__T4iotaTiZ4iotaFNaNbNiNfiZS3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(10)))) | |
return 0 | |
end | |
function _D3std5range13__T4iotaTiTiZ4iotaFNaNbNiNfiiZS3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(begin, _end) | |
--[[stmt import std.conv : unsigned; | |
]] | |
return s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(0, 0):__ctor(begin, _end) | |
end | |
function _D3std4conv15__T8unsignedTiZ8unsignedFNaNbNiNfiZk(x) | |
return x | |
end | |
function _D3std5range11__T4iotaTiZ4iotaFNaNbNiNfiZS3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(_end) | |
local begin = 0 | |
return _D3std5range13__T4iotaTiTiZ4iotaFNaNbNiNfiiZS3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(begin, _end) | |
end | |
function _D3std9algorithm9iteration42__T3mapS3110testRanges4mainFNfZ9__lambda1Z51__T3mapTS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ3mapMFNaNbNiNfS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult(r) | |
--[[stmt import std.meta : AliasSeq, staticMap; | |
]] | |
return s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult(s3std5range13__T4iotaTiTiZ4iotaFiiZ6Result(0, 0)):__ctor(r) | |
end | |
function _D3std9algorithm9iteration45__T6filterS3110testRanges4mainFNfZ9__lambda2Z140__T6filterTS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ6filterMFNaNbNiNfS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZS3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult(range) | |
return s3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResult(s3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResult):__ctor(range) | |
end | |
function _D3std9algorithm9iteration16__T4eachS5printZ233__T4eachTS3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResultZ4eachFNfS3std9algorithm9iteration181__T12FilterResultS3110testRanges4mainFNfZ9__lambda2TS3std9algorithm9iteration91__T9MapResultS3110testRanges4mainFNfZ9__lambda1TS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ9MapResultZ12FilterResultZv(r) | |
while not r:empty() do | |
print(r:front()) | |
r:popFront() | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math; | |
import io; | |
@safe: | |
auto sum(T...)(T args) | |
{ | |
T[0] ret; | |
foreach (arg; args) | |
ret += arg; | |
return ret; | |
} | |
int main(string[] args) | |
{ | |
print(sum(1, 2, 3, 4)); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- testSum.d | |
function _Dmain(args) | |
print(_D7testSum16__T3sumTiTiTiTiZ3sumFNaNbNiNfiiiiZi(1, 2, 3, 4)) | |
return 0 | |
end | |
function _D7testSum16__T3sumTiTiTiTiZ3sumFNaNbNiNfiiiiZi(_param_0, _param_1, _param_2, _param_3) | |
local ret = 0 | |
do | |
local arg = _param_0 | |
ret = (ret + arg) | |
end | |
do | |
local arg = _param_1 | |
ret = (ret + arg) | |
end | |
do | |
local arg = _param_2 | |
ret = (ret + arg) | |
end | |
do | |
local arg = _param_3 | |
ret = (ret + arg) | |
end | |
return ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment