Jump to content


Bomb Bloke

Member Since 25 May 2013
Offline Last Active Yesterday, 12:53 PM
*****

Posts I've Made

In Topic: Weird program error on reboot

Yesterday, 07:07 AM

Remember that scripts execute from top to bottom. When you initially run your script on boot, the first thing it tries to do is build your ACTIONS table: but none of the variables you're trying to copy into it contain anything yet, so you "fill" the table with a bunch of nils.

Your script then proceeds to define all of your functions into the global scope, where they remain even when your script terminates. This is why re-running your script then allows you to assign some actual data into the ACTIONS table - the global scope only clears when you reboot your computer.

Note that in later versions of ComputerCraft, the global scope is cleared when a script ends. Generally you should be localising everything you can.

Edit:

It may also help to know that Lua always assigns by value, never by reference. Confusingly, when you attempt to assign a function/table/coroutine you end up assigning a pointer value leading to the relevant area in memory, but working with that pointer value in the variable is not the same as being able to use a variable as a reference.

In Topic: Overriding fs functionality

22 May 2019 - 04:39 PM

View PostMrObsidy, on 22 May 2019 - 03:29 PM, said:

To do this I override every single function in fs to prefix the root directory.

Just glancing through the fs API, this looks like it'll at least break fs.combine() and fs.complete().

It's very difficult to comment on your issue without seeing the relevant lines in OneOS in addition to your own code.

In Topic: Endless nan errors in calculator program (+ WarpDrive Integration)

22 May 2019 - 07:58 AM

View PostSquidDev, on 18 May 2019 - 06:39 AM, said:

Tables are compared by reference, which means that tables with the same entries aren't always equal.

To clarify, the values you're comparing are your table pointers, as opposed to what's in your tables (their contents). Unless you compare a table pointer to itself you won't ever find an "equal match" that way; whether your tables contain the "same entries" isn't at all relevant.

A primitive but simple example of a check that looks at table contents might look like this:

local function compareTables(table1, table2)
  for i = 1, #table1 do
    if table1[i] ~= table2[i] then return false end
  end

  return true
end

if compareTables(disp, {0, 0, 0}) then ...

It'd be helpful to know what values you're actually expecting to get out of your script. Providing example input alongside the "correct" output would make it a lot easier to figure out which alterations need to be made.

In Topic: Disknet: "Modem" communications through a disk drive!

03 May 2019 - 07:09 AM

 SquidDev, on 02 May 2019 - 03:07 PM, said:

I realise this is the only way to do it

Is it really? I mean, even regular modem messages don't arrive until the next server tick. Obviously this can go faster, but does it need to?

In Topic: Are tables passed by reference or by value?

26 April 2019 - 08:25 AM

View PostMrObsidy, on 24 April 2019 - 06:17 PM, said:

EDIT: By testing, I found out that Lua indeed is pass-by-reference (the above code outputs "bar".)

Just to make sure you're clear on this, Lua always passes values.

When you attempt to assign a table (or function, or coroutine...) to a variable, you actually end up assigning a pointer to it instead - which you can see if you try printing the variable's contents. Copying such values means that you then have multiple pointers leading to the one memory object: you can't actually pass copies of tables themselves because you never actually assign tables in the first place.