Click here to Skip to main content
13,002,399 members (64,969 online)
Click here to Skip to main content
Add your own
alternative version

Stats

37.2K views
679 downloads
28 bookmarked
Posted 2 Feb 2007
MIT

Calling Lua functions : using C++ language.

, 2 Feb 2007
Rate this:
Please Sign up or sign in to vote.
Calling Lua functions : using C++ language.

Audience

This article was written for C++ developers that want extend your application with Lua programming Language.

Introduction

One of the most common tasks when you use Lua in C++ application is call Lua functions, but this can be tiresome, you need use a lot of functions of LUA C API (lua_getglobal, lua_pushnumber, lua_pushstring, lua_tointeger and so on) to call one simple Lua function. Here I will show C++ templates that can make your life easy.

Interface

The interface is very easy see:. Think that you have these four Lua function and you want to call in your application:

Listing 1 – Lua Functions – test.lua
--------------------------------------------------------------------------------------

var = 10;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">function sum4(a, b, c, d)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">      return a+b+c+d;<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">end<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">function catenate(a, b)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">      <span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:black; mso-ansi-language:EN-US;mso-no-proof:yes">return a.." and "..b;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">end<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">function incVar(value)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">      <span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:black; mso-ansi-language:EN-US;mso-no-proof:yes">var = var+value;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">end<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">function getVar()<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">      return var;<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">end<o:p>

--------------------------------------------------------------------------------------

Then what you need to call these function is use:

  • LuaCall template class.

The basic way are you instantiate LuaCall with types of your Lua function receive and return, for sample:

float a = LuaCall<float, int, float, int, int>(L, "sum4").call(5, 1.5, 5, 5); 
See complete sample below (listing 2).

Listing 2 – using LuaCall – main.cpp

--------------------------------------------------------------------------------------

#include <iostream><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">#include "LuaCall.h"<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:teal; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">extern "C" <span style='color:fuchsia'>{<o:p>

#include<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes"> <lua.h><o:p>

#include<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes"> <lauxlib.h><o:p>

#include<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes"> <lualib.h><o:p>

}<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:teal;mso-no-proof:yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:teal;mso-no-proof:yes'=""><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">int main()<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<o:p>

try<o:p>

{<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">     <o:p>

      <span style='color:black'>lua_State *<span style='color:black'>L;<o:p>

<o:p>

      <span style='color:black'>L = <span style='color:black'>luaL_newstate();<o:p>

<o:p>

      <span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">if(luaL_loadfile(<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:black; mso-ansi-language:EN-US;mso-no-proof:yes">L, <span style='color:teal'>"list1.lua") || lua_pcall<span style='color:fuchsia'>(L<span style='color:fuchsia'>, 0<span style='color:fuchsia'>, 0<span style='color:fuchsia'>, 0<span style='color:fuchsia'>))<o:p>

