Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    557
  • comments
    1237
  • views
    422939

Untitled

Sign in to follow this  
Evil Steve

66 views

And now scripting is in. I'm amazed how nice and simple it was, once I got my OOPy stuff working with C closures.
I can run a script that just calls LoadScript("Test2.script") correctly, and call a function from that newly loaded script with the following code:

// The function:
class LoadScript : public EScriptFunction
{
public:
LoadScript() : EScriptFunction(L"LoadScript") {}

virtual void Call(EScriptContext& context)
{
EScriptMgr::Get().LoadScript(context.GetArgAsString(0));
}
};

// Register the function
EScriptMgr::Get().Register(new LoadScript);

// Load and run Test.script (Which will cause LoadScript to be called)
EScriptMgr::Get().LoadScript(L"Test.script");

// Get an object allowing us to make a call to the "main" function in Lua
EScriptCall::SP pCall = EScriptMgr::Get().Call(L"main");

// Add some args
pCall->AddArg(L"LOL");
pCall->AddArg(42);

// Call the script function
if(!pCall->Call())
{ /* Error */ }

// Get the first return value as a string
std::wstring strRetval = pCall->GetRetvalAsString(0);


Nice and simple. I might make some wrapper functions to easily call script functions with 0 or 1 parameters that return void.

So anyway, scripting is now "Complete", and is ready to be moved into TEH ENGINE. I told you there was a reason to be doing this side project [smile]
So I've now got 3 modules ready to bung into the main engine; File system, network and scripting.

I'll probably start getting the guts of the server going today, and it should be ready for a test tomorrow if all goes well. I'll post in the lounge if that's the case.

Anyway, work time...
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!