Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide OOP declarations #1

Open
jushar opened this issue Feb 13, 2018 · 5 comments
Open

Provide OOP declarations #1

jushar opened this issue Feb 13, 2018 · 5 comments
Labels
enhancement New feature or request

Comments

@jushar
Copy link

jushar commented Feb 13, 2018

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).

@Subtixx
Copy link
Owner

Subtixx commented Feb 13, 2018

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!)

@Subtixx Subtixx added the enhancement New feature or request label Feb 13, 2018
@Subtixx
Copy link
Owner

Subtixx commented Feb 17, 2018

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);

@Subtixx
Copy link
Owner

Subtixx commented Feb 18, 2018

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)

@Subtixx
Copy link
Owner

Subtixx commented Feb 20, 2018

Still work in progress but I'd do it like this:
https://github.com/Subtixx/mtasa-typescript/tree/oop

Is this what you suggested?

@jushar
Copy link
Author

jushar commented Feb 20, 2018

Yes, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants