Jump to content
  • Advertisement
Sign in to follow this  
Valor Knight

Question with sqplus

This topic is 4701 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(Decided to go with sqplus, just changed title) This may seem like a dumb question but I cannot find the answer anywhere, and I’m new to trying to implement a scripting language in my program. I am trying to register a function via RegisterDirect, inside a class function ex: (Lua is setup as LuaObject... setup is fine I assume because it works fine when it is not in classes) void someclass::function2(){...} void someclass::function() { Lua->RegisterDirect("Test function", function2); } function 2 is another member function inside of the same class. But, when I try, I get 12 errors. Now if I registered a function outside of a class, and the register call was not in a member function, then it will compile and execute correctly. Is there something I am missing on how to register functions inside of a class, or preferably as a wrapper? [Edited by - Valor Knight on October 7, 2005 9:43:18 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You're trying to use a member functions as if it was a regular functions.
The correct usage(if the function is static) is:
Lua->RegisterDirect("Test function", &someclass::function2);

If this function isn't static, you'll need to bind the current instance to it with "this". I know it's possible with stl's bind1st or with boost::bind.

Share this post


Link to post
Share on other sites
When I used LuaPlus, I registered pre-allocated classes and member functions as:

someclass myClass;

Lua->RegisterDirect("Test function",&myClass,someclass::function2);

By the time I needed class instance support, I had switched to Squirrel (and wrote Sqplus to provide bindings to Squirrel that did not appear to exist with Lua and LuaPlus). Perhaps ask Joshua Jensen for more info about LuaPlus bindings: LuaPlus.org or post the questions on the LuaPlus forum.

For more complete binding support for Lua, perhaps see luabind (requires boost headers): http://luabind.sourceforge.net/

Share this post


Link to post
Share on other sites
Thanks for the help, I have been switching choices, trying to decide what scripting language would be easier to do this in. I have actually tried your sqplus but I could not get it to compile correctly in my project. I assume that SquirrelVM::Init(); initilizes it, but there was no real indication on what files were required to include to add it in my project. Ill have to try it again if that is my best chance to implement this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Valor Knight
Thanks for the help, I have been switching choices, trying to decide what scripting language would be easier to do this in. I have actually tried your sqplus but I could not get it to compile correctly in my project. I assume that SquirrelVM::Init(); initilizes it, but there was no real indication on what files were required to include to add it in my project. Ill have to try it again if that is my best chance to implement this.


Sorry about that. I'll create a very simple example shortly.
In the meantime:

Link with squirrel.lib, sqstd.lib, and sqplus.lib (See the testSqPlus2 example).

#include "sqplus.h"

int main(int argc,char * argv[]) {
SquirrelVM::Init();
SquirrelObject helloWorld = SquirrelVM::CompileBuffer("print(\"Hello World\");");
SquirrelVM::RunScript(helloWorld);
SquirrelVM::Shutdown();
}

See testSqPlus2.cpp for example bindings.

What compiler/environment are you using?

Share this post


Link to post
Share on other sites
I am using Microsoft Visual Studio.net 2003.

Having a problem (I got the include files ect.. from the demo program)
Do I have to include the sqplus project into my solution? Thats the only thing that I can see that is diffrent from your demo app

Thanks


error LNK2019: unresolved external symbol "public: static void __cdecl SquirrelVM::Shutdown(void)" (?Shutdown@SquirrelVM@@SAXXZ) referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall SquirrelObject::~SquirrelObject(void)" (??1SquirrelObject@@UAE@XZ) referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol "public: static class SquirrelObject __cdecl SquirrelVM::RunScript(class SquirrelObject const &,class SquirrelObject *)" (?RunScript@SquirrelVM@@SA?AVSquirrelObject@@ABV2@PAV2@@Z) referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol "public: static class SquirrelObject __cdecl SquirrelVM::CompileBuffer(char const *)" (?CompileBuffer@SquirrelVM@@SA?AVSquirrelObject@@PBD@Z) referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol "public: static void __cdecl SquirrelVM::Init(void)" (?Init@SquirrelVM@@SAXXZ) referenced in function _WinMain@16

Share this post


Link to post
Share on other sites
Quote:
Original post by Valor Knight
I am using Microsoft Visual Studio.net 2003.

Having a problem (I got the include files ect.. from the demo program)
Do I have to include the sqplus project into my solution? Thats the only thing that I can see that is diffrent from your demo app

Thanks



Yes, include the sqplus project and you should be good to go.

Share this post


Link to post
Share on other sites
Ok got it to work, thanks - just had to make my project dependant on the sqplus project.



[Edited by - Valor Knight on October 8, 2005 12:13:53 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!