This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lebuildman's profile picture

How the Program "lua" Works

Started by lebuildman, 22 May 2014 - 06:15 PM
lebuildman #1
Posted 22 May 2014 - 08:15 PM
In a Folder, I have the "rom" folder from both CC 1.53 and 1.63

But I don't understand how the program "lua" works.
Can someone Help me? I'm planning a Lua Interpreter 2.0 using the Windows and Such, but The Code is REALLY HARD

Thx for Helping,
Buildman
flaghacker #2
Posted 22 May 2014 - 08:30 PM
In a Folder, I have the "rom" folder from both CC 1.53 and 1.63

But I don't understand how the program "lua" works.
Can someone Help me? I'm planning a Lua Interpreter 2.0 using the Windows and Such, but The Code is REALLY HARD

Thx for Helping,
Buildman

Try

edit /rom/programs/lua
CometWolf #3
Posted 22 May 2014 - 08:44 PM
Based on the wording of his post, im pretty sure he already has access to the code. However to be brunt, you should probably start with something easier if you don't understand it. The main points of interest here would be

pcall(), protected function call allowing you to catch and handle errors without your program crashing.

setfenv, changes the program environment. This is used to change the table where all the variables defined within the program are stored.

getfenv, gets the program environment.

setmetatable, this one is a big one, but in short here it's used with the __index metamethod. What this does is, if you look up a nil value within a table that has this as a metamethod, it will use this to attempt to look up the value elsewhere. This may be a function or another table. In this case it's the table returned by getfenv, meaning that it's probably _G. This prevents you from overwriting variables in _G while in the lua prompt, unless you specifically try do by doing _G.variable = whatever.