Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Sqrat
thomas:
Playing with Sqrat for a while, I've found out that it is not alltogether as nice as easy as it looked at first sight, at least not for us (or maybe I'm really just too stupid).
First, it is not trivial to bind enum values, of which we have quite a number bound. You need to add each enum name with its proper value to the constant table. Not all values are contiguous either, and not all are in our own headers.
Basically, as far as enum values go, we are left with the following choices:
* maintain the enum and its script binding separately
* use X-Macros
The first solution is error prone and a maintenance nightmare, the second solution is moderately ugly and doesn't look like C++. Also it won't work for the wxWidgets enums that we bind (will have to do these by hand either way).
Also, giving X-Macros a try (which kind of worked, too), I suddenly realized that Code::Blocks uses Unicode strings, so when a script is called, its identifiers should obviously be provided as wchar_t.
Adding a L wrapper generated "note: no known conversion for argument 1 from 'const wchar_t [4]' to 'const SQChar* {aka const char*}'".
Oh oh, looks like I forgot compiling with -DSQUNICODE.
Now, compiling with -DSQUNICODE, it turns out that neither Squirrel nor Sqrat work properly in Unicode mode... Squirrel has a special codepath for MSVC to behave properly, and typedefs wchar_t on every other compiler (no, I'm not joking, look at lines 116-125 in squirrel.h), and Sqrat calls sq_throwerror with ordinary C character strings, regardless of ANSI/Unicode mode (with -DSQUNICODE, the function expects const wchar_t*). Both issues break the build.
Ideas? Seriously, I must be making a mistake here, this cannot be ;D
thomas:
Note:
There seems to be a similar issue with constants in SQPlus. At least that is how I interprete the obscure macros used all over the place, which bind constants not as constants, but rather as macro-generated getter callback functions which return a constant at runtime.
This might be a third solution for the binding issue in Sqrat, though it kind of shares the worst of both worlds. It's ugly and obscure, and it has runtime overhead.
MortenMacFly:
Well looking at how we did things in the Squirrel we use I see in squirrel.h:
1.)
--- Code: ---// C::B patch: Comment out Unicode stuff
//#ifdef _UNICODE
//#define SQUNICODE
//#endif
--- End code ---
...and 2.)
--- Code: ---// C::B patch: Comment out typedef
//typedef unsigned short wchar_t;
--- End code ---
What happens if you do the same in Squirrel 3.x.x?
(We also don't compile with SQUNICODE btw...)
MortenMacFly:
Well I just tried with your example, and if I exchange lines 109-122 with:
--- Code: ---// C::B patch: Unicode stuff only if not omitted
#if !defined(SQUNICODE) && defined(_UNICODE) && !defined(NO_SQUNICODE)
#define SQUNICODE
#endif
#ifdef SQUNICODE
#if (defined(_MSC_VER) && _MSC_VER >= 1400) // 1400 = VS8
#if !defined(_NATIVE_WCHAR_T_DEFINED) // this is if the compiler considers wchar_t as native type
#define wchar_t unsigned short
#endif
// C::B patch: typedef only for non-GCC
#elif !defined(__GNUC__) // wchar_t is already defined in GCC
typedef unsigned short wchar_t;
#endif
--- End code ---
...and then within your sqtest sample:
--- Code: ---static void printfunc(HSQUIRRELVM v,const SQChar *s,...)
{
va_list vl;
va_start(vl, s);
#ifdef SQUNICODE
vwprintf(s, vl);
#else
vprintf(s, vl);
#endif
va_end(vl);
}
--- End code ---
...and all references in sqRat to sq_throwerror with something like:
--- Code: --- if(SQ_FAILED(sq_get(vm, 1))) { // Lookup the proper overload
return sq_throwerror(vm, _SC("No overload matching this argument list found"));// How to best appropriately error?
}
--- End code ---
...it works fine here, when compiling with SQUNICODE enabled.
It seems sqrat was never tried with unicode, too - but these simple changes should do it.
thomas:
--- Quote ---
--- Code: ---// C::B patch: Comment out typedef
//typedef unsigned short wchar_t;
--- End code ---
--- End quote ---
Well, sure enough, this is what I did, and this certainly works... it's just bleh. "Vendors Are Bad For Security" as Ben Laurie put it (though I'm sure this patch is kind of harmless).
--- Quote ---(We also don't compile with SQUNICODE btw...)
--- End quote ---
Hum... how does a script work with non-ANSI characters then? Without this, Squirrel strings (and scripts) are, according to the docs "plain 8-bits ASCII characters". The script loading functions in sqstdlib, too, only support UTF-8 and UTF-16 with SQUNICODE. This would mean that our scripted wizards and debugger scripts only work "by accident" because they're not localized :S
--- Quote from: MortenMacFly on June 27, 2012, 03:53:02 pm ---Well I just tried with your example, and if I exchange ...
--- End quote ---
Yes, yes, did all that too...
--- Quote ---with something like:
return sq_throwerror(vm, _SC("No overload matching this argument list found"));
--- End quote ---
That is exactly the problem. There are two occurrences that do not have the _SC.
Of course if I patch them in manually, it works. But again... bleh.
Let me maybe reword the Unicode question: Do we want Unicode? (Apparently so far we don't need it at all?)
Do we want to locally patch both packages so they work, or rather ... something else?
And about the enum issue... how dirty do we want to get, really... I'm not sure.
Navigation
[0] Message Index
[#] Next page
Go to full version