Communicating with Lua is one way. In addition to reading Lua variables from C, you can also create Lua variables from C. The process for doing so is simple: you push a value onto the stack, then tell the Lua runtime to assign that value to a variable by name.
To create a variable, use the lua_setglobal (lua_State*, const char*) function. This function returns nothing. Its first argument is the Lua state to work on, the second argument is the name of the global variable to assign. This function will pop the top value off the stack and assign it to the name of the variable specified.
Let's take the example from the last section and reverse it. This time, the variables for class, attack, and defense are going to be created in C and printed out in Lua. The C code will push all values onto the stack, then use lua_setglobal to assign them to variables...