LuaSockets library will not correctly load - c

So, I've been annoyingly trying to work with LuaSockets2.0.2, and when I try to use it, I get the following error:
lua5.1: /media/pi/Cruzer/Lua/flywheels.lua:7: module 'luasocket.c' not found:
no field package.preload['luasocket.c']
no file './luasocket/c.lua'
no file '/usr/local/share/lua/5.1/luasocket/c.lua'
no file '/usr/local/share/lua/5.1/luasocket/c/init.lua'
no file '/usr/local/lib/lua/5.1/luasocket/c.lua'
no file '/usr/local/lib/lua/5.1/luasocket/c/init.lua'
no file '/usr/share/lua/5.1/luasocket/c.lua'
no file '/usr/share/lua/5.1/luasocket/c/init.lua'
no file './luasocket/c.so'
no file '/usr/local/lib/lua/5.1/luasocket/c.so'
no file '/usr/lib/arm-linux-gnueabihf/lua/5.1/luasocket/c.so'
no file '/usr/lib/lua/5.1/luasocket/c.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './luasocket.so'
no file '/usr/local/lib/lua/5.1/luasocket.so'
no file '/usr/lib/arm-linux-gnueabihf/lua/5.1/luasocket.so'
no file '/usr/lib/lua/5.1/luasocket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
/media/pi/Cruzer/Lua/flywheels.lua:7: in main chunk
[C]: ?
Running it with only Lua gives me the same problem. I read through the LuaSocket documentation, checked over my third-edition Lua book, and tried to do a handful of other things, but I didn't get any different results.
I'm trying to make something that will allow me to send a TCP message to an IP to first see if it's up, and second, see if it will send back data, as it's for an experiment/project thing I'm doing. I'm also using a Raspberry Pi 2+.
I understand that it says it's missing these Lua files. local socket = require("sockets") gives me a similar error, and trying require("socket") or require("sockets.lua") all still give me an error. Nothing currently appears to work, so what should I do?

Related

Writing in the executable while running the program

I'm writing a C program and I would like to be able to store data inside the executable file.
I tried making a function to write a single byte at the end of the file but it looks like it can't open the file because it reaches the printf and then gives "segmentation fault".
void writeByte(char c){
FILE *f;
f = fopen("game","wb");
if(f == 0)
printf("\nFile not found\n");
fseek(f,-1,SEEK_END);
fwrite(&c,1,sizeof(char),f);
fclose(f);
}
The file is in the correct directory and the name is correct. When I try to read the last byte instead of writing it works without problems.
Edit: I know I should abort the program instead of trying to write anyway but my main problem is that the program can't open the file despite being in the same directory.
There are several unrelated problems in your code and the problem you're trying to solve.
First you lack proper error handling. If any function that can fail (like e.g. fopen) fails, you should act accordingly. If, for example you did
#include <error.h>
#include <errno.h>
...
f = fopen("game","wb");
if ( f == NULL ) {
error(1,errno,"File could not be opened");
}
...
You would have recieved an useful error message like
./game: File could not be opened: Text file busy
You printed a message, which is not even correct (the file not beeing able to be opened is somthing different, than not beeing found) and continued the program which resulted in a segmentation fault because you dereferenced the NULL pointer stored in f after the failure of fopen.
Second As the message tells us (at least on my linux machine), the file is busy. That means, that my operating system does not allow me to open the executable I'm running in write mode. The answers to this question lists numerous source of the explanation of this error message. There might be ways to get around this and open a running executable in write mode, but I doubt this is easy and I doubt that this would solve your problem because:...
Third Executable files are stored in a special binary format (usually ELF on Linux). They are not designed to be manually modified. I don't know what happens if you just append data to it, but you could run into serious problems if your not very careful and know what you're doing.
If you just try to store data, use another plain and fresh file. If you're hoping to append code to an executable, you really should gather some background information about ELF files (e.g. from man elf) before continuing.

How can i fix on APL2 the generated error code AP211-10

A procedure on APL2 returns the error AP211-10 when it tries to execute a sentence VLIST. When it writes the file, it seems not to have enough space. Where do we have to change the parameter?
In the IBM doc AP211-10 means a problem in I/O file. And it seems related with the common error B37.
The expected result is the creation of the file correctly but actually the file created is corrupted and it is not possible to open on APL2.

Getting file-size property from Nautilus

I am hacking on Evince and trying to add a feature that shows the size of the file in the file-property page.
But I am unable to get the file-size value from Nautilus file info.
Does anybody how to get size-info of a file from Nautilus?
I can get it in terminal using ls -l and stat commands.
Assuming Evince uses GIO (I failed to find a way to quickly browse its code), you can use e.g. g_file_query_info() to get a GFileInfo pointer.
You can then use g_file_info_get_size() to get the size of the file.

How to read GET and POST data in C?

I'm running a web server. I'm using CGI, specifically C: I compile .c files into .out files, and then rename them to .cgi. I'm having quite some trouble reading GET and POST data: after dumping argv I noticed that GET data appears on either argv[25] or argv[26], quite randomly - I didn't check POST data.
So the question is, how can a C program read GET or POST data through CGI?
Use getenv
How to retrieve form "POST" data via cgi-bin program written in C
http://www.codingunit.com/c-reference-stdlib-h-function-getenv

Lua loadfile not finding a file

I had some lua code with the following line:
JSON = loadfile("JSON.lua")()
The file JSON.lua is in the same directory as the lua code that line came from. This code worked for me for a while, and then, without my changing either the lua source, or the JSON.lua, or permission of any of the files, or the directory from where I was running the lua code, I started getting a nil error on that line. (I simply recall NO relevant changes that could have any impact on the lua code.)
Adding an assert revealed that the error was caused by the file not being found. Playing with file permissions, restarting my machine didn't resolve the issue, and pulling back code that I had checked in and was working perfectly did not resolve the error.
I resolved the error by changing the line above to provide the absolute path to that JSON.lua file.
Is there anything explaining why the code without the absolute path could have worked for a while and then stopped working?
Note: This behavior of working and then not working happened to me twice over a week. I am puzzled and though I have now found a fix, I am really curious as to the explanation for that intermittent behavior.
Lua uses package.path, whose default value comes from the environment variable LUA_PATH if it is set, as the list of directories to search. You can put . of the front of this list to load files from the current directory, or you can put your files in a path on the list.
A late answer on this, as I found exactly the same problem.
First, contrary to the previous answer, loadfile doesn't use the package.path search path. It only looks in the specified directory. And if you don't specify a directory, it only look in the 'current directory'. I can't explain exactly why it stopped working for you, but probably your Lua code is somehow being run with a different 'current directory' than previous.
There are two possible fixes: One is to specify an absolute path to loadfile.
JSON = loadfile("c:\\my_folder\\JSON.lua")()
The alternative fix depends on the particular library you're using, which I suspect is Jeffrey Friedl's Lua JSON lilbrary. Because this supports the newer Lua module mechanism, you can just load the module with require, which does support the package.path search path.
JSON = require("JSON")

Resources