Open jushar opened 6 years ago
Hey! Congrats on getting the first issue, and thanks for reporting this one!
Totally yes! On all your points. Tried your Haxe stuff after messing with this, and didn't liked the output. I got all weird prototypes in my lua file. I started messing with typescript for the MTA:SA Lua Syntax Highlighter and... I LOVED it.
The plan here is first of all get the functions sorted.. Tbh it's a fucking mess haha. https://github.com/Subtixx/mtasa-typescript/blob/master/MTA.d.ts#L67 https://github.com/Subtixx/mtasa-typescript/blob/master/MTA.d.ts#L72
Like that. Still having some trouble figuring TS out though. For example I'm not able to put the typings in a sub-directory which makes things hard atm. But yea after that's done I want to do the OOP stuff too. But the TypeScriptToLua transpiler is a bit messy (See issue I opened over there, thats also the reason why my fork exists!)
I'll have to look into further modifying the transpiler. Since the transpiler will make this lua script:
MTA.addEvent(MTA,"onClientPlayerKillMessage",true)
function onClientPlayerKillMessage(killer,weapon,wr,wg,wb,kr,kg,kb,width,resource)
if MTA.wasEventCancelled(MTA) then
return
end
outputKillMessage(source,wr,wg,wb,killer,kr,kg,kb,weapon,width,resource)
end
MTA.addEventHandler(MTA,"onClientPlayerKillMessage",MTA.getRootElement(MTA),onClientPlayerKillMessage)
from this typescript:
MTA.addEvent("onClientPlayerKillMessage", true)
function onClientPlayerKillMessage(killer: MTA.Player, weapon, wr, wg, wb, kr, kg, kb, width, resource) {
if (MTA.wasEventCancelled()) return;
outputKillMessage(MTA.source, wr, wg, wb, killer, kr, kg, kb, weapon, width, resource)
}
MTA.addEventHandler("onClientPlayerKillMessage", MTA.getRootElement(), onClientPlayerKillMessage);
Okay. This is now fixed with https://github.com/Subtixx/TypescriptToLua/commit/6ec1241e041eb207a7a50e16845d14faca56831c it will now produce the expected output of:
addEvent("onClientPlayerKillMessage",true)
function onClientPlayerKillMessage(killer,weapon,wr,wg,wb,kr,kg,kb,width,resource)
if wasEventCancelled() then
return
end
outputKillMessage(MTA.source,wr,wg,wb,killer,kr,kg,kb,weapon,width,resource)
end
addEventHandler("onClientPlayerKillMessage",getRootElement(),onClientPlayerKillMessage)
EDIT: Okay the output should now be completely correct (MTA.source => source) with https://github.com/Subtixx/TypescriptToLua/commit/4dcf985faf824b8e6e729b56c3086e4781e3bcdd
addEvent("onClientPlayerKillMessage",true)
function onClientPlayerKillMessage(killer,weapon,wr,wg,wb,kr,kg,kb,width,resource)
if wasEventCancelled() then
return
end
outputKillMessage(source,wr,wg,wb,killer,kr,kg,kb,weapon,width,resource)
end
addEventHandler("onClientPlayerKillMessage",getRootElement(),onClientPlayerKillMessage)
Still work in progress but I'd do it like this: https://github.com/Subtixx/mtasa-typescript/tree/oop
Is this what you suggested?
Yes, exactly.
First of all, I'm pretty excited about this project. If it works as expected and the underlying TypeScriptToLua library gets mature enough, it may even be superior to the Haxe stuff.
One suggestion though: Since TypeScript tends to be more of an object-oriented language with ES6 classes, I'd suggest you additionally provide an object-orientied API and favour it over the procedural one (e.g. by moving it to a separate namespace).