YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

[sqplus] How do I call a Squirrel function in C++?
TheKrane
#1 Posted : Tuesday, August 16, 2016 1:05:06 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/16/2016(UTC)
Posts: 2

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
I've set up a simple scripting system for my game engine using C++ and Squirrel.
Everything is working fine so far. I can compile and execute scripts without problems.
When I try to call one specific function though it's just not executing the code at all.

Here's my Squirrel script:
Code:

function Start()
{
    print("Initializing Player");
}

function Update()
{
    print("Updating Player");
}


And here's how I'm trying to call the funtions:
Code:

squirrelScript = SquirrelVM::CompileBuffer(buffer.str().c_str());
SqPlus::SquirrelFunction<void>("Start", squirrelScript);


Is calling a function like this even possible? If so, how?
Thanks in advance,
TheKrane
gcgcgc
#2 Posted : Wednesday, August 17, 2016 11:55:11 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/19/2011(UTC)
Posts: 9

Thanks: 0 times
Was thanked: 1 time(s) in 1 post(s)
TheKrane wrote:
I've set up a simple scripting system for my game engine using C++ and Squirrel.
Everything is working fine so far. I can compile and execute scripts without problems.
When I try to call one specific function though it's just not executing the code at all.

Here's my Squirrel script:
Code:

function Start()
{
    print("Initializing Player");
}

function Update()
{
    print("Updating Player");
}


And here's how I'm trying to call the funtions:
Code:

squirrelScript = SquirrelVM::CompileBuffer(buffer.str().c_str());
SqPlus::SquirrelFunction<void>("Start", squirrelScript);


Is calling a function like this even possible? If so, how?
Thanks in advance,
TheKrane


I think SquirrelFunction is an object you can call, like this:

SqPlus::SquirrelFunction<void> myFunction("Start");
myFunction(arguments to pass to function);

I'm not sure where the script fits in just yet, maybe just compiling it adds Start to the VM, or maybe you have to call that too.
1 user thanked gcgcgc for this useful post.
TheKrane on 8/19/2016(UTC)
TheKrane
#3 Posted : Friday, August 19, 2016 8:17:47 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/16/2016(UTC)
Posts: 2

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
Thank you so much!
I finally figured it out thanks to your help.
I didn't realize that SquirrelFunction is a function like any other and needs to be called like one. Squirrel can be really confusing sometimes, because there's not enough information about it online.

Here's my final solution:
Code:

SqPlus::SquirrelFunction<void>("Update")();
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.075 seconds.