Jump to content
  • Advertisement
Sign in to follow this  
jflanglois

SqPlus Question and Comment

This topic is 4356 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

First the question: How does one get operator() to work on a squirrel object when it has parameters? Take the following code for example:
#include "sqplus.h"

#include <iostream>

struct Test {
  void operator()( int i ) {
    std::cout << "operator() " << i << std::endl;
  }
};

int main() {
  SquirrelVM::Init();
  SqPlus::SQClassDef< Test >( L"Test" ).
    func( &Test::operator (), L"_call" );

  SquirrelObject script = SquirrelVM::CompileBuffer(
    L"local test = Test();\n"
    L"test( 3 );" );

  SquirrelVM::RunScript( script );
  SquirrelVM::Shutdown();
}


I get an exeption with:
AN ERROR HAS OCCURED [attempt to call 'instance']

CALLSTACK
*FUNCTION [main()] console_buffer line [2]

LOCALS
[test] INSTANCE
[this] TABLE
If I don't have any parameters for opertor(), then it works fine. Am I missing something about the _call metamethod? It can take parameters, can't it? Now the comment: You may have noticed that the code above uses wide character strings. If I define SQPLUS_SUPPORT_STD_STRING, then string works, but wstring doesn't. I propose that instead of:
inline void Push( HSQUIRRELVM v, const std::string & value ) { sq_pushstring( v, value.c_str(), -1 ); }
inline bool Match( TypeWrapper< const std::string & >, HSQUIRRELVM v, int idx ) { return sq_gettype( v, idx ) == OT_STRING; }
inline std::string Get( TypeWrapper< const std::string & >, HSQUIRRELVM v, int idx ) { const SQChar * s; SQPLUS_CHECK_GET( sq_getstring( v, idx, &s ) ); return std::string( s ); }

It be:
inline void Push( HSQUIRRELVM v, const std::basic_string< SQChar > & value ) { sq_pushstring( v, value.c_str(), -1 ); }
inline bool Match( TypeWrapper< const std::basic_string< SQChar > & >, HSQUIRRELVM v, int idx ) { return sq_gettype( v, idx ) == OT_STRING; }
inline std::basic_string< SQChar > Get( TypeWrapper< const std::basic_string< SQChar > & >, HSQUIRRELVM v, int idx ) { const SQChar * s; SQPLUS_CHECK_GET( sq_getstring( v, idx, &s ) ); return std::basic_string< SQChar >( s ); }

As far as I've tested it, it seems to work correctly. I suppose one could add the definitions for wstring instead, since I'm not entirely sure if SqChar will always be char or wchar_t, and that basic_string< SqChar > will be equivalent to string and wstring. jfl.

Share this post


Link to post
Share on other sites
Advertisement
Not clear why the metamethod _call does not work, perhaps trace the code to see if it's an SqPlus issue or language issue, or change the code slightly (register doCall() instead of _call):

SquirrelObject script = SquirrelVM::CompileBuffer(
L"local test = Test();\n"
L"test.doCall( 3 );" );



Also perhaps test the _call method in pure script code (and post question on Squirrel forum).

String change: please post on the Squirrel forum for feedback; if no objections, I'll make the changes to SqPlus.

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!