As sbk mentioned, you'd access your variable as a member of a userdata:
print(cside.myVar) -- 5
Here is some sample code to do this using the Lua API. Its straightforward, although tedious. You'll either want to make your own code generator or using something like swig or tolua++
/* gcc -o simple simple.c -llua -lm -ldl */
#include <stdio.h>
#include "lua.h"
#include "lauxlib.h"
int myVar = 5;
int l_set( lua_State *L )
{
const char *key = luaL_checkstring(L, 2);
int val = luaL_checkint(L, 3);
if (strcmp(key, "myVar") == 0)
myVar = val;
}
int l_get( lua_State *L )
{
const char *key = luaL_checkstring(L, 2);
if (strcmp(key, "myVar") == 0)
{
lua_pushinteger(L, myVar);
return 1;
}
}
int main(int argc, char *argv[])
{
const struct luaL_Reg somemt[] =
{
{ "__index", l_get },
{ "__newindex", l_set },
{ NULL, NULL }
};
lua_State *L = luaL_newstate();
luaL_openlibs( L );
lua_newuserdata(L, sizeof(void *));
luaL_newmetatable(L, "somemt");
luaL_register( L, NULL, somemt );
lua_setmetatable(L, -2);
lua_setglobal(L, "cside");
luaL_dostring(L, "print('from Lua:', cside.myVar)");
luaL_dostring(L, "cside.myVar = 200");
printf( "from C: myVar = %d\n", myVar );
}