-
Notifications
You must be signed in to change notification settings - Fork 0
Lua
Rust is not an easy language,
for that reason Yrnu acts as a compiler for the Lua programing language,
allowing you to use the Yrnu Rust crate using Lua binding to the functions and structures in the crate.
Lua is a lightweight, high-level programming language created for embedded use in applications.
Known for its simplicity and efficiency.
To be able to write Lua scripts that runs using Yrnu you first need to know Lua.
if you don't intended to use the scripting feature, skip to the CLI section.
In this section you would learn the basics of the Lua programing language as fast as possible,
if you already know the basics of Lua you can skip to the next page.
In Lua you can define a variable in by writing his name equals followed by a value.
zero = 0this way of defining a variable makes the variable global, to define a local variable to a specific scope
use the local keyword before the variable name.
local name = "value"this variable would not be accessible from outside of the scope that he was defined there,
if the local keyword is used out side of any scope it would be visible only in the current file.
There are 6 key types in Lua
stringnumberbooleannilfunctiontable
for now we would only look on the first 4 of them, here is an example of defining each of the types:
local name = "john" -- string
local description = [[
this is a short description
about john.
how cool is that!
]] -- multi-line string
local age = 27 -- number (no different between int and float)
local is_cool = true -- boolean (true/false)
local pet_name = nil -- nil a.k.a None or null in other languagesto convert from one type to another we can use the functions that been provided by the standard library.
for example to try to convert a text into a number we would use the tonumber function
age = tonumber("31")
print(type(age)) -- numberwe can also convert a string to a number implicitly like so:
sum = "14.5" + 10 -- 14.5 converts to a number implicitly
print(sum) -- 24.5similarly we can use the tostring function to convert other types into a string
age = tostring(31)
print(type(age)) -- stringTo get user input we can use the Lua io module and call the read function
local name = io.read()