New to Lua, confused by error <eof> - lua

I recently started taking an interest in Lua programming with a Minecraft addon called Computercraft, which involves console-based GUIs to control computers and other things with Lua. However, I seem to be randomly getting an error where the code requires something called an "eof". I have searched multiple manuals and how-tos, and none mention this particular error. In fact, I am having trouble finding anything with an error list. I am fairly new to programming, but have had basic Python experience. Could anyone explain what "eof" is?

An eof is do or then.
Usually eof means you have too many (or not enough) end statements. Paste code maybe?

Suppose I create a file with one too many end statements:
> edit test.lua
for i = 1, 10 do
print(i)
end
end
When I run it, and lua encounters that extra end statement on the last line where there is no code block still open, you'll get an error like:
> test.lua
bios: 337: [string "test.lua"]: 4: '<eof>' expected
(from a quick test in CCDesk pr7.1.1)
Problems with the basic structure of the blocks of lua code show up with bios on the left rather than your file name; the part of bios that loads lua files will usually tell you where it was at in the file when couldn't make sense of the code anymore (like line 4: here). Sometimes it might be a bit of a puzzle to work your way from the scene of the accident back to where things got off track. =)

Using ESPlorer there is a difference between "uploading" a script and "sending" a script. Use "Upload".
This is not the same issue as the one reported, but as searching landed me here...

Related

How to deobfuscate this?

I obfuscated this script using some site
But i'm wondering how to deobfuscate it? can someone help me?
i tried using most decompilers and a lot of ways but none has worked
local howtoDEOBFUSCATEthis_Illll='2d2d341be85c64062f4287f90df25edffd08ec003b5d9491e1db542a356f64a488a1015c2a6b6d4596f2fa74fd602d30b0ecb05f4d768cd9b54d8463b39729eb1fe84630c0f8983f1a0087681fe4f2b322450ce07b
something like that for an example.
the whole script: https://pastebin.com/raw/fDGKYrH7
First reformat into a sane layout. a newline before every local and end will do a lot. Then indenting the functions that become visible is pretty easy.
After that use search replace to inline constants. For example: local howtoDEOBFUSCATEthis_IlIlIIlIlIlI=8480; means you can replace every howtoDEOBFUSCATEthis_IlIlIIlIlIlI with 8480. Though be careful about assignments to it. If there are any then it's better to rename the variable something sensible.
If an identifier has no match you can delete the statement.
Eventually you get to functions that are actually used.
Looking at the code it seems to be an interpreter implementation. I believe it's a lua interpreter
Which means that you'll need to verify that and decompile what the interpreter executes.

Lua: run code while waiting for input

I'm currently working on a lua program.
I want to use it in Minecraft with a mod called "OpenComputers" which allows the use of lua scripts on emulated systems.
The programm I'm working on is relatively simple: you have a console and you enter a command to control a machine.
It looks like this:
while(true) do
io.write("Enter command\n>")
cmd = io.read()
-- running code to process the command
end
But the problem is: I need a routine running in the background which checks data given by the machine.
while(true) do
-- checking and reacting
end
How can I make this work?
I can't jump to a coroutine while waiting on io.read()
It's not enough to check after someone used a command (sometimes I don't use it for days but I still have to keep an eye on it)
I'm relatively new to lua so please try to give a simple solution and - if possible - one that does not rely on third party tools.
Thank you :)
If you have some experience with opencomputers, you can add a(n asynchronous) listener for "key_down", and store the user input in a string (or whatever you want).
For example:
local userstr = ""
function keyPressed(event_name, player_uuid, ascii)
local c = string.char(ascii)
if c=='\n' then
print(userstr)
userstr = ""
else
userstr=userstr..c
end
--stores keys typed by user and prints them as a string when you press enter
end
event.register("key_down", keyPressed)
Running multiple tasks is a very broad problem solved by the operating system, not something as simple as Lua interpreter. It is solved on a level much deeper than io.read and deals with troubles numerous enough to fill a couple of books. For lua vm instead of physical computer, it may be simpler but it would still need delving deep into how the letters of code are turned into operations performed by the computer.
That mod of yours seems to already emulate os functionality for you: 1,2. I believe you'll be better off by making use of the provided functionality.

How to call a function from a lua file of a c++/lua project on interactive terminal?

