Skip to content

Latest commit

 

History

History
89 lines (58 loc) · 2.28 KB

File metadata and controls

89 lines (58 loc) · 2.28 KB

int.unm

https://github.com/SupTan85/int.lua

Syntax & Usage

Note

This function handles the unary minus operator, it negates the value of the given number.

function int.unm(x, self_changed) -- reverses the sign.
Parameter Type Description
x int object only Required. The value whose sign will be reversed.
self_changed boolean (default: false) Optional. Enable if you want to change the value in this object only.
(disable copy object for optimization)

Return Value:

  1. int object

Example:

local int = require("int") -- import module

local x, y = int.new("-12.2", "12.3456")
print(int.unm(x)) -- output: 12.2
print(int.unm(y)) -- output: -12.3456

operators

This feature lets you to call a function with an operator.

Important

function was embedded in __unm on metadata.

local int = require("int") -- import module

local x, y = int.new("-123", "12.3456")
print(-x) -- output: 123
print(-y) -- output: -12.3456

methods

This feature lets you to call functions on an object.

local int = require("int") -- import module

local x, y = int.new("-12.2", "12.3456")
print(x:unm()) -- output: 12.2
print(y:unm()) -- output: -12.3456

Tip

In this example, a function inside the object is called and returns the object itself as the input.

also you can do like this:

local int = require("int") -- import module

local x, y = int.new("-12.2", "12.3456")

-- this works like "print(int.unm(x))"
print(y.unm(x)) -- output: 12.2

-- this works like "print(int.unm(y))"
print(x.unm(y)) -- output: -12.3456

Tip

In this example, a function inside the object is called but a different object is used as the input.


function & methods
operators

end