You need to use ExecuteBuffer and call it as if you would ingame. ex: If you wanna click a button on your custom addon ingame is "/script MyCustomButton:Click()" while the ExecuteBuffer call from C# would be 'MyCustomButton:Click()'
Then it would execute all relevant code associated with the button click handler in your lua.
A more indepth way to do it would be as in ArcEmu.
Code:
oid lua_engine::BeginLuaFunctionCall(lua_function ref)
{
ReferenceHandler::getReference(lua_state, (ptrdiff_t)ref);
}
bool lua_engine::ExecuteLuaFunction(int params, int res, variadic_parameter** results, bool getparams)
{
bool ret = true;
lua_State* lu = lua_state;
int top = lua_gettop(lu);
if(lua_type(lu, top - params) != LUA_TFUNCTION)
{
ret = false;
if(params++ > 0)
{
for(int i = top; i > 0 && i >= (top - params); i--)
{
if(!lua_isnone(lu, i))
lua_remove(lu, i);
}
}
else
lua_pop(lu, 1); //pop the nil pushed by BeginFunctionCall.
}
else
{
if(lua_pcall(lu, params, res, 0))
{
report(lu);
ret = false;
}
//Get result arguments from lua.
else if(getparams)
*results = luabridge::tdstack<variadic_parameter*>::get(lu, (top - params));
}
return ret;
}
void lua_engine::EndLuaFunctionCall(int res)
{
lua_State* lu = lua_state;
for(int i = res; i > 0; i--)
{
if(!lua_isnone(lu, res))
lua_remove(lu, res);
}
}