How to get C++ function names in hg diffs? - c++

I would like to get the C++ function names in a file. I tried do this with the command diff because I only need get the name of the function which is modified but I could not get it.
I know that with python files it is possible using git with the option 'git diff file.py'.
Is it possible do it with c++ files in Mercurial?

I think you are looking for the config option diff.showfunc. The doc (hg help config) says:
"showfunc"
Show which function each change is in.
It's working fine for Python functions and I think the heuristic should work similarly for C++ files. Maybe it will need functions body to be indented to correctly detect C++ functions.

Related

Ways to find where a function is defined on a github repo without having to do a manual search?

I've been looking at the pytorch repo. In particular, I'm trying to find where this function is defined: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/core/TensorBase.h#L505-L506
It's declared here in the header file but I can't seem to find where it's actually defined. Is there a quick way I can do this for a github repo?
You can search a lot of things without downloading the repo by using github search bar :
If you want full vscode search abilities, you can also use this marvelous project :
https://github1s.com/pytorch/pytorch
Edit #1: It have been brought to my attention, that you can have a similar effect by pressing the dot on you keyboard from -any- github repository directly ;) Enjoy !
Edit #2 : I also learnt that there is also this : https://gitpod.io/#{repository github url} that you can use to read and edit your own repo. Wow, the things we discover every days !
I don't think github has any such functionality and the search function often times doesn't work well for me.
However, depending on the specific case, there are some heuristic methods using the web interface that are quicker than scrolling through the search results.
For example in this case, have a look at the git blame for the line. The commit putting the declaration there should also have put the definition somewhere, usually.
In this case you will get this commit, which by a quick search on the page shows you that there is a macro for explicit specialization definitions of the function template in this file.
I also couldn't find a definition of the primary template with a quick look. Presumably the function is supposed to be explicitly specialized for all types it is used with.
The best way I know is to get a local copy with git clone and use git grep -n <fn_name> from the root of the directory (or wherever the source code is stored, either is fine). That will list all instances of the last argument and what file and line number it appears on, so it's typically pretty easy to tell which is the definition because it will have a { instead of a ; at the end.

Run Python script inside C++ with Python.h

I'm currently aware of this turotial, but I don't see anything in the tutorial that just simply runs a script. If I have a file pySolve.py how can I just call it to be executed inside of my code? No input is required as the C++ end generates all files needed before calling the python solve script.
You need to call PyRun_File or one of its variants. And of course first you must call Py_Initialize. You can see example usage of these functions in my open-source project here: https://github.com/jzwinck/pccl/blob/master/run.cpp

AngelScript, how to load a script file?

I know how I can bind C++ functions to AngelScript, but in my C++ code, how do I load an .as script file? How can I say in my C++ "Execute myscript.as now!" ?
In the AngelScript API I don't find any function like "LoadScript" or "ExecuteScript".
Or do I have to define a path somewhere from where AngelScript loads all scripts and I don't need to tell it the exact files?
Just found it out (in a small side sentence in the docs):
AngelScript doesn't provide a build in file loading. That's why there is no API function. So the manual loading is indeed the only way.
asIScriptModule::AddScriptSection will load a script string. asIScriptContext::Execute will execute a function from a script. The documentation was pretty clear about all of this; you might want to give it a look.

Using windows CopyFile function to copy all files with certain name format

Hello! I am updating some C code that copys files with a certain name. basically, I have a directory with a bunch of files named like so:
AAAAA.1.XYZ
AAAAA.2.ZYX
AAAAA.3.YZX
BBBBB.1.XYZ
BBBBB.2.ZYX
Now, In the old code, they just used a call to ShellExecute and used xcopy.exe. to get all the files starting with AAAAA, they just gave xcopy the name of the file as AAAAA.* and it knew to copy all of the files starting with AAAAA. now, im trying to get it to copy with out having to use the command line, and I am running into trouble. I was hoping CopyFile would be smart enough to handle AAAAA.* as the file to be copied, but it doesnt at all do what xcopy did. So, any Ideas on how to do this without the external call to xcopy.exe?
Check this out as a starting point
http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx
or even better this full example
http://msdn.microsoft.com/en-us/library/aa365200(v=VS.85).aspx
You could also use SHFileOperation or IFileOperation (the latter being only available from Vista upwards but is now the recommended way according to MSDN). SHFileOperation supports wildcards and displays a progress by default, but there's also a flag for silent operation.
Check out the following MSDN links for more info:
http://msdn.microsoft.com/en-us/library/bb762164(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb775771(v=VS.85).aspx
You would basically have to write code to reproduce the functionality in xcopy. To do so, you must build a list of files by accessing the path and recursing through it. Test each found entry with your pattern and keep only those that match. Then iterate over that list with CopyFile.
See the following set of functions that can help you build the file list:
http://en.wikipedia.org/wiki/Dirent.h
It might just be easier to keep using xcopy unless you have a specific reason not to.
There are lots of ways to do it. I'd probably use a loop of FindFirstFile() / FindNextFile().
However, is there any reason you can't still use xcopy? You can launch it with CreateProcess(). It isn't pretty, but it works.

Differing paths for lua script and app

My problem is that I'm having trouble specifying paths for Lua to look in.
For example, in my script I have a require("someScript") line that works perfectly (it is able to use functions from someScript when the script is run standalone.
However, when I run my app, the script fails. I believe this is because Lua is looking in a location relative to the application rather than relative to the script.
Hardcoding the entire path down to the drive isn't an option since people can download the game wherever they like so the highest I can go is the root folder for the game.
We have XML files to load in information on objects. In them, when we specify the script the object uses, we only have to do something like Content/Core/Scripts/someScript.lua where Content is in the same directory as Debug and the app is located inside Debug. If I try putting that (the Content/Core...) in Lua's package.path I get errors when I try to run the script standalone.
I'm really stuck, and am not sure how to solve this. Any help is appreciated. Thanks.
P.S. When I print out the default package.path in the app I see syntax like ;.\?.lua
in a sequence like...
;.\?.lua;c:...(long file path)\Debug\?.lua; I assume the ; means the end of the path, but I have no idea what the .\?.lua means. Any Lua file in the directory?
You can customize the way require loads modules by putting your own loader into the package.loaders table. See here:
http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders
If you want to be sure that things are nicely sandboxed, you'll probably want to remove all the default loaders and replace them with one that does exactly what you want and nothing more. (It will probably be somewhat similar to one of the existing ones, so you can use those as a guide.)