Jump to content
  • Advertisement
Sign in to follow this  
chophias

Grabbing output from lua script

This topic is 2572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

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;
for(i=0;i<10;i++)
{
cout << i << ",";
}
}

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

//open luabind
luabind::open(pLua);

/* Register functions and classes with luabind here */
luabind::module(pLua)
[
luabind::def("teller", &teller)
];

/* load and run the script here */

luaL_dofile(pLua, "script1.lua");

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

//tidy up
lua_close(pLua);

return 0;
}


script1.lua

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


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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!