how to find a library that's being included in a lua application - linux

I'm kinda new to linux so you'll have to pardon my question if it's really basic. I have a code snippet that includes the following line:
require("axf.sf")
I am trying to find the file that contains this code.
I've tried the following commands on my server:
find / -name axf.sf
find / -name axf.sf*
But I can't locate it. I know the code exists because the program works.
any suggestions would be appreciated.

Lua, like many languages, has the concept of a "path" to search for required modules.
It can be configured by several means, but it's usually something like
./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua
(you can verify if your's is different by checking typing =package.path at a Lua prompt)
The default package searcher first takes the package name ("axf.sf" in your example) and replaces each dot with the OS's directory separator. ("axf/sf" in your example, since you're on Linux). Then it replaces the ? on each pattern with the transformed package name, and uses the first one that exists on your system.
so, it would search for
./axf/sf.lua
/usr/local/share/lua/5.1/axf/sf.lua
/usr/local/share/lua/5.1/axf/sf/init.lua
/usr/local/lib/lua/5.1/axf/sf.lua
/usr/local/lib/lua/5.1/axf/sf/init.lua
/usr/share/lua/5.1/axf/sf.lua
/usr/share/lua/5.1/axf/sf/init.lua

Related

How to resolve system directories paths independently of system locale?

TLDR
I need to get paths to system directories like "Screenshots":
On an English system. I can just use this one:
C:/Users/User/Pictures/Screenshots
How do I get the path to "Screenshots" directory on a non-English system?
C:/Users/User/Pictures/[NAME]
Description
I have a file manager app, it displays system directories and loads them on click.
The app can run system commands via Powershell and use Node.js (preferred)
Problem
The problem is, it only works if the system has English system language.
Currently, to resolve the "Screenshots" directory path, the app simply joins the User directory with the word "Screenshots"
const pictures = electronRemote.app.getPath('pictures')
const screenshots = PATH.join(pictures, 'Screenshots')
link to the line in code
Expectedly, the C:/Users/User/Screenshots path only exists on English systems.
One way to solve this is to use short names, at least on Windows, I know that system directories have short names like SCREEN~1 and WALLPA~1 for Screenshots and Wallpapers directories, but if I use these names the paths will look like this:
C:/Users/User/SCREEN~1 instead of C:/Users/User/Screenshots throughout the app.
And even if I were to run these paths through a function to convert it to readable name, how would I know which word to replace it with? I need to get the name in the system's language.
Are these translations stored somewhere on the system? Can I just retrieve the translated directory name and use that in the code above?
Question
How do I make it to get / resolve the actual path of system directories like Screenshots and Wallpapers, independently of system locale?
If you know how to do it, could you please suggest the solution for all platforms (Win, Mac, Linux)?
Should I just use the short names like SCREEN~1 and then automatically replace all the occurrences in UI and also filter all paths through a function that replaces this short name with the actual path throughout the whole app? Seems like a lot of work, this approach

Is this an error in the "path.normalize" documentation?

I've trying to figure out an issue with file paths using path and upath
(specific question: Issue saving to Windows "mapped network drive" in Electron)
Reading the documentation for path.normalize(path) it gives the following examples:
For example, on POSIX:
path.normalize('/foo/bar//baz/asdf/quux/..');
// Returns:
'/foo/bar/baz/asdf'
On Windows:
path.normalize('C:\temp\\foo\bar\..\');
// Returns: 'C:\temp\foo\'
In the first example, what happened to "quux"? And in the second, what happened to "bar"? Are these just copy-paste errors? Sorry if this seems a trivial question but this "path" stuff, particularly on Windows, is very confusing to me (I'm on macOS).
Like the doc says:
The path.normalize() method normalizes the given path, resolving '..' and '.' segments.
Try without the .. at the end, that is suggesting that you're going one directory up and is getting interpreted as basically
cd /foo/bar//baz/asdf/quux
cd ..
Also, this might be a mistake but you got two slashes between bar//baz in here.

How to create same path to directory on different platforms in Python?

In the piece of code I have, there are many instances where I have the following line
'/home/myname/directory'
For example, I have the following lines of code
filepath = os.listdir('/home/myname/directory')
for content in filepath
# do something
In the next part of the project, I have to share the code with some one else. I know this person runs openSUSE. If I want code to create that specific directory with the same path to the directory as mine, what do I need to include?
I know its going to involve the OS module but i am not sure which functions and methods to use.
Your code can check the existence of the directory and create it if not found:
if not os.path.exists("/home/myname/directory"):
os.makedirs("/home/myname/directory")
# do something

Reversing/Debugging - Identifying symlinks in applications

I was wondering, is there any guidlines for identifying symlink related function in an application binary?
Let's take BusyBox for example, /bin/ping is a symlink to /bin/BusyBox.
How can I know identify the ping related functions within the BusyBox binary?
Thanks in advance :)
You can't generally do that.
In case of BusyBox, it checks upon startup which commandline was invoked to execute the binary (including the path to the binary itself). It then calls functions that provide the functionality that was selected based on the basename of the binary / symlink.
Again in case of BusyBox, most of the times the funktion names are closely related to the command name. But this is basically just coincidence: it could well be that someone created an exectable "A" that would call a function "X" when started via a symlink name "B" and function "Y" when called as "C".

Getting echofunc.vim to work

I came across echofunc.vim today (from a link in SO). Since I'm rubbish at remembering the order of function parameters, it looked like a very useful tool for me.
But the documentation is a bit lean on installation! And I've not been able to find any supplementary resources on the internet.
I'm trying to get it running on a RHEL box. I've copied the script into ~/.vim/plugin/echofunc.vim however no prompt when I type in a function name followed by '('. I've tried adding
let g:EchoFuncLangsUsed = ["php","java","cpp"]
to my .vimrc - still no prompting.
I'm guessing it needs to read from a dictionary somewhere - although there is a file in /usr/share/vim/vim70/ftplugin/php.vim, this is the RH default and does not include an explicit function list.
I'm not too bothered about getting hints on the functions/methods I've defined - just trying to get hints for the built-in functions. I can see there is a dictionary file available here which appears to provide the resources required for echofunc.vim, I can't see how I set this up.
TIA,
It expects a tags file, the last line of the description describes exactly how to generate it:
ctags -R --fields=+lS .
It works here with PHP but not with JS. Your mileage may vary.
I didn't know about this plugin, thanks for the info.
You should try phpcomplete.vim, it shows a prototype of the current function in a scratchpad. It is PHP only, though.

Resources