{<o:p>

            <span style='color:blue'>throw std<span style='color:fuchsia'>::string<span style='color:fuchsia'>(std<span style='color:fuchsia'>::string<span style='color:fuchsia'>(lua_tostring<span style='color:fuchsia'>(L<span style='color:fuchsia'>, -<span style='color:red'>1)));<o:p>

      <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">}<o:p>

            <span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

      <span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:black; mso-ansi-language:EN-US;mso-no-proof:yes">std::cout << LuaCall<<span style='color:blue'>float, <span style='color:blue'>int, <span style='color:blue'>float, <span style='color:blue'>int, <span style='color:blue'>int>(<span style='color:black'>L, <span style='color:teal'>"sum4").<span style='color:black'>call(<span style='color:red'>5, <span style='color:red'>1.5, <span style='color:red'>5, <span style='color:red'>5) <span style='color:fuchsia'><< std<span style='color:fuchsia'>::endl<span style='color:fuchsia'>;<o:p>

<o:p>

      <span style='color:black'>std::<span style='color:black'>cout << <span style='color:black'>LuaCall<<span style='color:black'>std::<span style='color:black'>string, <span style='color:black'>std::<span style='color:black'>string, <span style='color:black'>std::<span style='color:black'>string>(<span style='color:black'>L, <span style='color:teal'>"catenate").<span style='color:black'>call(<span style='color:teal'>"Renato", "Bianca") << std<span style='color:fuchsia'>::endl<span style='color:fuchsia'>;<o:p>

<o:p>

      <span style='color:black'>LuaCall<<span style='color:black'>NullT, <span style='color:blue'>int>(<span style='color:black'>L, <span style='color:teal'>"incVar").<span style='color:black'>call(<span style='color:red'>10);<o:p>

<o:p>

      <span style='color:black'>std::<span style='color:black'>cout << <span style='color:black'>LuaCall<<span style='color:blue'>int>(<span style='color:black'>L, <span style='color:teal'>"getVar").<span style='color:black'>call() <span style='color:fuchsia'><< std<span style='color:fuchsia'>::endl<span style='color:fuchsia'>;<o:p>

<o:p>

            <o:p>

      <span style='color:blue'>if(<span style='color:black'>L != <span style='color:black'>NULL)<o:p>

      <span style='color:fuchsia'>{<o:p>

            <span style='color:black'>lua_close(<span style='color:black'>L);<o:p>

      <span style='color:fuchsia'>}<o:p>

}<o:p>

catch<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes"> (<span style='color:blue'>const std<span style='color:fuchsia'>::string <span style='color:fuchsia'>&e<span style='color:fuchsia'>)<o:p>

{<o:p>

      <span style='color:black'>std::<span style='color:black'>cout << <span style='color:black'>e << <span style='color:black'>std::<span style='color:black'>endl;<o:p>

}<o:p>

<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      return <span style='color:red'>0;<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">}<o:p>

Implementation

This is the implementation of LuaCall:

Listing 3 –LuaCall imp – LuaCall.h

--------------------------------------------------------------------------------------

