Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading files #83

Open
H2CO3 opened this issue Jun 15, 2017 · 10 comments
Open

Reading files #83

H2CO3 opened this issue Jun 15, 2017 · 10 comments

Comments

@H2CO3
Copy link

H2CO3 commented Jun 15, 2017

It does not appear to be possible to read files in any way. io.read doesn't exist, io.input doesn't exist, etc. Why? It's really annoying (also the fact that this is completely undocumented). loadfile, dofile, etc. don't work either, so they can't be used as a workaround (I want to read a config file). It's incredible that such a trivial task cannot be accomplished after several days of googling and trying to find any documentation on this issue -- without success.

@rvirding
Copy link
Owner

rvirding commented Jun 18, 2017

You are the first to ask for it. I will see what I can do.

Btw we do have loadfile and dofile. They are in the list of currently supported Lua library functions listed in README.

@H2CO3
Copy link
Author

H2CO3 commented Jun 19, 2017

Yes, I tried both loadfile and dofile, but neither of them work for some reason. Whether I specify a relative or absolute path, with or without the .lua extension, etc. they can't find the file for some reason. (The file has got only ASCII printable characters in its name, it's not a Unicode normalization issue either.)

@rvirding
Copy link
Owner

Could you give me an example?

@H2CO3
Copy link
Author

H2CO3 commented Jul 17, 2017

Sure, although I'm not sure how much additional information this provides, I'm afraid it's not too much. I'm using VerneMQ and I'm trying to read a configuration file like this:

return {
   db_engine              = "mysql",           -- mysql, postgresql, mongodb, redis, memcached
   pool_id                = "****",            -- whatever
   db_name                = "parashout",       -- database name
   msg_tbl_name           = "message",         -- table name in which messages are stored
   msg_id_col_name        = "id",              -- message primary key
   msg_type_col_name      = "type",            -- message type: text, image, seen
   msg_resend_id_col_name = "resend_id",       -- message resend ID
   msg_conv_id_col_name   = "conversation_id", -- ID of conversation message is sent to
   msg_sender_id_col_name = "sender_id",       -- user who sent the message
   msg_date_col_name      = "date",            -- date of sending
   msg_text_col_name      = "text",            -- if type == text, the text of the message, else NULL.
   msg_media_url_col_name = "media_url",       -- if type == zimage, the image URL, else NULL.
   host                   = "localhost",       -- DB connection host
   port                   = nil,               -- DB connection port
   username               = "verne",           -- DB connection username
   password               = "****",            -- DB connection password
}

In a VerneMQ plugin file, which is successfully run, I was trying to call:

local config = dofile("config.lua")

where config.lua is in the same directory as the plugin file.

This, however, failed: the VerneMQ error console said that dofile() can't find the file. Then I tried to specify the full path, like /home/verne/config.lua; this resulted in the same error. I have retried with loadfile() as well, with the same result.

@rvirding
Copy link
Owner

rvirding commented Jul 19, 2017

This is the first I have heard of VerneMQ at all and that it uses luerl. 😄 I will try to check and see what is happening.

One thing is that dofile by default loads from the current working directory of the running erlang so there is no guarantee that it will automatically find the file in same directory as the plugin. I can load your config.lua so it can manage the file as such. My last question is whether the path is correct?

Can you also send me the plugin? If I still can't make head or tails of the problem I will contact the VerneMQ people myself and ask for help.

@H2CO3
Copy link
Author

H2CO3 commented Jul 19, 2017

@rvirding Thanks for your reply! Yes, I figured that the current directory is something related to the environment, that's why I tried with the absolute path as well. I assume the path should have been correct, because it was one of the first things that popped in my mind, so I checked it many times with e.g. cat and ls, and those did report a file at that location.

I'll have to check with my manager whether I am allowed to post the plugin – it's for an internal company project. I'll get back to you once I know that.

@rvirding
Copy link
Owner

Hi, I am getting back into luerl now. Did you send me that plugin, I can't see it anywhere? How does VerneMQ use luerl?

@rvirding
Copy link
Owner

I tested this from the erlang shell putting the config in the file "v.lua" then doing

7> luerl:do("local local = dofile(\"v.lua\")", S0).

and it seemed to work.

@H2CO3
Copy link
Author

H2CO3 commented Mar 21, 2018

Hi, and thanks for getting back!

Unfortunately, the project has since been abandoned, and I no longer seem to be able to find the source for that plugin. 😞If it does (and is supposed to) work, then I can imagine it was only a problem with my setup…

Anyway, thanks for making luerl!

@micw
Copy link

micw commented Oct 5, 2020

Hello,
this issue was originally about reading files with io.read, which is still not implemented. Then discussion went to dofile and finally stopped. May I create a new one for io.read as feature request?

Kind regards,
Michael.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants