Created
September 23, 2020 20:20
-
-
Save foopis23/8b1d7e41f40729adcb1f3d12a6dae073 to your computer and use it in GitHub Desktop.
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
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] | |
-- Lua Library inline imports | |
function __TS__Class(self) | |
local c = {prototype = {}} | |
c.prototype.__index = c.prototype | |
c.prototype.constructor = c | |
return c | |
end | |
function __TS__New(target, ...) | |
local instance = setmetatable({}, target.prototype) | |
instance:____constructor(...) | |
return instance | |
end | |
function __TS__ArrayForEach(arr, callbackFn) | |
do | |
local i = 0 | |
while i < #arr do | |
callbackFn(_G, arr[i + 1], i, arr) | |
i = i + 1 | |
end | |
end | |
end | |
Player = __TS__Class() | |
Player.name = "Player" | |
function Player.prototype.____constructor(self, name) | |
self.name = name | |
self.health = 20 | |
end | |
function Player.prototype.takeDamage(self, damage) | |
self.health = self.health - damage | |
end | |
players = { | |
__TS__New(Player, "foopis23"), | |
__TS__New(Player, "jamac"), | |
__TS__New(Player, "speedgoergo") | |
} | |
__TS__ArrayForEach( | |
players, | |
function(____, player) | |
player:takeDamage( | |
math.random() * 5 | |
) | |
print( | |
(tostring(player.name) .. " ") .. tostring(player.health) | |
) | |
end | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment