Call Lua table function from C++ w/ self in function
<p>My goal is to simply call a table function from C++ that uses 'self' inside of the function to access fields and functions of that table. I keep getting the lovely 'attempt to call a nill value (local self)' on the line that has 'self.name'. Below is my Lua script.</p>

<pre><code>Foo = { name = 'Foo' }

function Foo:OnUpdate()
  print('In OnUpdate in Lua')
  print(self.name)
end
</code></pre>

<p>Below is my C++ code (ignoring any error handling for now).</p>

<pre><code>lua_State* L = luaL_newstate();
luaL_openlibs(L);
luaL_dofile(L, "foo.lua");
lua_getglobal(L, "Foo");
lua_getfield(L, -1, "OnUpdate");
lua_pcall(L, 0, 0, 0);
</code></pre>

<p>When 'lua_pcall' is called, I see 'In OnUpdate in Lua' in the CLI, but never 'Foo'. If I check the error from 'lua_pcall' I get the error message mentioned above. Am I missing a certain Lua C API function prior to calling 'lua_pcall'? I am aware of the '.' vs. ':' in lua for utilizing 'self'. If I add a call in the Lua script like 'Foo:Update()', everything works perfectly. This has got me stumped.</p>