I'm writing a wrapper class around the V8 engine so that eventually I'll be able to do something like this
script->createClass("Test");
script->getClass("Test")->addFunction("funct1",testfunct1);
script->getClass("Test")->addVariable("x",setter,getter);
So far I can create classes and add functions to them and it works perfectly, however I have encountered a problem with adding variables.
My class template is stored as such
Persistent<Object> classInstance;
and I try to add an Accessor like this:
this->classInstance->SetAccessor(String::New(variableName),setter,getter);
Compiling this code gives me the error that v8::Object doesn't have a SetAccessor function (though I've seen doxygen documentation that says otherwise).
So my question is: How can I fix this? Is it possible to cast an Object to an ObjectTemplate?
SetAccessor on Object is available as of V8 2.2.12, which was released May 2010. (Before that, it was indeed only available on ObjectTemplate.) You should probably update your copy of V8.
Related
I developed some ANTLR + LLVM parser code in spring. Since it is only a recreational project, I did not touch the code or see whether it compiles in the meantime. During that time, several system updates took place, which I assume caused my current problems:
When trying to compile the code today (with clang++), I suddenly got several error messages. Initially the std::any class was not found at all. I then played with "std=c++17" and "std=c++20" options. Now the main error (as I understand it) seems to be
error: no member named 'as' in 'std::any'
The error occurs whenever i do something like for instance
args.push_back(visit(*it).as<sarg>());
or, more stripped-down:
antlrcpp::Any myvar;
//...
myvar.as<some_type>();
I picked this up from Antlr tutorial codes where this seems to be the standard idiom to cast an antlrcpp::Any object to the type desired by the calling function.
I noticed that antlrcpp::Any apparently is merely a wrapper for std::any, which apparently really does not support this "as" method.
What can i do to make my code work again?
I am using swig 4.0.2 to generate a package for tcl use.
The source .i file contains lots of classes and the generated _wrap.cpp file contains the all the classes with their methods as I would expect and everything compiles ok with no warnings.
However, for at least 1 class, when I come to call a method on a instance from a tcl script I get a runtime error saying the method does not exist. The error also dumps out all the available methods of the class. The method I am trying to call, along with a few others, does not exist in that list.
Invalid method. Must be one of: configure cget -acquire -disown -delete ...
There doesn't appear to be any pattern to which methods are not in the list though it is consistent which methods are missing.
The missing methods are scattered through the declared swig interface. ie they aren't at the beginning or end, nor all in one block. There is no pattern to their names nor function signature that I can see.
The function being run when the error occurs is SWIG_Tcl_MethodCommand: a function generated by swig. It is responsible for looking up the method by name and printing out the error code.
The function wrappers all exist and are referenced in the class's swig_method array.
I would have imagined that if a method was not going to be found by the look up it would be all or nothing.
Does anyone have ideas where I could look for errors?
I'm afraid I haven't been able to isolate into a small testcase that I can share.
I'm using swig 4.02, generating code for tcl8 and compiling under c++ 14.
The problem is caused by copy and paste code.
A second swig package exists in the Project I'm working on. It redeclares the same class interface but with some methods missing!
If I sync up the declarations then everything works.
This leaves the question of how the original code with unsynced swig interfaces (that was generated with swig1.0) ever worked.
I am trying to write custom function in bootstrapper.cc under v8/src/init.
int helloworld(){
return 0;
}
When it try to call it from chromium console, it throws undefined.
Look around bootstrapper.cc to see how other built-in functions are installed. Examples you could look at include Array and DataView (or any other, really).
There is no way to simply define a C++ function of a given name and have that show up in JavaScript. Instead, you have to define a property on the global object; and the function itself needs to have the right calling convention, and process its parameters / prepare its return value appropriately so that it can be called from JavaScript. You can't just take or return an int.
If you find it inconvenient to work with C++, an alternative might be to develop a Chrome extension, which would allow you to use JavaScript for the implementation, and also remove the need to compile/maintain/update your own build (which is a lot of work!). There is no existing guide for how to extend V8 in the way you're asking, because that approach is so much work that we don't recommend doing it like this (though of course it is possible -- you just have to read enough of the existing C++ source to understand how it's done).
I have a strange problem which appears in wxWidgets libraries and which can be reproduced easily in debugger. It does not seem to be wxWidgets-specific, so I'm asking this here.
I perform some kind of non-standard initialisation. During this initialisation a method wxAppBase::Initialize() is called. wxAppBase is the base class of my own App-class. Within wxAppBase::Initialize() an other method OnInitGui() is called, this method exists in wxAppBase as well as in my derived class.
And here is the problem: In Debug Build, everthing works well, OnInitGui() is executed as expected. But in Release-build I never reach OnInitGui() method but end up in a completely different one which does not have anything to do with OnInitGui(). So it seems an illegal jump is performed.
All pointers seem to be valid and this happens in wxWidgets library completely.
Anybody an idea what could cause such a behaviour and how one could fix this?
Every hint/idea/suggestion is welcome.
This looks like a bad build. Clean everything and rebuild both the library and your application using exactly the same compiler and compiler options and the problem will probably just disappear.
I am building a 3D Game Engine. I have build many in other languages, but finally decided to reap the speed benefits of C++ (despite not knowing it particularly well).
I have a class called EngineOptions that I use to store information about how the engine is to be initialized. The engine's main class, Monolith, then takes a const reference to the options instance like so:
monolith::EngineOptions options();
monolith::Monolith engine(options);
Monolith has a correct header file and a constructor like this:
Monolith::Monolith(const EngineOptions& options) : m_options(options)
{
m_window(m_options.windowWidth, m_options.windowHeight, m_options.windowTitle);
}
While I think this is correct, the compiler is complaining that there is:
no matching function for call to 'monolith::Monolith::Monolith(monolith::EngineOptions (&)())'
Excuse me if I'm being stupid, but I think this code is correct, am I wrong?
I am using the Code::Blocks IDE with the standard GCC toolchain provided on my system.
Remove the parentheses from this line:
monolith::EngineOptions options();
The compiler thinks you're declaring a function returning an EngineOptions instance.