Squirrel Scripting Language

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
mynameisactuallyyoshi
Gnoblar
Posts: 24
Joined: Fri Nov 10, 2006 7:07 pm

Post by mynameisactuallyyoshi »

Hey everyone, sorry to bring this thread back from the dead, but I just tried the tutorial on this stuff in the Wiki, and I got some compiler errors after copying the code from the tut.

Basically, most of the errors involve not being able to convert between the SQChar * type and Ogre's string type. I realize that SQChar is just typedef-ed wchar_t (which seems to be defined as unsigned short) and Ogre's string type is just the STL string type, but I'm not sure how to convert between the two, and I'm wondering if I'm the only one experiencing this problem (maybe the Wiki tutorial is a little out of date? because it uses SceneManager's removeEntity but there is no removeEntity function in the most recent Ogre distribution, from what I can tell).

For the most part I was able to just change SQChar * variables to String variables, but the printFunc function is a bit trickier and I can't seem to just fudge that one, so is there some way that I'm missing to convert from wchar_t * to String?

Thanks!
User avatar
Project5
Goblin
Posts: 245
Joined: Mon Nov 22, 2004 11:56 pm
Location: New York, NY, USA

Post by Project5 »

In SqPlus.h, look for the macro SUPPORT_STD_STRING or similar. It should be near the top, and it controls the defining of Push, Get, and Match for std::string. All you have to do is copy that vebatim into your code and replace std::string with Ogre::String.

Or you can just use the macro and define the functions in SqPlus.h if Ogre::String is the same as std::string. This will work if you're not compiling Ogre with unicode on.

Hope that helps,

--Ben
mynameisactuallyyoshi
Gnoblar
Posts: 24
Joined: Fri Nov 10, 2006 7:07 pm

Post by mynameisactuallyyoshi »

Hey, thanks for the reply...

I tried both of your suggestions, but to no avail. In the first case, I just got the same errors as if I hadn't taken your suggestion. The errors go like...

Error 1 error C2664: 'Ogre::Entity::setMaterialName' : cannot convert parameter 1 from 'const SQChar *' to 'const Ogre::String &' c:\documents and settings\...

Error 3 error C2664: 'SquirrelVM::CompileScript' : cannot convert parameter 1 from 'const char [9]' to 'const SQChar *' c:\documents and settings\...

Error 4 error C2664: 'Ogre::Log::logMessage' : cannot convert parameter 1 from 'SQChar [2048]' to 'const Ogre::String &' c:\documents and settings\...

In the second case, I just uncommented the line at the top that says

Code: Select all

// === Uncomment to support std::string ===
//#define SQPLUS_SUPPORT_STD_STRING
and I get 100+ errors... I think mainly due to namespace issues. In any case... I figure Squirrel is only using SQChar * to be unicode compatible, which may not be the most important concern at the moment, so I might just change the code accordingly, but if you have any other ideas, that would be great, too.

Thanks!
User avatar
Project5
Goblin
Posts: 245
Joined: Mon Nov 22, 2004 11:56 pm
Location: New York, NY, USA

Post by Project5 »

The first case looks like Push and Get aren't defined for std::string. Squirrel uses c style strings, so SqPlus needs to know how to convert from one to the other.

If uncommenting SQPLUS_SUPPORT_STD_STRING doesn't work, I'd suggest looking near the bottom of SqPlus.h for where Push, Get, and Match are defined for ints, floats, etc, and make your own set for converting back and forth between SQChar* and std::string.

In any case, we should probably move this conversation to the Squirrel embedding forums over here.

--Ben
ahmedmustafa123
Gnoblar
Posts: 4
Joined: Thu Jan 18, 2007 4:10 am

Post by ahmedmustafa123 »

anyone have a c++ code for handling CEGUI in squirrel
ahmedmustafa123
Gnoblar
Posts: 4
Joined: Thu Jan 18, 2007 4:10 am

Post by ahmedmustafa123 »

any one can HELPPP MEEE HERE???? where to put this code, where is this "UI" name space???
pfo wrote:@Tyn: Squirrel is the first scripting language I have ever used, so I know nothing about tolua and I have not looked at how lua and CEGUI play together. This is my approach to Squirrel <-> CEGUI interaction:

I created a namespace called "UI" to hold all CEGUI interaction, here's a sample:

