title: send lua output to non stdout
body: <p>I have a c program running embedded Lua.  as of right now, it's just a hello world.  before moving on, though, I'd like to be able to get the lua output to be sent somewhere other than <code>stdout</code>, so that I can manipulate it in some manner.  Here's my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #include &lt;lua.h&gt;
  #include &lt;lauxlib.h&gt;
  #include &lt;lualib.h&gt;
  
  int main() {
      lua_State *luaVM = luaL_newstate();
      //char result[1024];
  
      if (luaVM == NULL) {
          printf("Error initializing lua!\n");
          return -1;
      }
      luaL_openlibs(luaVM);
      luaL_dostring(luaVM, "print(\"hello world!\")");
      //Somehow put the output into result
  
      //printf("%s\n%s\n", result, result);
  
      lua_close(luaVM);
      return 0;
  }
  </code></pre>
  
  <p>For example, I'd like to use <code>result</code>, seen in the comments, to print the result of the lua code twice.  Can this be done?</p>