template <<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T1, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T2<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>Duo <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">};<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:green; mso-ansi-language:EN-US;mso-no-proof:yes">// type that represents unused type parameters<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>NullT <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">};<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class LuaCallBase<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCallBase(<span style='color:black'>lua_State *<span style='color:black'>luaState, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>L = <span style='color:black'>luaState;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>lua_getglobal(<span style='color:black'>L, <span style='color:black'>functionName.<span style='color:black'>c_str());<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">protected:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void push<span style='color:fuchsia'>(const <span style='color:blue'>int &<span style='color:black'>value)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>lua_pushinteger(<span style='color:black'>L, <span style='color:black'>value);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void push<span style='color:fuchsia'>(const <span style='color:blue'>float &<span style='color:black'>value)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>lua_pushnumber(<span style='color:black'>L, <span style='color:black'>value);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void push<span style='color:fuchsia'>(const <span style='color:blue'>double &<span style='color:black'>value)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>lua_pushnumber(<span style='color:black'>L, <span style='color:black'>value);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void push<span style='color:fuchsia'>(const <span style='color:black'>std::<span style='color:black'>string &<span style='color:black'>value)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>lua_pushstring(<span style='color:black'>L, <span style='color:black'>value.<span style='color:black'>c_str());<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void get<span style='color:fuchsia'>(int <span style='color:fuchsia'>&value<span style='color:fuchsia'>) const<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>value = <span style='color:black'>lua_tointeger(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void get<span style='color:fuchsia'>(float <span style='color:fuchsia'>&value<span style='color:fuchsia'>) const<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>value = <span style='color:black'>lua_tonumber(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void get<span style='color:fuchsia'>(double <span style='color:fuchsia'>&value<span style='color:fuchsia'>) const<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>value = <span style='color:black'>lua_tonumber(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void get<span style='color:fuchsia'>(std<span style='color:fuchsia'>::string <span style='color:fuchsia'>&value<span style='color:fuchsia'>) const <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">{<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            <span style='mso-spacerun:yes'> value <span style='color:fuchsia'>= (<span style='color:blue'>char*)<span style='color:black'>lua_tostring(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>);<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void get<span style='color:fuchsia'>(NullT <span style='color:fuchsia'>&value<span style='color:fuchsia'>) const <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">protected:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>lua_State *<span style='color:black'>L;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">};<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">template <<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename TR,<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T1 = NullT,<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T2 = NullT,<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T3 = NullT,<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T4 = NullT<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>LuaCall<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>: public <span style='color:black'>Duo<<span style='color:black'>TR, <span style='color:blue'>typename LuaCall<span style='color:fuchsia'><T1<span style='color:fuchsia'>,T2<span style='color:fuchsia'>,T3<span style='color:fuchsia'>,T4<span style='color:fuchsia'>,NullT<span style='color:fuchsia'>> > <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>, public <span style='color:black'>LuaCallBase<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCall(<span style='color:black'>lua_State *<span style='color:black'>L, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:fuchsia'>: LuaCallBase<span style='color:fuchsia'>(L<span style='color:fuchsia'>, functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>TR call<span style='color:fuchsia'>(T1 <span style='color:black'>a1, <span style='color:black'>T2 a2<span style='color:fuchsia'>, T3 <span style='color:black'>a3, <span style='color:black'>T4 a4<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>TR returnValue<span style='color:fuchsia'>;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>push(<span style='color:black'>a1);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>push(<span style='color:black'>a2);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>push(<span style='color:black'>a3);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>push(<span style='color:black'>a4);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:blue'>if(<span style='color:black'>lua_pcall(<span style='color:black'>L, <span style='color:red'>4, <span style='color:red'>1, <span style='color:red'>0) <span style='color:fuchsia'>!= 0<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">                  <span style='color:blue'>throw std<span style='color:fuchsia'>::string<span style='color:fuchsia'>(std<span style='color:fuchsia'>::string<span style='color:fuchsia'>(lua_tostring<span style='color:fuchsia'>(L<span style='color:fuchsia'>, -<span style='color:red'>1)));<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>get(<span style='color:black'>returnValue);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:blue'>return returnValue<span style='color:fuchsia'>;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">};<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">template <<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename TR, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T1, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T2, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T3<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>LuaCall<<span style='color:black'>TR,<span style='color:black'>T1,<span style='color:black'>T2,<span style='color:black'>T3,<span style='color:black'>NullT> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>: public <span style='color:black'>Duo<<span style='color:black'>TR,<span style='color:black'>T1> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>, public <span style='color:black'>LuaCallBase<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCall(<span style='color:black'>lua_State *<span style='color:black'>L, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">: LuaCallBase<span style='color:fuchsia'>(L<span style='color:fuchsia'>, functionName<span style='color:fuchsia'>)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      TR <span style='color:black'>call(<span style='color:black'>T1 a1<span style='color:fuchsia'>, T2 <span style='color:black'>a2, <span style='color:black'>T3 a3<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">{<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            TR <span style='color:black'>returnValue;<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            push(a1<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>push(<span style='color:black'>a2);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>push(<span style='color:black'>a3);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:blue;mso-no-proof:yes'="">if<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">(lua_pcall(<span style='font-size:10.0pt;font-family:"courier new";color:black;mso-no-proof: yes'="">L, 3<span style='color:fuchsia'>, 1<span style='color:fuchsia'>, 0<span style='color:fuchsia'>) != <span style='color:red'>0)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:3'>                  throw <span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>lua_tostring(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>)));<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">}<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            get<span style='color:fuchsia'>(returnValue<span style='color:fuchsia'>);<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            return returnValue;<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">};<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:green;mso-no-proof: yes'=""><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">template <<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename TR, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T1, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T2<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>LuaCall<<span style='color:black'>TR,<span style='color:black'>T1,<span style='color:black'>T2,<span style='color:black'>NullT,<span style='color:black'>NullT> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>: public <span style='color:black'>Duo<<span style='color:black'>TR,<span style='color:black'>T1> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>, public <span style='color:black'>LuaCallBase<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCall(<span style='color:black'>lua_State *<span style='color:black'>L, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">: LuaCallBase<span style='color:fuchsia'>(L<span style='color:fuchsia'>, functionName<span style='color:fuchsia'>)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      {<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>TR call<span style='color:fuchsia'>(T1 <span style='color:black'>a1, <span style='color:black'>T2 a2<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">{<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            TR <span style='color:black'>returnValue;<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            push<span style='color:fuchsia'>(a1<span style='color:fuchsia'>);<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            push<span style='color:fuchsia'>(a2<span style='color:fuchsia'>);<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            if<span style='color:fuchsia'>(lua_pcall<span style='color:fuchsia'>(L<span style='color:fuchsia'>, 2<span style='color:fuchsia'>, 1<span style='color:fuchsia'>, 0<span style='color:fuchsia'>) != <span style='color:red'>0)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:3'>                  throw <span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>lua_tostring(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>)));<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>get(<span style='color:black'>returnValue);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:blue'>return returnValue<span style='color:fuchsia'>;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">};<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:green; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">template <<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename TR, <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">typename T1<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>LuaCall<<span style='color:black'>TR,<span style='color:black'>T1,<span style='color:black'>NullT,<span style='color:black'>NullT,<span style='color:black'>NullT> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>: public <span style='color:black'>Duo<<span style='color:black'>TR,<span style='color:black'>T1> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>, public <span style='color:black'>LuaCallBase<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCall(<span style='color:black'>lua_State *<span style='color:black'>L, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">: LuaCallBase<span style='color:fuchsia'>(L<span style='color:fuchsia'>, functionName<span style='color:fuchsia'>)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      TR <span style='color:black'>call(<span style='color:black'>T1 a1<span style='color:fuchsia'>)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            TR <span style='color:black'>returnValue;<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            push<span style='color:fuchsia'>(a1<span style='color:fuchsia'>);<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            if<span style='color:fuchsia'>(lua_pcall<span style='color:fuchsia'>(L<span style='color:fuchsia'>, 1<span style='color:fuchsia'>, 1<span style='color:fuchsia'>, 0<span style='color:fuchsia'>) != <span style='color:red'>0)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:3'>                  throw <span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>lua_tostring(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>)));<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">}<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            get<span style='color:fuchsia'>(returnValue<span style='color:fuchsia'>);<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            return returnValue;<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">};<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:blue;mso-no-proof:yes'="">template<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""> <span style='color:fuchsia'><typename <span style='color:black'>TR><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>LuaCall<<span style='color:black'>TR,<span style='color:black'>NullT,<span style='color:black'>NullT,<span style='color:black'>NullT,<span style='color:black'>NullT> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>: public <span style='color:black'>Duo<<span style='color:black'>TR,<span style='color:black'>NullT> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>, public <span style='color:black'>LuaCallBase<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCall(<span style='color:black'>lua_State *<span style='color:black'>L, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">: LuaCallBase<span style='color:fuchsia'>(L<span style='color:fuchsia'>, functionName<span style='color:fuchsia'>)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'=""><o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      TR <span style='color:black'>call(<span style='color:blue'>void)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>TR returnValue<span style='color:fuchsia'>;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:blue;mso-no-proof:yes'="">if<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">(lua_pcall(<span style='font-size:10.0pt;font-family:"courier new";color:black;mso-no-proof: yes'="">L, 0<span style='color:fuchsia'>, 1<span style='color:fuchsia'>, 0<span style='color:fuchsia'>) != <span style='color:red'>0)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            {<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:3'>                  throw <span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>std::<span style='color:black'>string(<span style='color:black'>lua_tostring(<span style='color:black'>L, <span style='color:fuchsia'>-1<span style='color:fuchsia'>)));<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:black'>get(<span style='color:black'>returnValue);<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:blue'>return returnValue<span style='color:fuchsia'>;<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">};<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">template <><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">class  <span style='color:black'>LuaCall<<span style='color:black'>NullT,<span style='color:black'>NullT,<span style='color:black'>NullT,<span style='color:black'>NullT,<span style='color:black'>NullT> <o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>: public <span style='color:black'>LuaCallBase<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes">{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:blue; mso-ansi-language:EN-US;mso-no-proof:yes">public:<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:black'>LuaCall(<span style='color:black'>lua_State *<span style='color:black'>L, <span style='color:blue'>const std<span style='color:fuchsia'>::string<span style='color:fuchsia'>& functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='color:fuchsia'>: LuaCallBase<span style='color:fuchsia'>(L<span style='color:fuchsia'>, functionName<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>{<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:fuchsia'>}<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";color:fuchsia; mso-ansi-language:EN-US;mso-no-proof:yes"><o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='color:blue'>void call<span style='color:fuchsia'>(void<span style='color:fuchsia'>)<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">      <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">{<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            if<span style='color:fuchsia'>(lua_pcall<span style='color:fuchsia'>(L<span style='color:fuchsia'>, 0<span style='color:fuchsia'>, 0<span style='color:fuchsia'>, 0<span style='color:fuchsia'>) != <span style='color:red'>0)<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:2'>            {<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">                  <span style='color:blue'>throw std<span style='color:fuchsia'>::string<span style='color:fuchsia'>(std<span style='color:fuchsia'>::string<span style='color:fuchsia'>(lua_tostring<span style='color:fuchsia'>(L<span style='color:fuchsia'>, -<span style='color:red'>1)));<o:p>

