Code Monkey home page Code Monkey logo

gmod-typescript's People

Contributors

dependabot[bot] avatar lolleko avatar timonz1535 avatar utkinn avatar vurv78 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gmod-typescript's Issues

Optional arguments

Would it be possible to support optional arguments? An example of this would be https://wiki.facepunch.com/gmod/Global.EmitSound

declare function EmitSound(soundName: string, position: Vector, entity: number, channel: CHAN, volume: number, soundLevel: SNDLVL, soundFlags: SND, pitch: number, dsp: number): void;

When it should be:

declare function EmitSound(soundName: string, position: Vector, entity: number, channel?: CHAN, volume?: number, soundLevel?: SNDLVL, soundFlags?: SND, pitch?: number, dsp?: number): void;

Operator Map Types (Metamethods)

Hi, I found this project and decided to try it out. You've done a great job! The GLua API works very well. And it's really cool that anyone can try out a working toolkit, not a theoretical one (I've tried CSharp.lua, but there's no complete GLua API for it anywhere).

I am faced with the problem that Vector, Angle and VMatrix have metamethods for operator overloading, but they cannot work in TypeScript. This is by design of the TypeScript, because the JavaScript does not have an operator overloading :<

However, I found that the developers of the TypeScriptToLua provided special mapping functions:
https://typescripttolua.github.io/docs/advanced/language-extensions#operator-map-types

Also Vector and Angle have index variables (x, y, z, p, y, r, pitch, yaw, roll) that can be declared in the interface, instead of doing them through mapping functions.

For example operators as methods:

interface Vector {

	x: number, 1: number;
	y: number, 2: number;
	z: number, 3: number;

	add: LuaAdditionMethod<Vector, Vector>;
	sub: LuaSubtractionMethod<Vector, Vector>;
	// mul: LuaMultiplicationMethod <Vector, Vector> & LuaMultiplicationMethod <number, Vector>; // two methods (+1 overload)
	mul: LuaMultiplicationMethod <Vector | number, Vector>; // its also correct but one method
	div: LuaDivisionMethod <number, Vector>;
	neg: LuaNegationMethod <Vector>; // or 'negate' or 'unm'?

	...

how it looks

		let offset = Vector(0, 0, 10)
		let basePoint = Vector(0, 0, 1000)
		instance.pos = Vector()
		instance.pos[3] = 30
		instance.pos.z = 30
		instance.pos.y = instance.pos.y + 20
		instance.pos = instance.pos.add(basePoint)

		instance.pos = instance.pos.mul(Vector(0, 0, 1000))
		instance.pos = instance.pos.mul(2)
		instance.pos = instance.pos.div(2)

		instance.pos = instance.pos.neg().mul(2).add(basePoint).sub(offset)

and gets this lua code

        local offset = Vector(0, 0, 10)
        local basePoint = Vector(0, 0, 1000)
        instance.pos = Vector()
        instance.pos[3] = 30
        instance.pos.z = 30
        instance.pos.y = instance.pos.y + 20
        instance.pos = instance.pos + basePoint
        instance.pos = instance.pos * Vector(0, 0, 1000)
        instance.pos = instance.pos * 2
        instance.pos = instance.pos / 2
        instance.pos = ((-instance.pos * 2) + basePoint) - offset

Could you add operators and index variables to your declarations?

Entity classes (Like Player/Npc/Weapon) should extend the Entity class

If you try and access an Entity function on a Player, you'll get an error. Same with trying to compare a Player with an Entity. This is since these classes don't derive / extend the Entity.

In my bindings for Haxe to starfall I ended up hardcoding these since the Gmod Wiki doesn't tell you anything about which classes inherit from what
https://github.com/Vurv78/SFHaxe/blob/528b30a2a78ac5f044aac5d8583c67da84f05955/src/generator/Hardwired.hx#L39

Will probably need to do the same here unfortunately, there's some basic/the most common ones in the link I provided

... functions expecting arrays

Functions like print are generated as so right now:

declare function print(args: any[]): void;

They should be like this instead (as far as I know)
Works for me when I manually changed it.

declare function print(...args: any[]): void;

Nice project dude, I was thinking of making this but then was pointed to this after they found it when I somehow couldn't..

Another Note: I think you're supposed to make all of these functions @noSelf because they're all passing nil as the first argument. https://typescripttolua.github.io/docs/the-self-parameter/

Replacing generated JS functions with builtin gmod functions

Gmod comes with a number of builtin libraries such as the string library. For example:

// JavaScript version
print("haystack".endsWith("needle"))
// Gmod version
print(string.EndsWith("haystack","needle"))

Both of these functions will accomplish the same goal, however if using the JS version, the transpiler will need to add

local function __TS__StringEndsWith(self, searchString, endPosition)
    if endPosition == nil or endPosition > #self then
        endPosition = #self
    end
    return string.sub(self, endPosition - #searchString + 1, endPosition) == searchString
end

to the transpiled output. This will result in a lot of redundant code.
Is there a way we can make TypeScriptToLua use the built-in gmod libraries?
I'd be happy to write the logic to do so, just not sure if it is possible or where to start.

Missing Globals, Realms / States

There is no way to control script workflow with a SERVER/CLIENT realms. Its not exists in TypeScript.

https://wiki.facepunch.com/gmod/States

There are also some global variables, such as ENT, SWEP, GM. However, I have no idea how to implement them correctly, because they will be visible in the entire TypeScript code. TypeScriptToLua uses globalThis for _G alias. globalThis implemented by TypeScript itself.

https://wiki.facepunch.com/gmod/Global_Variables

Minor. Garry's mod also have some constants (vector_origin, vector_up) at the bottom of the page.
I don't like their names, I'd rather make my own like ZeroVector, ForwardVector and other. But perhaps it can be useful to someone. I think you will decide for yourself whether you need to spend time on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.