I liked being able to call lua so much I made a class called luacall:

Code
/***************************************************************************
    luacall.h
    Utility class for calling lua
***************************************************************************/

#ifndef MAME_LUACALL_H
#define MAME_LUACALL_H

#pragma once

class lua_engine;

class luacall {
	public:
		static lua_engine *m_luaengine;
		static void        (lua_engine::* lualoadstringf)  (const char * astr);
		static int         (lua_engine::* luagetintvarf)   (const char * astr);
		static double      (lua_engine::* luagetdoublevarf)(const char * astr);
		static std::string (lua_engine::* luagetstringvarf)(const char * astr);

	static void lualoadstring(const char *astr) { 
			((*m_luaengine).*lualoadstringf)(astr); 
		}

	static int luagetintvar(const char *astr) {
			int retval =  ((*m_luaengine).*luagetintvarf)(astr); 
			return retval;
		}

	static double luagetdoublevar(const char *astr) {
			double retval =  ((*m_luaengine).*luagetdoublevarf)(astr); 
			return retval;
		}

	static std::string luagetstringvar(const char *astr) {
			std::string retval =  ((*m_luaengine).*luagetstringvarf)(astr); 
			return retval;
		}

}; // end class luacall  

#endif  // MAME_LUACALL_H

/***************************************************************************
    luacall.cpp
    Utility class for calling lua functions
***************************************************************************/

#include "emu.h"
#include "luacall.h"

lua_engine *luacall::m_luaengine;
void      (lua_engine::* luacall::lualoadstringf)  (const char * astr);
int         (lua_engine::* luacall::luagetintvarf)   (const char *astr);
double      (lua_engine::* luacall::luagetdoublevarf)(const char *astr);
std::string (lua_engine::* luacall::luagetstringvarf)(const char *astr);
luaengine.h:
Code
	int luagetintvar( const char *astr);
	double luagetdoublevar( const char *astr);
	std::string luagetstringvar( const char *astr);
and in luaengine.cpp:
Code
		luacall::m_luaengine = this; 
		luacall::lualoadstringf   = &lua_engine::load_string;
		luacall::luagetintvarf    = &lua_engine::luagetintvar;
		luacall::luagetdoublevarf = &lua_engine::luagetdoublevar;
		luacall::luagetstringvarf = &lua_engine::luagetstringvar;

	int         lua_engine::luagetintvar   ( const char *astr) { return sol()[astr]; };
	double      lua_engine::luagetdoublevar( const char *astr) { return sol()[astr]; };
	std::string lua_engine::luagetstringvar( const char *astr) { return sol()[astr]; };

so then I can do stuff like:

Code
// call lua with a string to execute:
	char buffer[128];
	snprintf(buffer,128,"if drawdot then drawdot( %f, %f ) end", xcoord, ycoord);
	luacall::lualoadstring(buffer);

// get the value from a double var:

printf("Get Double %f\n",luacall::luagetdoublevar("testdouble"));

//some indirection: get a double var from the name stored in the variable named by teststring2

printf("Testing luagetstring:   value for %s %f\n",
                luacall::luagetstringvar("teststring2").c_str(),
		luacall::luagetdoublevar(luacall::luagetstringvar(luacall::luagetstringvar("teststring2").c_str()).c_str()));

// get the value from a integer var:
printf("Get Int %d\n",luacall::luagetdoublevar("testint"));


If the variable isn't defined, it seems to just return 0, 0.0 or the empty string.

Code
Testing luagetstring:   value for  0.000000
Get Double 0.000000
Get Int 0
[MAME]> testdouble=5.29
[MAME]> testint=300
[MAME]> teststring2="orange"
[MAME]> orange="grape"
[MAME]> grape=777
[MAME]> 
Testing luagetstring:   value for orange 777.000000
Get Double 5.290000
Get Int 300