Changes

Jump to navigation Jump to search
648 bytes added ,  18:24, 23 October 2016
→‎open(): Add examples
Line 150: Line 150:  
|param2 = mode
 
|param2 = mode
 
|param2text = Optional mode parameter. See the table below. Defaults to "rb".
 
|param2text = Optional mode parameter. See the table below. Defaults to "rb".
|example1 =  
+
|example1text = Note that the below example must be run first for the others to work.
 +
|example1 = var path = getprop("/sim/fg-home") ~ '/Export/demo.txt';
 +
var file = io.open(path, "w"); # open in write mode
 +
var text = 'Hello, World!' ~ "\r";
 +
io.write(file, text);
 +
io.close(file);
 +
|example2 = var path = getprop("/sim/fg-home") ~ '/Export/demo.txt';
 +
var file = io.open(path, "r"); # open in read mode
 +
print(io.readln(file)); # prints "Hello, World!"
 +
io.close(file);
 +
|example3 = var path = getprop("/sim/fg-home") ~ '/Export/demo.txt';
 +
var file = io.open(path, "a"); # open in append mode
 +
var text = "\n" ~ 'This is line 2';
 +
io.write(file, text);
 +
io.close(file);
 
}}
 
}}
  

Navigation menu