I'm reading some source codes of a project, which is a combination of c++ and lua, they are interwined through luabind.
There is a la.lua file, in which there is a function exec(arg). The lua file also uses functions/variables from other lua file, so it has statements as below in the beginning
module(..., package.seeall);
print("Loading "..debug.getinfo(1).source.."...")
require "client_config"
now I want to run la.exec() from interactive terminal(on linux), but I get errors like
attempt to index global 'lg' (a nil value)
if I want to import la.lua, I get
require "la"
Loading #./la.lua...
./la.lua:68: attempt to index global 'ld' (a nil value)
stack traceback:
./lg.lua:68: in main chunk
[C]: in function 'require'
stdin:1: in main chunk
[C]: ?
what can I do?
Well, what could be going wrong?
(Really general guesswork following, there's not much information in what you provided…)
One option is that you're missing dependencies because the files don't properly require all the things they depend on. (If A depends on & requires B and then C, and C depends on B but doesn't require it because it's implicitly loaded by A, directly loading C will fail.) So if you throw some hours at tracking down & fixing dependencies, things might suddenly work.
(However, depending on how the modules are written this may be impossible without a lot of restructuring. As an example, unless you set package.loaded["foo"] to foo's module table in foo before loading submdules, those submodules cannot require"foo". (Luckily, module does that, in newer code without module that's often forgotten – and then you'll get an endless loop (until the stack overflows) of foo loading other modules which load foo which loads other modules which …) Further, while "fixing" things so they load in the interpreter you might accidentally break the load order used by the program/library under normal operation which you won't notice until you try to run that one normally again. So it may simply cost too much time to fix dependencies. You might still be able to track down enough to construct a long lua -lfoo-lbar… one-off dependency list which might get things to run, but don't depend on it.)
Another option is that there are missing parts provided by C(++) modules. If these are written in the style of a Lua library (i.e. they have luaopen_FOO), they might load in the interpreter. (IIRC that's unlikely for C++ because it expects the main program to be C++-aware but lua is (usually? always?) plain C.) It's also possible that these modules don't work that way and need to be loaded in some other way. Yet another possibility might be that the main program pre-defines things in the Lua state(s) that it creates, which means that there is no module that you could load to get those things.
While there are some more variations on the above, these should be all of the general categories. If you suspect that your problem is the first one (merely missing dependency information), maybe throw some more time at this as you have a pretty good chance of getting it to work. If you suspect it's one of the latter two, there's a very high chance that you won't get it to work (at least not directly).
You might be able to side-step that problem by patching the program to open up a REPL and then do whatever it is you want to do from there. (The simplest way to do that is to call debug.debug(). It's really limited (no multiline, no implicit return, crappy error information), but if you need/want something better, something that behaves very much like the normal Lua REPL can be written in ~30 lines or so of Lua.)

How to run a set of TWEANN benchmarks in Erlang correctly?

I've been reading Gene I Sher's Handbook to neuroevolution through Erlang and trying to replicate all the experiments described there.
And it all worked, until I came to chapter 19, which read
Having set everything up, we execute the benchmark for every noted experimental setup, and run it to completion. To do this, we simply modify the constraints used in our benchmarker module, and then execute benchmarker:start(Experiment_Name), for every of our experimental setups.
There are 14 experiments altogether, named:
1. [SlidingWindow5]2. [SlidingWindow10]3. [SlidingWindow20] 4. [SlidingWindow50]5. [SlidingWindow100]
and
1. [ChartPlane5X10]2. [ChartPlane5X20]3. [ChartPlane10X10]4. [ChartPlane10X20]5. [ChartPlane20X10]6. [ChartPlane20X20]7. [ChartPlane50X10]8. [ChartPlane50X20]9. [ChartPlane100x10]
Just starting a polis and running benchmarker:start(SlidingWindow5). in an erlang shell results in * 1: variable 'SlidingWindow5' is unbound.
I'm probably being obtuse and not doing something obvious, but I really wish to understand which arguments to pass to the benchmarker:start().
Reading the source code didn't help so far.
I think that reading the whole book is not necessary to figure out how to make this particular piece of code work.
All right. I needed to use an all-lowercase name: benchmarker:start(slidingwindow5)..
This answer is correct, but inconclusive; it gives the solution but does not explain why the solution is as it is from an Erlang perspective. Please don't upvote it until it does.

In rails.vim why do I get "E345 can't find file in path" errors?

I've been learning Ruby/Rails with vim. Tim Pope's rails.vim seems like a really good tool to traverse files with, but I keep getting these pesky "E345 can't find file in path" errors. I'm not vim expert yet, so the solution isn't obvious. Additionally, I've tried this and it doesn't apply to my problem.
As an example of the problem. I have a method format_name defined in app/helpers/application_helper.rb and it is used in app/helpers/messages_helper.rb. Within the latter file I put my cursor over the usage of format_name and then hit gf and I get that error. Similar disfunction with commands like ]f and [f
However, it works sometimes. I was able to gf from user to the app/models/user.rb
Ideas?
I think that is a limitation of rails.vim. It does not support “finding” bare methods. Supporting something like that would require one of the following:
an exhaustive search of all the source files for each “find” request
(which could be expensive with large projects),
“dumb” indexing of method names
(e.g. Exuberant Ctags and gControl-]; see :help g_CTRL-]), or
smart enough parsing of the code to make a good guess where the method might be defined
(which is hard to do properly).
If you know where the method is, you can extend many of the navigation commands with a method name:
:Rhelper application#format_name
But, you do not have to type all of that in. Assuming the cursor is on format_name you can probably just type:RhTabspaceappTab#Control-R Control-W (see :help c_CTRL-R_CTRL-W).

Resources