Code: Select all

	SquirrelObject root = SquirrelVM::GetRootTable();
	nameSpaceTable = SquirrelVM::CreateTable();
	root.SetValue("UI", nameSpaceTable);
	Register(v, nameSpaceTable.GetObjectHandle(), LoadLayout, "LoadLayout");
	Register(v, nameSpaceTable.GetObjectHandle(), RestoreLayout, "RestoreLayout");
	Register(v, nameSpaceTable.GetObjectHandle(), _SetLayout, "SetLayout");
	Register(v, nameSpaceTable.GetObjectHandle(), BindEvent, "BindEvent");
	Register(v, nameSpaceTable.GetObjectHandle(), BindListSelectedEvent, "BindListSelectedEvent");
	Register(v, nameSpaceTable.GetObjectHandle(), BindListDoubleClickEvent, "BindListDoubleClickEvent");
	Register(v, nameSpaceTable.GetObjectHandle(), _ClearUIEvents, "ClearEvents");
	Register(v, nameSpaceTable.GetObjectHandle(), _GetWindowText, "GetWindowText");
	Register(v, nameSpaceTable.GetObjectHandle(), _SetWindowText, "SetWindowText");
	Register(v, nameSpaceTable.GetObjectHandle(), _HideWindow, "HideWindow");
	Register(v, nameSpaceTable.GetObjectHandle(), _ShowWindow, "ShowWindow");
	Register(v, nameSpaceTable.GetObjectHandle(), ClearListbox, "ClearListbox");
	Register(v, nameSpaceTable.GetObjectHandle(), AddListboxItem, "AddListboxItem");
	Register(v, nameSpaceTable.GetObjectHandle(), PopulateListWithDir, "PopulateListWithDir");
	Register(v, nameSpaceTable.GetObjectHandle(), GetParentDir, "GetParentDir");

where to put this?? and where is te decleration of the functions (GetParentDir, GetParentDir,...)
User avatar
ebol
Halfling
Posts: 67
Joined: Sun Sep 24, 2006 8:49 pm

Post by ebol »

Sorry to dig this up, but I have this issue that's driving me mad.

I know that this sound stupid, but I'm having linker errors when I try to bind a class to Squirrel. At first I thought I forgot to link to some libraries, but that was not it. I checked 100 times if Squirrel and SqPlus are build with the same parameters as my application, and their are - the same calling convention, both using the same runtime library version... And linker returns only errors about the binding code, initializing and destroying VM compiles, links and works.

I tried to bind Ogre::Vector3 class like in tutorial, also checked it with any other classes, results are always the same.

EDIT:
And another strange thing, I tried this:

Code: Select all

SquirrelObject helloWorld = SquirrelVM::CompileBuffer(_T("print(\"Hello World\");"));
SquirrelVM::RunScript(helloWorld);
and I got a linker error about SquirrelVM::CompileBuffer, but SquirrelVM::RunScript links, and they are the methods of the same class...


I'm totally lost, If someone can help me with this in any way, I would be really grateful.

Here's the linker output:

Code: Select all

Error	1	error LNK2019: unresolved external symbol "public: static class SquirrelObject __cdecl SquirrelVM::CreateFunction(class SquirrelObject &,int (__cdecl*)(struct SQVM *),wchar_t const *,wchar_t const *)" (?CreateFunction@SquirrelVM@@SA?AVSquirrelObject@@AAV2@P6AHPAUSQVM@@@ZPB_W3@Z) referenced in function "class SquirrelObject __cdecl SqPlus::RegisterClassType<class cMonster>(struct SQVM *,wchar_t const *,wchar_t const *)" (??$RegisterClassType@VcMonster@@@SqPlus@@YA?AVSquirrelObject@@PAUSQVM@@PB_W1@Z)	cGameWorld.obj

Code: Select all

Error	2	error LNK2019: unresolved external symbol "int __cdecl SqPlus::CreateClass(struct SQVM *,class SquirrelObject &,void *,wchar_t const *,wchar_t const *)" (?CreateClass@SqPlus@@YAHPAUSQVM@@AAVSquirrelObject@@PAXPB_W3@Z) referenced in function "class SquirrelObject __cdecl SqPlus::RegisterClassType<class cMonster>(struct SQVM *,wchar_t const *,wchar_t const *)" (??$RegisterClassType@VcMonster@@@SqPlus@@YA?AVSquirrelObject@@PAUSQVM@@PB_W1@Z)	cGameWorld.obj

