![]() ![]() Now you should be ready to install and write your own libraries and make changes to the libraries of others. If it errors, make sure you try to `require` the right file and that it is in your `package.path`. Now, save the file and you are ready to require the file! In fact, you can try it out from the lua prompt. The whole file should now look like this: Now we only need to return the table we just created and we are done! The functions will get a number and need to call the respective function from the robot library that many times. Now we can install our functions into it! As said before, these functions wil have no error checking, this is left as an exercise to the reader. If you do, don't forget to localise your variables! So, lets create this table! I find it easiest to create this table beforehand, but you can also create it at the end. Now we get to the fun part.Īt the end of the file, we need to return a table which will hold all the functions. Your example: local hello 'hello' local function input() what kind of input end if input() hello then - fill in later end I attempt to assist over at r/OpenComputers and here. We can do this like you would do it in any other file, with `local robot = require 'robot'`. Look up Lua Tutorials, check out code samples, the usual. So open a file called a and we can start!įirst we need to require the robot api. So `movebot.forward(10)` will try to move the robot ten times. So, what will our library do? It will be a wrapper around the movement functions of the `robot` api, but it will move the robot multiple times. The library will not do propererror checking, that is left as an exercise to the reader. So, now you know how to load a library, but not how to write one, so that is what we are going to do now. So now require knows where to find your library! Then we get the following path: `/usr/local/lib/?.lua`. This needs to be followed by the `?.lua` to do the substitution with the name. First you need the path to the directory (`/usr/local/lib/`). First you need to make the path to the new folder recognisable to `require`. So you need to encode your new directory in the path. How do you tell `require` where it needs to look? This can be done by changing `package.path` to include the installation location of your new library. So, lets say you installed a library in `/usr/local/lib` and `require` can't seem to find it. This improves loading times and minimizes RAM usage! The vaule is stored so `require` does not have to load the same library twice. If it exists, it is executed and the return value is stored and returned to the caller. Then require tries all the paths and sees if the file exists. Each string between the ` ` is seen as a path and the name you provide is used to replace the `?`. The default value of `package.path` is `"/lib/?.lua /usr/lib/?.lua /home/lib/?.lua. You can open up a lua prompt and try to print it now. This is done by looking at the string in `package.path`. `require` needs the name of the library you want to load, but not the path to that file, so it needs to search the file system somehow. But what does `require` do? Where does it pull these libraries from? Is there another way to get the arguments as a table, or is this a bug MC: 1.10.2 OC: 1.6. In order to load a library, you can use the function `require`. How should I get the raw command line arguments to a lua program I am using a lua implementation of Argparse, and by default it uses the arg table, which doesnt appear to exist in OpenOS. In this tutorial, we are going to explain how the `require` function and the `package` library works. Delete it or let me know to shorten this.So, you want to know what this `require` thingy does? Or maybe you installed a library you can't load? You want to write your own library? Then we are here to help you. You can see its similar to OpenComputers, but instead ofĪlso the main reason why I wanted to do this to program a Microcontroller is to have a big reactor control program. With Arduino the coding is "simple" much like OpenComputers. Make special X Block and put EEPROM Into itĢ. ![]() (Not joking nor being Sarcastic) But it should be easily done with something likeġ. Now it looks like something a ten year old can do. I don't know Arduino much, but I assume that you can write Arduino programs with more high-level and easy-to-use libraries than a BIOS. The reason for that is that you're not programming an Arduino, you're programming a computer on its lowest level. Writing data to an EEPROM is not hard, it's writing a program in only 4 KB with only basic APIs that's difficult. Take out your EEPROM (and put the old one back in, otherwise your dev computer won't start)Ĭ("- your BIOS code here").Stick an empty EEPROM chip into your computer.If you ask me, writing to an EEPROM chip is not that hard: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |