diff --git a/dst/QScript/Introduction.html b/dst/QScript/Introduction.html index 3741a1b..7f7f3ef 100644 --- a/dst/QScript/Introduction.html +++ b/dst/QScript/Introduction.html @@ -1,7 +1,7 @@ +
If you want to create a class, you first call the class() function like this:
class()
my_class = class() -- Creates a class creator +
my_class becomes a class creator. You can think of it like a bowl of ingredients which you can add to by simply setting the values of it.
my_class
my_class = class() -- Creates a class creator + +my_class.MyVar = 50.0 -- Creates a variable inside the class +function my_class.MyFunc(self,a) -- Creates a function inside the class + return self.MyVar+a +end +
Once you are done with defining your class, you call the finish() function like this:
finish()
finish(my_class) -- Finishes the class +
my_class will turn into a normal class where you cannot add any more variables or functions to it. In other words, my_class will get "baked" and you cannot add any more ingredients to it.
Next ->
Here is the real meat and potatoes of QScript. The import/export system allows you to share objects, functions and classes between scripts and other languages! The system is stupidly simple to understand.
Here is a simple code example:
function Add(a,b) + return a + b +end + +export(Add) +
That is it! Just put the global variable you want to export in the global scope (not inside another function) and the thing you want to export will get added to a special list which will contain all the exported elements from your file.
Exporting classes and objects works the same way.
my_class = class() + +finish(my_class) + +my_object = object(my_class) + +export(my_class) +export(my_object) +
<- Prev | +Next ->
Now that you have exported some variables, something's gotta import them! As always, it is very simple to do.
Let's say that you have made a file called "MyLib.lua" inside a mod called "MyMod". These are the contents of it:
-- MyMod/MyLib.lua +function add(a,b) + return a + b +end + +export(add) +
Now you want to import it inside another file. You call the import() function with the file name of the thing you want to import. It will return a table containing all the exported variables.
import()
MyLib = import("MyMod/MyLib.lua") -- Import the library + +MyLib.add(5,7) -- Will return 12 +
Importing works between other languages. So you don't need to worry about a library being written in a different language than you would like. (You could even use multiple languages in one project! Think about that!)
<- Prev
Objects store a number of variables and functions which are defined in the class the object comes from. They kind of act like tables but are not modifiable. Meaning, if you wanted to make a new variable or function inside an object, you would get an error.
Another thing that is different from tables is that you cannot change the type of the variables. Once they have been defined, that's it. You cannot change that variable to any other type which it originally was defined with.
To create a new object, simply call the object() function with a class, and it will return a new object based on the class you gave it.
object()
my_class = class() -- Start creating the class + +my_class.var = 10.0 -- Make a variable + +finish(my_class) -- Finish the class + +my_object = object(my_class) -- Make the object +