Sign in to follow this  

Grabbing output from lua script

Recommended Posts


I 've got the following code
extern "C"
#include "lua/lua.h"
#include "lua/lauxlib.h"
#include "luabind/luabind.hpp"
#include <iostream>
using namespace std;
void teller()
int i = 0;
cout << i << ",";

int main()
//create a lua state
lua_State* pLua = lua_open();

//open luabind

/* Register functions and classes with luabind here */
luabind::def("teller", &teller)

/* load and run the script here */

luaL_dofile(pLua, "script1.lua");

//luaL_dostring(pLua, "teller()");

//tidy up

return 0;

print("[lua]: About to call the C++ teller() function")

If I uncomment //luaL_dostring(pLua, "teller()"); , then i get the output from the teller() function in my console window,
If I use luaL_dofile(pLua, "script1.lua"); , then i dont get anything in my console window, just "process returned 0, 0x0)

Im using lua 5.1.4 & luabind 0.9.1

Anyone can tell me how to grab the output from a .lua file that was executed from inside c++?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this