MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 430 forks source link

Emulated Lua 5.3 shell requires "=" at the start. #1661

Closed SoniEx2 closed 6 years ago

SoniEx2 commented 8 years ago

Real Lua 5.3 shell doesn't require "=" at the start, it'll simply check for an expression.

setsunafseiei commented 8 years ago

Then just add =

gjgfuj commented 8 years ago

... The point is that it's meant to be compatible with the real shell, and it's not.

On Wed, 6 Apr 2016, 12:11 AM Setsuna F Seiei notifications@github.com wrote:

Then just add =

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/MightyPirates/OpenComputers/issues/1661#issuecomment-205827370

payonel commented 8 years ago

Thing is, I try to not make changes to OpenOS that are 5.2 or 5.3 specific. The only case we currently have is the bit32 lib that loads conditionally due to the machine _G environment providing the library conditionally based on the Lua version of the cpu. But the result of this effort is that both archs have bit32, it makes them common. Basically, you're asking a tool, in the OS, to behave differently when a different CPU is inserted.

I would be more in favor of not requiring = for either CPU.

EDIT In other words, we aren't emulating the 5.2 shell on a 5.2 CPU and the 5.3 on a 5.3 CPU, we're just emulating a Lua prompt in the /bin/lua script.

fnuecke commented 8 years ago

FWIW I'd be fine with making the = optional. I.e. make it work either way (have it replace = with return as before, if there's no = try running the input, if it fails, try running it again with return prefixed, if that also fails return first error).

Kubuxu commented 8 years ago

Running line two times is deep rabbit hole that you might not be willing to go as modification of global state could be performed two times.

SoniEx2 commented 8 years ago

Yes, you're supposed to check syntax errors returned by load().

SoniEx2 commented 8 years ago
if str:sub(1,1) == "=" then str = "return " .. str:sub(2) end
local chunk, err = load("return " .. str)
if not chunk then
  chunk, err = load(str)
end
if not chunk then
  -- check for multiline input
end
-- run chunk/print syntax errors/etc

see also #1662

fnuecke commented 8 years ago

Yeah, I should have said 'loading' instead of 'running', my bad.

payonel commented 6 years ago

we resolved this now