Tables? (for making a settings file)
#1
Posted 11 December 2017 - 06:15 PM
#2
Posted 11 December 2017 - 06:20 PM
More specifically, One can use textutils.serialise and textutils.unserialise to convert from a table to a string and back again. One can serialise a table, write it to a file to save settings. Then read a file and deserialise it to load settings.
#3
Posted 11 December 2017 - 06:29 PM
Quote
P. S. How to even create a table?
Edited by OrdinaryCassetteNerd, 11 December 2017 - 06:30 PM.
#4
Posted 11 December 2017 - 06:36 PM
OrdinaryCassetteNerd, on 11 December 2017 - 06:29 PM, said:
#5
Posted 11 December 2017 - 07:08 PM
#6
Posted 11 December 2017 - 07:45 PM
SquidDev, on 11 December 2017 - 06:36 PM, said:
To build on what SquidDev said, and to help you along in whatever project you end up choosing to do, I also suggest you read Lupus590's tutorial on making complex goals manageable.
And to give you an idea of the can of worms you're opening with trying to make an OS, take some time and read through BB's Guide to Coroutines - unless you can understand this, your 'OS' isn't going to be much of an OS as all.
As SquidDev said, you should really focus on simpler projects to start, then work your way up to writing something as complex as an 'OS'.
Edited by Dog, 11 December 2017 - 07:46 PM.
#7
Posted 11 December 2017 - 08:12 PM
#8
Posted 11 December 2017 - 08:22 PM
https://www.lua.org/pil/2.5.html
Edited by KingofGamesYami, 11 December 2017 - 08:22 PM.
#9
Posted 12 December 2017 - 05:35 PM
KingofGamesYami, on 11 December 2017 - 08:22 PM, said:
#10
Posted 12 December 2017 - 07:24 PM
OrdinaryCassetteNerd, on 12 December 2017 - 05:35 PM, said:
http://www.computerc..._World_Tutorial
#11
Posted 12 December 2017 - 08:26 PM
OrdinaryCassetteNerd, on 12 December 2017 - 05:35 PM, said:
Varargs, which are explained in this section of the manual.
Typically I will simply define tArgs:
local tArgs = {...}
...though in some cases I'll simply use them as-is, without a table.
#12
Posted 13 December 2017 - 12:48 AM
KingofGamesYami, on 12 December 2017 - 08:26 PM, said:
local tArgs = {...}
...though in some cases I'll simply use them as-is, without a table.
It's odd to me how everyone wraps varargs in a table, and names it exactly "tArgs", nothing else, almost universally. Is this some sort of unwritten rule of CC? I find this syntax much more intuitive:
local arg1, arg2, arg3 = ...
#13
Posted 13 December 2017 - 01:08 AM
Lignum, on 13 December 2017 - 12:48 AM, said:
local arg1, arg2, arg3 = ...
If I'm not mistaken, tArgs is shorthand for 'table of arguments'.
I can't tell you why others use a table, but I can tell you why I do. While capturing each argument in a separate variable might be easier in some instances, what do you do when you don't know how many arguments you are going to get? For me, regardless of count, putting them in a table makes it easier to manage since each arg is a separate table entry and they're numbered sequentially (and I don't have to type out arg1, arg2, arg3, arg4, etc. = ...).
Edited by Dog, 13 December 2017 - 01:12 AM.
#14
Posted 13 December 2017 - 01:11 AM
I'm pretty sure I picked up this habit from reading the source code.
Edited by KingofGamesYami, 13 December 2017 - 01:13 AM.
#15
Posted 13 December 2017 - 11:07 AM
Lignum, on 13 December 2017 - 12:48 AM, said:
It's more of a Lua rule than just CC, but I don't like hungerian notation and would use args as my variable name. Although, in languages where you don't delare types (like Lua), I see the usefulness of hungerian notation.
#16
Posted 13 December 2017 - 12:00 PM
KingofGamesYami, on 12 December 2017 - 08:26 PM, said:
OrdinaryCassetteNerd, on 12 December 2017 - 05:35 PM, said:
Varargs, which are explained in this section of the manual.
Er, not exactly. The auto-built "args" table is a feature of vararg functions, not some sort of "alternative". There is no equivalent: after Lua 5.1, you're simply expected to build that table yourself, if you want it.
The feature's still available in ComputerCraft, but many coders don't use it for whatever reason. Probably because they don't realise it's there. It's handy, though, in that it automatically includes an "n" key telling you exactly how many arguments were passed to the function - you don't have to request a count-up later.
#17
Posted 13 December 2017 - 12:03 PM
Bomb Bloke, on 13 December 2017 - 12:00 PM, said:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users