T O P I C R E V I E W |
jschultz |
Posted - Jul 01 2017 : 3:26:04 PM sol2 (https://github.com/ThePhD/sol2/) is a C++ wrapper for the Lua scripting language. The main wrapper object, sol::state, has an operator lua_State*() which returns a pointer to the underlying Lua handle. Most of the time, you would not want to operate on this raw handle, but use the functions provided by the wrapper. Suppose you have declared a sol::state lua; and now want to operate on this object (e.g. you want to write lua.set("foo", 1);).
If you have smart conversion from . to -> enabled, this will now kick in automatically. I understand that with other types such as smart pointers this is desirable, but in the case of the sol2 wrapper, it is much more likely that you do not want to use this operator explicitely here. Can an exception for this behaviour be added for sol2, or maybe some heuristics to figure out when it is sensible to apply this automatic conversion and when not? For example, I can imagine that the conversion could be disabled when the class you are working on has more than just a handful of public members. That way, smart pointers would still automatically convert from . to -> (since they have very few member functions), but sol::state would not trigger the conversion. |
11 L A T E S T R E P L I E S (Newest First) |
feline |
Posted - Jul 10 2017 : 1:45:04 PM The problem here is that VA is working as expected, and as the settings tell it to.
Normally va_stdafx.h is the method for adding the special case handling for the few classes that need to be handled differently. I just don't understand why this is not working in your solution, but it is working in a very simple test situation. |
jschultz |
Posted - Jul 10 2017 : 1:37:14 PM Since that would require editing the file everytime I am updating the library, I'd rather continue using Ctrl+Z or wait for a real fix. |
feline |
Posted - Jul 10 2017 : 1:29:36 PM I am seeing the same problem here with your solution, but I have no idea why. I have found one clue, in your solution, VA's HCB shows 3 base classes for "sol::state", specifically:
std.unique_ptr<lua_State> std._Unique_ptr_base<lua_State> sol.state_view
while in my test project, the HCB only shows one base class, "sol.state_view". The va_stdafx.h file is having the expected effect, but it seems as if an extra operator that I am not blocking is being picked up from somewhere.
Is editing the SOL library to comment out, or hide the problem operator an option for you? |
jschultz |
Posted - Jul 07 2017 : 4:46:53 PM I'm using the 2.18.0 release from the release page, but using the latest git commit shouldn't make a difference in this regard. Adding the other operator also didn't help.
Maybe it helps analyzing the problem inside my project environment; You can download the source from https://github.com/sagamusix/openmpt and then load build/vs2015/OpenMPT.sln (this is also the path I put the .h file into). You can just #include <sol/sol.hpp> in any .cpp file and then paste the example code there to trigger the issue, as far as I can see. |
feline |
Posted - Jul 07 2017 : 11:30:46 AM Strange, things are obviously working differently for you. This suggests we are using different versions of the library, or something similar. Let's try "guess the operator", does adding:
void operator->() const;
to your va_stdafx.h file, inside the state class, and rebuilding the symbol database have any effect? |
jschultz |
Posted - Jul 06 2017 : 10:00:38 PM Yes, I am getting the "banana" suggestion, but typing "lua." still turns it into "lua->".
(PS: The forum software's notification e-mails turns ">" into ">". That is probably not intended.) |
feline |
Posted - Jul 06 2017 : 07:39:09 AM Ah, that's interesting, there are two different "sol.hpp" files in this library. That I did not expect.
However, this still works the same for me. So, let's try something different. Can you please add a line to your va_stdafx.h file, so that it now reads:
namespace sol
{
class state
{
void operator*() const;
void banana() const;
}
} rebuild your VA symbol database, and then see if banana is shown in the listbox? You may need to set:
VA Options -> Enhanced Listboxes -> Source of C/C++ content: Default Intellisense
to check this. I am trying to find out if the va_stfafx.h file is being read as expected for you. Doing this here adds "banana" to the listbox. |
jschultz |
Posted - Jul 05 2017 : 3:56:27 PM quote: Originally posted by feline
Let's start with the basics. Which IDE and version of VA are you using?
VS2015, VA build 10.9.2223.0.
quote: Originally posted by feline
Which, if any, Sol directories have you added to your solution include directories?
The "single" subfolder, and I include sol as <sol/sol.hpp>. Modifying your test to include sol like that, I still get the . to -> conversion when inserting a dot before the semicolon.
quote: Originally posted by feline
Is it possible the correction is coming from the IDE, and not from VA? If so, this won't help, since the work around is only for VA.
No, turning off this specific option in VA also fixes the problem. |
feline |
Posted - Jul 05 2017 : 3:40:56 PM Let's start with the basics. Which IDE and version of VA are you using?
Which, if any, Sol directories have you added to your solution include directories?
I am testing with the very simple test case:
#include <sol.hpp>
void simpleSolLibraryTest()
{
sol::state lua;
lua;
} what do you get with this test?
Is it possible the correction is coming from the IDE, and not from VA? If so, this won't help, since the work around is only for VA. |
jschultz |
Posted - Jul 03 2017 : 6:51:28 PM Hm, I saved the file (with blank line at the end), rebuilt the symbol databases and restarted the IDE, but I'm still getting the auto-correction from . to ->. |
feline |
Posted - Jul 03 2017 : 10:03:11 AM I think I have a solution for this.
Can you please create a new text file called "va_stdafx.h" and place it in the same directory as your .SLN file. Now open this file and add the following code:
namespace sol
{
class state
{
void operator*() const;
}
}
making sure that the file ends with a blank line. There is no need to add this file to the solution, VA looks for this helper file automatically. Once you have saved the file, press the button:
VA Options -> Performance -> Rebuild symbol databases
and restart the IDE.
|
|
|