Code: Select all

Error	3	error LNK2019: unresolved external symbol "public: int __thiscall SquirrelObject::SetValue(wchar_t const *,int)" (?SetValue@SquirrelObject@@QAEHPB_WH@Z) referenced in function "void __cdecl SqPlus::setupClassHierarchy(class SquirrelObject)" (?setupClassHierarchy@SqPlus@@YAXVSquirrelObject@@@Z)	cGameWorld.obj

Code: Select all

Error	4	error LNK2019: unresolved external symbol "public: class SquirrelObject __thiscall SquirrelObject::GetValue(wchar_t const *)const " (?GetValue@SquirrelObject@@QBE?AV1@PB_W@Z) referenced in function "void __cdecl SqPlus::setupClassHierarchy(class SquirrelObject)" (?setupClassHierarchy@SqPlus@@YAXVSquirrelObject@@@Z)	cGameWorld.obj

Code: Select all

Error	5	error LNK2019: unresolved external symbol "public: int __thiscall SquirrelObject::SetValue(wchar_t const *,class SquirrelObject const &)" (?SetValue@SquirrelObject@@QAEHPB_WABV1@@Z) referenced in function "void __cdecl SqPlus::setupClassHierarchy(class SquirrelObject)" (?setupClassHierarchy@SqPlus@@YAXVSquirrelObject@@@Z)	cGameWorld.obj

Code: Select all

Error	6	error LNK2019: unresolved external symbol "public: int __thiscall SquirrelObject::Exists(wchar_t const *)const " (?Exists@SquirrelObject@@QBEHPB_W@Z) referenced in function "void __cdecl SqPlus::setupClassHierarchy(class SquirrelObject)" (?setupClassHierarchy@SqPlus@@YAXVSquirrelObject@@@Z)	cGameWorld.obj
Thanks in advance.
Moo_Juice
Kobold
Posts: 29
Joined: Mon Apr 27, 2009 10:28 am

Re: Squirrel Scripting Language

Post by Moo_Juice »

Hi guys,

I've chosen Squirrel as the scripting language of choice for my project. It looks great and does everything I want it to do (and more).

I've compiled and included 'sqplus.h", but I get the following linker error:

Code: Select all

1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator<char>::allocator<char>(void)" (??0?$allocator@D@std@@QAE@XZ) already defined in sqplusD.lib(SquirrelVM.obj)
The Squirrel DLLs I built are all multi-threaded, and I can't figure out why it won't link.

Sorry if it's an obvious solution.


Thanks in advance!
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Squirrel Scripting Language

Post by jacmoe »

Make sure you're not linking to the wrong runtime (debug/release), and make sure that you're using multithreaded debug DLL/multihreaded DLL in your runtime settings.
You probably forgot to set it to DLL?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Moo_Juice
Kobold
Posts: 29
Joined: Mon Apr 27, 2009 10:28 am

Re: Squirrel Scripting Language

Post by Moo_Juice »

My application is Multi-threaded [Debug] DLL.

The Squirrel libraries are multi-threaded. They don't specify MultiThreaded Debug DLL as they're statically linked.
Moo_Juice
Kobold
Posts: 29
Joined: Mon Apr 27, 2009 10:28 am

Re: Squirrel Scripting Language

Post by Moo_Juice »

Just as an update,

My DEBUG links against:

OgreMain_d.lib
OIS_d.lib
common_d.lib
MyGUI_d.lib
squirrelD.lib
sqstdlibD.lib
sqplusD.lib

and RELEASE:

OgreMain.lib
OIS.lib
common.lib
MyGUI.lib
squirrel.lib
sqstdlib.lib
sqplus.lib

Release builds just fine.
Moo_Juice
Kobold
Posts: 29
Joined: Mon Apr 27, 2009 10:28 am

Re: Squirrel Scripting Language

Post by Moo_Juice »

Ok, update to this:

My DLLs are Multi-threaded Debug DLLs.
Squirrel libraries are just Multi-threaded Debug.

Switching my DLLs to Multi-Threaded-Debug means success, but then i get problems with heap pointers during the runtime.

I tried building the squirrel libraries as multi-threaded Debug DLLs, but got a ton of compilation errors.


Argh! :)
Post Reply