Evaluate chaiscript file within a chaiscript file - chaiscript

I'm starting to learn chaiscript and couldn't find this in the documentation.
I know there is API to evaluate a chaiscript file from C++ by calling ChaiScript::eval_file
But is it possible to do the same from a chaiscript file?

From within ChaiScript the use function is available, but the eval_file is not. use only loads a file if it has not already been loaded. eval_file loads the file regardless.
use("use.inc")
assert_equal("hello", greet())
// Include it a second time and see if there are any errors
use("use.inc")
assert_equal("hello", greet())
From here: https://github.com/ChaiScript/ChaiScript/blob/master/unittests/use.chai
Documentation of the C++ implementation of this function is here: http://chaiscript.com/docs/5/classchaiscript_1_1_chai_script.html#a9fc2eaf37274d09d1ee90ffd411e665c
I don't see any documentation specifying that it's also exposed to the ChaiScript runtime, but you can see many of the functions that are exposed here: https://github.com/ChaiScript/ChaiScript/blob/master/include/chaiscript/language/chaiscript_engine.hpp#L318

Related

Bindgen: How to include all functions in some files but only certain functions in other files?

I have two folders that I want to create bindings for:
Include: - I need everything in this folder
Src: - I only need 3 functions (of many) from one file (of many)
All of the required files are included in wrapper.h.
I can create bindings for the correct functions in src by using:
bindings.allowlist_function("myfunc")
However this then means that bindgen only creates bindings for those functions explicitly mentioned. Not the other files in the wrapper.
Is there a way to create the bindings as I wish?
Note: This code is auto-generated so I can't simply move the function.
Furthermore, there are a lot of custom types that are required by these functions and the allowlist_function method brings all of those over automatically. So I need a way to mix allowlist and the files the wrapper.h. I can't manually transfer the functions over as these files change semi-frequently and I am trying to prevent issues in FFI mismatch that manual copying introduces.
**With further research: **
I have found that in Bindgens source code it shows an allowlist_file which suggests it would allow me to allowlist my wrapper and the specific functions.
if let Some(hidden_files) = matches.values_of("allowlist-file") {
for file in hidden_files {
builder = builder.allowlist_file(file);
}
This is included on the documentation at:
https://rust-lang.github.io/rust-bindgen/allowlisting.html
However, when you follow the links it is not in the builder docs and can't be found when running the code. I am confused as to whether this method really exists?

Linking to specific topics in HelpnDoc compiled CHM using Visual C++ HtmlHelp

I am confused here. I have migrated my CHM help from HtmlHelp Workshop to HelpNDoc. I compiled the CHM file and updated my MFC project to direct to the correct topic:
HtmlHelp((DWORD_PTR)_T("msa-options-publishers-db.html"), HH_DISPLAY_TOPIC);
The above approach worked with my previous CHM file. When I invoke this call the following happens:
It doesn't find it. Now I am having difficulties here because if I click F1 in my IDE (VS2017) it takes me to here. This article provides an example for showing a topic:
HWND hwnd =
HtmlHelp(
GetDesktopWindow(),
"c:\\Help.chm::/Intro.htm>Mainwin",
HH_DISPLAY_TOPIC,
NULL) ;
The above HtmlHelp API call is taking 4 parameters. Yet, in my CDialogEx derived class I only have two parameters:
So I need to find a way that will work to open any topic in my CHM file as compiled with HelpNDoc.
Update
On further research I located the topic that discusses the HtmlHelp API call that I am using (found in the CWinApp class). It states:
Parameters
dwData Specifies additional data. The value used depends on the value
of the nCmd parameter.
nCmd Specifies the type of help requested. For a list of possible
values and how they affect the dwData parameter, see the uCommand
parameter described in About the HTMLHelp API Function in the Windows
SDK.
So we end up here where we are given a link to details about HH_DISPLAY_TOPIC. We have gone full circle. Looking closely it states:
Specifies a compiled help (.chm) file, or a specific topic within a compiled help file.
To specify a defined window type, insert a greater-than (>) character followed by the name of the window type.
So my code should still be fine.
You won't believe how simple the resolution to this issue was!
I did a test with HTML Help Workship API window:
The only one that worked was when I used htm as the suffix and not html. See:

how to tell the run-time loader not to run the constructor function when dlopen a shared library

From the manual of dlopen, I see
" Instead, libraries should export routines using the attribute((constructor)) and attribute((destructor)) function attributes.
See the gcc info pages for information on these. Constructor routines are executed before dlopen() returns, and destructor routines are
executed before dlclose() returns.
"
I do not want the constructor in a specific shared library to run automatically, while the ones in other shared libraries are not affected. Is there any way to achieve that?
Actually, I'm using dlopen, dlsym, dladdr to find the exact path of some shared library.
I do not want the constructor in a specific shared library to run automatically
Too bad: the library author decided that his library can't be used safely unless the constructors are run, and he has more say than you do.
Actually, I'm using dlopen, dlsym, dladdr to find the exact path of some shared library.
Are you saying that the only reason you dlopen that library is just so that you can find the absolute path to it?
If so, why do you care about the absolute path in the first place?

How to get sqldb to use a particular fbclient.dll?

I'm using sqldb to connect to Firebird from within my DLL. This fails because it cannot find fbclient.dll which is actually present in the same directory as my DLL. GetCurrentDir returns the path to the Windows system folder. Performing a SetCurrentDir with the path of the DLL successfully changes the current directory, but still it won't work. What can I do to get sqldb to use fbclient.dll at a location of my choosing?
From the wiki page seems there is no way to explicitly specify the directory from where the Firebird client library could be loaded. So as a workaround you may use the SetDllDirectory function which will add a directory provided to its only parameter to the search path used to locate DLL libraries for the application. A subsequent call to LoadLibrary function used to load the Firebird's client library will go through the search list and find it in the location you added by the SetDllDirectory function call.

Failed to create shared library with wx and STL, "multiple definition" error?

I tried to build a shared library using wx and STL, and failed in an error of "multiple definition of". Please refer to:
https://code.google.com/p/gppanel/issues/detail?id=7
The declaration of wxPointListNode is not found in the sources. The suspicious lines are like these:
include/mathplot.h:85:WX_DECLARE_LIST(wxPoint, PointList);
include/mathplot.h:87:WX_DEFINE_LIST(PointList);
include/gpLineLayer.h:16:typedef std::deque<mpPointLayer*> mpPointList_t;
What the problem is?
Without the actual code this is just a guess, but I suspect that
include/mathplot.h:87:WX_DEFINE_LIST(PointList);
generates the full definition of PointList, including a non-templated method wxPointListNode::DeleteData. mathplot.h is included by all of the .cpp files (gpPanel.cpp, gpSeries.cpp, and baseData.cpp). Each cpp file is compiled into a .o file, so each has its own definition of DeleteData, and when you try to link the .o files together into lib/libgpPanel.so the linker issues the errors you're reporting.
The definition of the method needs to be in its own cpp file that's compiled and linked in.
All wxWidgets methods with DEFINE in their name expand into a definition of something and a definition can only be used once in a module, so it typically can't appear in a header file (unless you can guarantee that it's included by only a single source file). So just don't put it there.
Moreover, if this is your code, you should avoid using the legacy WX_DECLARE_LIST macro at all and just use std::list<> or std::vector<> instead. Or, if you really want to use only wx (which can only be important if you are targeting some embedded platform without good STL implementation), then use wxVector<>.