Quartz101, on 01 January 2016 - 04:57 AM, said:
use fs.open("/hello", "w") {
write("Hello!")
close()
}
Using `use` could also make the resource self-closing (close when the scope is closed).
Posted 01 January 2016 - 02:26 PM
with fs.open("/test", "r+") as file {
file.write("hello")
}
do
local _rsx0_file = fs.open("/test", "r+")
_rsx0_file.write("hello")
if _rsx0_file.close then
_rsx0_file.close()
end
end
Edited by DemHydraz, 01 January 2016 - 02:26 PM.
Posted 01 January 2016 - 03:04 PM
Quartz101, on 01 January 2016 - 04:57 AM, said:
use fs.open("/hello", "w") {
write("Hello!")
close()
}
use aMethod() {
write(foobar)
}
foobar (and write) could either be a local variable or a property on the table.
DemHydraz, on 01 January 2016 - 02:26 PM, said:
with fs.open("/test", "r+") as file {
file.write("hello")
}
with file = fs.open("test", "w") {
file.write("testing!")
file.close()
}
Edited by SquidDev, 01 January 2016 - 03:04 PM.
Posted 06 January 2016 - 12:49 PM
Edited by Konlab, 06 January 2016 - 12:52 PM.
Posted 06 January 2016 - 09:11 PM
Edited by Detective_Smith, 06 January 2016 - 09:31 PM.
Posted 06 January 2016 - 09:55 PM
Posted 06 January 2016 - 09:56 PM
Edited by Detective_Smith, 06 January 2016 - 09:59 PM.
Posted 18 January 2016 - 04:29 PM
local class Vector3 (vec3) {
public x, y, z = 0, 0, 0
private shared: // Faster than regular private as its only declared once.
sqrt = math.sqrt
floor = math.floor
public:
function dot(v: vec3) { return self.x * v.x + self.y * v.y + self.z * v.z }
function cross(v: vec3) { return new Vector3(x: self.y*v.z-self.z*v.y, y: self.z*v.x-self.x*v.z, z: self.x*v.y-self.y*v.x ) }
function length() { return sqrt(self.x*self.x + self.y*self.y + self.z*self.z) }
function normalize() { return self * (1 / self.length()) }
function round() { return new Vector3(x: floor(self.x + 0.5), y: floor(self.y + 0.5), z: floor(self.z + 0.5)) }
metamethod: // Metamethods automatically have '__' added before each one, so metamethod add would be accessed as object.__add
function add(v: vec3) { return new Vector3(x: self.x += v.x, y: self.y += v.y, z: self.z += v.z) }
function sub(v: vec3) { return new Vector3(x: self.x -= v.x, y: self.y -= v.y, z: self.z -= v.z) }
function div(m: number) { return new Vector3(x: self.x *= m, y: self.y *= m, z: self.z *= m) }
function mul(m: number) { return new Vector3(x: self.x /= m, y: self.y /= m, z: self.z /= m) }
function unm(m: number) { return new Vector3(x: -self.x, y: -self.y, z: -self.z) }
function tostring() { return self.x..","..self.y..","..self.z }
}
Edited by Detective_Smith, 18 January 2016 - 04:31 PM.
Posted 19 January 2016 - 06:32 PM
Detective_Smith, on 26 December 2015 - 06:59 PM, said:
if x == 1 { print("yay!") }
if ifFound then
foundIF = true
end
if found "}" or "{" then
do stuff...
foundIF = false
end
Posted 19 January 2016 - 09:20 PM
LeDark Lua, on 19 January 2016 - 06:32 PM, said:
if ifFound then
foundIF = true
end
if found "}" or "{" then
do stuff...
foundIF = false
end
Posted 21 January 2016 - 01:32 AM
Edited by Detective_Smith, 21 January 2016 - 01:34 AM.
Posted 01 February 2016 - 08:10 PM
local class Vector3(x: number, y: number, z: number) @vec3 {
public x, y, z = x or 0, y or 0, z or 0
private shared floor, sqrt = math.floor, math.sqrt
// Static and shared functions and variables allow for faster object creation time.
// Also, you can have a ':' following the declared variables and functions. Though,
// It should be noted that this is as optional as ';' is for statements.
public static:
function dot(v: vec3) { return self.x * v.x + self.y * v.y + self.z * v.z }
function cross(v: vec3) { return Vector3(self.y*v.z-self.z*v.y, self.z*v.x-self.x*v.z, self.x*v.y-self.y*v.x ) }
function length() { return sqrt(self.x*self.x + self.y*self.y + self.z*self.z) }
function normalize() { return self * (1 / self.length()) }
function round() { return Vector3(floor(self.x + 0.5), floor(self.y + 0.5), floor(self.z + 0.5)) }
// Of course all these metamethods are accessed with a '__' prefix. For example, function add is accessed
// as object.__add. However, as said before, we can use 'static' allowing for greater control over
// metamethods. Naturally, the faster creation time benefit that comes with static follows here as well.
public static metamethod:
function add(v1: vec3, v2: vec3) { return Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z) }
function sub(v1: vec3, v2: vec3) { return Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z) }
function mul(v: vec3, m: number) { return Vector3(v.x * m, v.y * m, v.z * m) }
function div(v: vec3, m: number) { return Vector3(v.x / m, v.y / m, v.z / m) }
function unm(v: vec3, m: number) { return Vector3(-v.x, -v.y, -v.z) }
function tostring(v) { return v.x..","..v.y..","..v.z }
}
Edited by Detective_Smith, 02 February 2016 - 09:52 PM.
Posted 05 February 2016 - 09:24 PM
local class Object(color: number, size: number, shape: string) {
public:
color = color
size = size
shape = shape
}
local class Object(color: number => 1, size: number => 1, shape: string => "square") {
public:
color = color
size = size
shape = shape
}
Posted 13 February 2016 - 08:24 PM
local class Entity(name: string => "Unknown", king: string => "Unknown", spec: string => "Unknown", sound: string => "...", test => "boolean") @entity {
public name, kingdom, species, sound = name, king, spec, sound
private shared totalEntities = 0
public static:
function sayName() {
print("My name is " ..self.name)
}
function makeSound() {
print(self.sound)
}
function getTotal() {
print("There are " ..totalEntities.. " entities.")
}
private function init() {
totalEntities++
}
}
local class Animal(name: string, spec: string, sound: string) @animal extends Entity {
@super(name, "Animalia", spec, sound)
private shared totalAnimals = 0
public sound = sound
public static function getTotal() {
print("There are " ..totalAnimals.. " animals.")
}
private function init() {
totalAnimals++
}
}
local class Human(name: string, age: number) @human extends Animal {
@super(name, "Homo sapien", "Hi there!")
private shared totalHumans = 0
private age = age
public function getAge() {
print("I'm " ..age.. " years old.")
}
public static function getTotal() {
print("There are " ..totalHumans.. " humans.")
}
private function init() {
totalHumans++
}
}
local e1 = Entity()
local a1 = Animal("Leo", "Lion", "RAWR!")
a1:makeSound()
local h1 = Human("Bob", 24)
h1:getAge()
e1:getTotal()
a1:getTotal()
h1:getTotal()
/* The output of the program:
RAWR!
I'm 24 years old.
There are 3 entities.
There are 2 animals.
There are 1 humans.
*/
Edited by Detective_Smith, 13 February 2016 - 08:27 PM.
Posted 13 February 2016 - 08:42 PM
Edited by LeDark Lua, 14 February 2016 - 03:10 PM.
Posted 14 February 2016 - 03:17 PM
Posted 04 March 2016 - 11:16 PM
Edited by Detective_Smith, 20 March 2016 - 02:26 PM.
Posted 20 March 2016 - 09:17 AM
Posted 20 March 2016 - 02:18 PM
local x, y, = 10, 20 x, y += 30 // The above is translated into x, y = x + 30, y + 30 // Can be used with any amount of vars, and with things such as *=, >>=, &=, .=, etc
Edited by Detective_Smith, 20 March 2016 - 02:22 PM.
0 members, 1 guests, 0 anonymous users