<span lang=en-us style="font-size:10.0pt;font-family:"Courier New";mso-ansi-language: EN-US;mso-no-proof:yes">            <span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">}<o:p>

<span style='font-size:10.0pt;font-family:"courier new";mso-no-proof:yes'=""><span style='mso-tab-count:1'>      }<o:p>

<span style='font-size:10.0pt;font-family:"courier new";color:fuchsia;mso-no-proof: yes'="">};<o:p>

Bibliography
Roberto Ierusalimschy
Programming in Lua – 2nd ed. (http://www.inf.puc-rio.br/~roberto/pil2/)
ISBN 85-903798-2-5

David Vandevoorde - Nicolai M. Josuttis
C++ Templates - The Complete Guide
ISBN 0-201-73484-2
Lua.org
http://www.lua.org/
Mailing list
http://www.lua.org/lua-l.html
Community
http://www.lua.org/community.html
Embeddable scripting with Lua
http://www-128.ibm.com/developerworks/linux/library/l-lua.html
The Web Links listed here may not be valid in the future.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Renato Tegon Forti
Systems Engineer
Brazil Brazil
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
Questionhelp Pin
steven84414-Jun-13 17:32
membersteven84414-Jun-13 17:32 
Generalwell done! Pin
dled30-Aug-12 8:18
memberdled30-Aug-12 8:18 
GeneralRe: well done! Pin
Renato Tegon Forti4-Sep-12 3:15
memberRenato Tegon Forti4-Sep-12 3:15 
GeneralNice. Pin
Crusiatus Black13-Nov-08 1:43
memberCrusiatus Black13-Nov-08 1:43 
GeneralLooks good ... Pin
Sceptic Mole3-Feb-07 1:15
memberSceptic Mole3-Feb-07 1:15 
GeneralRe: Looks good ... Pin
Renato T Forti3-Feb-07 4:27
memberRenato T Forti3-Feb-07 4:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170626.1 | Last Updated 2 Feb 2007
Article Copyright 2007 by Renato Tegon Forti
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid