Brown Bag Studio
Would you like to react to this message? Create an account in a few clicks or log in to continue.

LUA Script Component

Go down

LUA Script Component Empty LUA Script Component

Post  EricWoh Fri Nov 04, 2011 9:30 pm

To help keep components in the engine more general, we will be adding a LUA Script Component. The engine will be able to interpret script files (.lua) as code, and execute functions inside of them without recompiling. To get a more general idea of this, an example follows.

A programmer is creating a new component that he wishes to have LUA script ran on. The first thing he will do is implement a static RegisterForLUA function. This function will inform a LUA script of variables, constructors and functions the script will need to know about to work with the SampleComponent class using macros define in "LUAInclude.h".

Code:
SampleComponent : public GOC {
int var;
void func(void);
SampleComponent(int) {}
public:
static RegisterForLua(lua_State * L)
{
  AddClassToLUA(L, SampleComponent)
    AddVariable(var, &SampleComponent::var)
    AddFunction(func, &SampleComponent::func)
    AddConstructor(int)
  EndClassToLua
}
};


Now the programmer has the ability to register his class with a LUA function, now he just needs a Lua Module with which to register. So, the user will serialize in the path of the Lua script he wishes to have run for a whatever event, lets say OnAttack. I'll assume you understand how to serialize and store strings.

Now the user will call the "RegisterLuaScript" function passing it its this pointer, the message id of when it would like to be activated, and the path of the LUA script it serialized in:

Code:
RegisterLuaScript(this, Mid::OnAttack, luaPath);

This function will determine the script component of the object, and, if it exists, create the LUA path, store it in a list of scripts to be ran whenever the Mid is received, and store the this pointer to be passed to the function when invoked.

Now, whenever the message is received, the script component will invoke the specified script on the object that received the message. Huzzah!

I feel the need to add that, at the moment, I have yet to build this. After I do, I'll let you know if this is the way it works.

EricWoh

Posts : 10
Join date : 2011-10-25

Back to top Go down

LUA Script Component Empty Re: LUA Script Component

Post  EricWoh Fri Nov 04, 2011 10:28 pm

I'm pretty sure this is going to work. I'll be writing this tomorrow. Let me know if anyone has any questions or concerns.

EricWoh

Posts : 10
Join date : 2011-10-25

Back to top Go down

LUA Script Component Empty Re: LUA Script Component

Post  EricWoh Sat Nov 05, 2011 4:49 am

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnddd.... implemented.

EricWoh

Posts : 10
Join date : 2011-10-25

Back to top Go down

LUA Script Component Empty Re: LUA Script Component

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum