How can I call javascript function in cocos2d-js.
I need to call split method.
If I call "This is a sample string".split(/ /g) it works fine. But I need to call it on a cocos2d object.
I believe somehow I need to convert cocos2d-js variable(string) to javascript executable object.
Please help.
Related
I got a c++ demo that has successfully called the API written in c++, now am trying to call those API from excel VBA. I've done quite a bit research but still not able to link them together.
Basically there's a API(TapQuoteAPI.dll) export function like this in demo
'TapQuote.h
TAP_DLLEXPORT const TAPICHAR *TAP_CDECL GetTapQuoteAPIVersion();
in demo c++ solution(TapQuoteAPI_Demo), i include the 'TapQuote.h' in demo.cpp,
the cout<<GetTapQuoteAPIVersion()<<endl; is successfully called, and result is print.
but when it comes to call this function in excel vba, i keep failing.
I tried to directly use the TapQuoteAPI.dll in excel like this, but not working.
Declare Function GetTapQuoteAPIVersion Lib "D:\Proejct\WIN32\TapQuoteAPI.dll" () As String
Then I also try to build another dll function with a deFile.def from TapQuoteAPI_Demo.dll since i successfully call it within the c++ demo.
Declare Function GetTapQuoteAPIVersion Lib "D:\Proejct\WIN32\TapQuoteAPI_demo.dll" () As String
also failed.
Could anyone shed some lights for me please?
If I had a lua script, say
print'hi'
How would I get the lua bytecode equivalent to it using c++? I'm not sure if I'm explaining this right though. Thanks for all your help!
You need to load a script and then dump its bytecode.
The relevant C API functions are luaL_loadfile or luaL_loadstring for loading (they use the primitive lua_load) and lua_dump for dumping.
Loading is easy to do with these helper functions.
Dumping is a bt more work because of the need to provide a writer function. It may be easier to call string.dump after loading:
// load script, leave function on the stack
lua_getglobal(L,"string");
lua_getfield(L,"dump");
lua_pushvalue(L,-3);
lua_call(L,1,1);
// string containing bytecode left on the stack
How to execute some function in CViewClass, when I get a file in Openfile() function in CDocumentClass?
I have a function OpenFile to get a file in CDocumentClass, and I can make it work getting a file and processing the file.
Now, I want to make some function in CViewClass operate after getting a file in CDocumentClass.
I've already tried to use OnInitialUpdate() in CViewClass, but it's executed only for the first time or the state of getting NEW project, so it doesn't make it work.
What function do I have to use to make it work?
To reflect changes made to the Document in a view, you should call:
yourDoc->UpdateAllViews();
See MSDN for more details.
IESetProtectedModeCookie function not found in Iepmapi.h
But when i call function using LoadLibrary technique with Ieframe.dll then it create entry in LOW folder of cookies but get GP after creating entry.
How?
If you look at the documentation for IESetProtectedModeCookie, you can see that it is only supported in IE8 and above.
Try defining _WIN32_IE=_WIN32_IE_IE80 and call the function normally instead of using LoadLibrary.
I found this blog post about how to bind c++ classes to lua: http://loadcode.blogspot.com/2007/02/wrapping-c-classes-in-lua.html
But it's not working straight out of the box.
I've tweaked the function to my own and instead of a Sprite class I'm using a NPC class.
I changed the function setSpeed to my own called NpcSetPosition(lua_State *L) which will be called everytime I call the following in lua:
local npc = Npc:New()
npc:SetPosition(5,5)
(the npc:SetPosition function)
Now what's interesting is how I call the checkSprite inside the NpcSetPosition and if I do so once, the lua script will run all fine. But if I do it twice(I call npc:SetPosition(5,5) twice) I get the following error message:
Lua Compile Error: script.lua:10: bad argument #1-1 to: 'SetPosition' (table expected, got userdata)
Which means I can't set the position for the npc twice which is crap.
Do you know what's going wrong?
Does it have to do with the lua stack?
Thanks.
Sounds like you are incorrectly managing your stack.
Are you doing lua_settop( 0 ); or similar in your SetPosition function?
If your managing your stack correctly then this error will disappear.