I want to set a Handle<Value> of an array. I'm a beginner to v8 and i can't found how to set it
when I do for example:
Persistent<Context> fcontext
Handle<Value> Arr = Array::New(0);
Persistent<Function> Func;
Handle<Value> result = Func->Call(fcontext->Global(), 0, Arr);
I receive this error:
error C2664: 'v8::Function::Call' : cannot convert parameter 3 from 'v8::Handle<T>' to 'v8::Handle<T> []'
1> with
1> [
1> T=v8::Value
1> ]
How do I make a Handle<Value> of an array with 1 element ?
const unsigned argc = 1;
Local<Value> argv[argc] = { Local<Value>::New(String::New("Hello World!")) };
func->Call(Context::GetCurrent()->Global(), argc, argv);
More examples:
http://izs.me/v8-docs/examples.html
http://nodejs.org/api/addons.html
Related
I'm capturing data in a boost::circular_buffer and would like to now perform a regex search on the contents but I'm having some difficulty getting boost::regex to understand how to look at the buffer.
Here's a stripped down version of the sort of thing I'd like to do based on the example here:
// Set up a pre-populated data buffer as an example
std::string test = "Fli<usefuldata>bble";
boost::circular_buffer<char> dataBuff;
for (std::string::iterator it = test.begin(); it != test.end(); ++it)
{
dataBuff.push_back(*it);
}
// Set up the regex
static const boost::regex e("<\\w*>");
std::string::const_iterator start, end;
start = dataBuff.begin(); // <-- error C2679
end = dataBuff.end();
boost::match_flag_type flags = boost::match_default;
// Try and find something of interest in the buffer
boost::match_results<std::string::const_iterator> what;
if (regex_search(start, end, what, e, flags))
{
// Do something - we found what we're after...
}
I (quite understandably I think) get this error when I try to compile:
1>c:\projects\ProtocolBufferProcessor\ProtocolBufferProcessor.h(53): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'boost::cb_details::iterator<Buff,Traits>' (or there is no acceptable conversion)
1> with
1> [
1> Buff=boost::circular_buffer<char>,
1> Traits=boost::cb_details::nonconst_traits<std::allocator<char>>
1> ]
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xstring(435): could be 'std::_String_iterator<_Elem,_Traits,_Alloc> &std::_String_iterator<_Elem,_Traits,_Alloc>::operator =(const std::_String_iterator<_Elem,_Traits,_Alloc> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::_String_iterator<_Elem,_Traits,_Alloc>, boost::cb_details::iterator<Buff,Traits>)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> and
1> [
1> Buff=boost::circular_buffer<char>,
1> Traits=boost::cb_details::nonconst_traits<std::allocator<char>>
1> ]
...but is there anything I can do other than create a std::string character by character from the circular buffer each time I run the regex?
I'm using Boost v1.54 if that makes a difference.
you need to use the buffer's iterator type:
Live On Coliru
#include <boost/circular_buffer.hpp>
#include <boost/regex.hpp>
using buffer_t = boost::circular_buffer<char>;
int main() {
// Set up a pre-populated data buffer as an example
std::string test = "Fli<usefuldata>bble";
buffer_t dataBuff;
for (std::string::iterator it = test.begin(); it != test.end(); ++it)
{
dataBuff.push_back(*it);
}
// Set up the regex
static const boost::regex e("<\\w*>");
buffer_t::const_iterator start = dataBuff.begin(); // <-- error C2679
buffer_t::const_iterator end = dataBuff.end();
boost::match_flag_type flags = boost::match_default;
// Try and find something of interest in the buffer
boost::match_results<buffer_t::const_iterator> what;
if (regex_search(start, end, what, e, flags))
{
// Do something - we found what we're after...
}
}
I've extracted the sections of my code to show what I believe is causing the error.
typedef unordered_multimap<string , ItemPtr > StringToItemMultiMap;
void Library::multiMapItemWithKeys ( StringToItemMultiMap * map , ItemPtr itemPtr , StringSet keySet )
{
StringSet::iterator it;
for ( it = keySet.begin ( ); it != keySet.end ( ); ++it )
{
pair< string , ItemPtr > aPair ( *it , itemPtr );
map->insert ( aPair );
}
}
I have this operator overload:
bool operator<(const ItemPtr & ip1, const ItemPtr & ip2)
{
bool result;
if ( ip1.getPtr ( )->getTitle ( ).compare ( ip2.getPtr ( )->getTitle ( ) ) < 0 )
result = true;
else
result = false;
return result;
}
This is a typical error:
1>------ Build started: Project: asgmt04, Configuration: Debug Win32 ------
1> Library.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xhash(672): error C2675: unary '++' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\unordered_map(632) : see reference to function template instantiation 'void std::_Hash<std::_Umap_traits<_Kty,_Ty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,true>>::insert<_Iter>(_Iter,_Iter)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=ItemPtr
1> , _Hasher=std::hash<CustomType>
1> , _Keyeq=std::equal_to<CustomType>
1> , _Alloc=std::allocator<std::pair<const std::string,ItemPtr>>
1> , _Iter=std::string
1> ]
Anyone know what is going on?
I can not make a call to a method of a class from another class :rewrite the code cocos2d (objective-c) on cocos2d-x (c++)
Error:
c:\program files\microsoft visual studio 11.0\vc\include\xrefwrap(273): error C2562: std::_Pmd_caller<_Ret,_Arg0>::_Call_pmd: функция типа "void", возвращающая значение
1> with
1> [
1> _Ret=void,
1> _Arg0=cocos2d::Object
1> ]
1> c:\program files\microsoft visual studio 11.0\vc\include\xrefwrap(271): см. объявление "std::_Pmd_caller<_Ret,_Arg0>::_Call_pmd"
1> with
1> [
1> _Ret=void,
1> _Arg0=cocos2d::Object
1> ]
Not become fully kidat.Tam 20 more lines of the same
HudLayer.cpp
CCMenuItem *button = CCMenuItemImage::create("1.png","1.png",menu_selector(HelloWorld::createSprite));
HelloWorld.cpp
void HelloWorld::createSprite(CCObject *sender)
{
_sprite->initWithFile("bird.png");
_sprite->setPosition(ccp(x,y));
}
In the IronMan.h you have to declare
static void playClicked();
In the Avenger.cpp you can use this method
CCSize *screenSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint pointOrigin = CCDirector::sharedDirector()->getVisibleOrigin();
float x = screenSize.width;
float y = screenSize.height;*
CCWidgetLayout* widgetLayout = CCWidgetLayout::create();
addChild(widgetLayout);
CCButton* playButton = CCButton::create("btn1.png", "btn2.png", "btn3.png");
playButton->setPosition(x/1.2f,y/1.5f);
playButton->setClickSelector(this,click_selector(IronMan::playClicked));
widgetLayout->addChild(playButton,1);
You should do like this..
CCMenuItem *button = CCMenuItemImage::create("1.png","1.png",menu_selector(HudLayer::createSpriteMethod));
void HudLayer::createSpriteMethod(CCObject *sender)
{
_helloWorld//assuming you have instance of HelloWorld
_helloWorld->createSprite(sender);
}
for HelloWorld::createSprite.....it should be static method.,nothing good comes from it.
In the following protocol buffer, how does one access the repeated fields in the extension from C++?
base.proto
message Base {
optional int32 id = 1;
repeated int32 ids = 2;
optional string name = 3;
repeated string names = 4;
extensions 1000 to 1999;
}
ext.proto
import "base.proto";
extend Base {
repeated string names = 1000;
optional int32 number = 1001;
repeated int32 numbers = 1002;
optional string name = 1003;
}
The following doesn't compile (in VS2010)
#include "base.pb.h"
#include "ext.pb.h"
using namespace ::google::protobuf;
int main(int argc, char *argv[])
{
Base b;
RepeatedPtrField<std::string> base_names = b.names(); // OK
RepeatedField<int> base_ids = b.ids(); // OK
int ext_number = b.GetExtension(number); // OK
std::string ext_name = b.GetExtension(name); // OK
assert( b.HasExtension(numbers) ); // OK
assert( b.HasExtension(names) ); // OK
int32 i = b.GetExtension(numbers); // ? Compiles but doesn't make sense.
RepeatedField<int32> ext_numbers = b.GetExtension(numbers); // compilation fails:
RepeatedPtrField<std::string> ext_names = b.GetExtension(names); // compilation fails:
return 0;
}
Compilation errors
1>test_proto.cpp(17): error C2440: 'initializing' : cannot convert from 'int' to 'google::protobuf::RepeatedField<Element>'
1> with
1> [
1> Element=google::protobuf::int32
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>\test_proto.cpp(18): error C2440: 'initializing' : cannot convert from 'const std::string' to 'google::protobuf::RepeatedPtrField<Element>'
1> with
1> [
1> Element=std::string
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
Thanks to Feng Xiao on the protobuf mailing list, use ExtensionSize(id) and GetExtension(id, index):
Base b;
int index = 0;
if (index < b.ExtensionSize(names))
{
std::string s_value = b.GetExtension(names, index);
}
I am using the MArgList class from the Maya API to retrieve arguments entered in the Maya command line. According to the class reference MArgList::get should be able to take an int or double as its second argument but it seems to be expecting a bool only and so throws a conversion error during compiling. The following is the code section and the errors generated. Any thoughts on what might be causing this would be much appreciated. The code was typed straight out of a tutorial on Maya plugin development, so it is a mystery why it is not working.
const int nPosts = 5;
const double radius = 0.5;
const double height = 5.0;
unsigned index;
index = args.flagIndex( "n", "number" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, nPosts );
unsigned index;
index = args.flagIndex( "r", "radius" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, radius );
unsigned index;
index = args.flagIndex( "h", "height" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, height );
1>Posts1Cmd.cpp(37): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const int' to 'bool &'
1>Posts1Cmd.cpp(39): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(42): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
1>Posts1Cmd.cpp(44): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(47): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you are going to get new values from the get function, you cannot have the target variables const.
Try
int nPosts = 5;
double radius = 0.5;
double height = 5.0;
Also, you should not declare a new index variable for each call. Just declare it once and reuse it.