One more 5.1 problem

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

One more 5.1 problem

Alexander Gladysh
Hi, all!

While trying Luabind b7 on Lua 5.1, I've got assertion on line 264 of
call_function.cpp. Same code works fine on 5.0. Am I doing something
wrong here?

    ExecuteString(
        L,
        "s = function()\n"
        "  while(true) do\n"
        "    coroutine.yield()\n"
        "  end;\n"
        "end;\n"
        "cr = coroutine.create(s)"
      );

    luabind::object cr = luabind::globals(L)["cr"];

    for(int i = 1; i < 5; ++i)
    {
      cr.push(cr.interpreter());
      lua_State * pThread = lua_tothread(cr.interpreter(), -1);
      lua_pop(cr.interpreter(), 1);
      // Assert is triggered after luabind::resume() returns.
      luabind::resume<void>(pThread, i);
    }

Thanks,
Alexander.

Full source code:

#include <iostream>

extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

#pragma warning(push, 4)
#pragma warning(disable : 4100 4675)

#include <luabind/luabind.hpp>
#include <luabind/object.hpp>

#pragma warning(pop)

std::string PopString(lua_State * L)
{
  //  Checks if there is really string on top of the string.
  //  Returns an empty string if the stack is empty.
  const char * pStr = lua_tostring(L, -1);
  if (pStr != NULL)
  {
    const std::string result(pStr);
    lua_pop(L, 1);
    return result;
  }
  return std::string();
}

void ExecuteString(lua_State * L, const std::string & script)
{
  try
  {
    if (
        luaL_loadbuffer(L, script.c_str(), script.length(), script.c_str()) ||
        lua_pcall(L, 0, 0, 0)
      )
    {
      throw PopString(L);
    }
  }
  catch (luabind::error & e)
  {
    std::string descr = PopString(e.state());
    throw (!descr.empty()) ? descr : "(No error message on stack.)";
  }
}

int main()
{
  try
  {
    lua_State * L;
    L = lua_open();
    if(!L)
      throw std::runtime_error("Failed to create Lua Virtual Machine");

    luaL_openlibs(L);

    luabind::open(L);

    ExecuteString(
        L,
        "s = function()\n"
        "  while(true) do\n"
        "    coroutine.yield()\n"
        "  end;\n"
        "end;\n"
        "cr = coroutine.create(s)"
      );

    luabind::object cr = luabind::globals(L)["cr"];

    for(int i = 1; i < 5; ++i)
    {
      cr.push(cr.interpreter());
      lua_State * pThread = lua_tothread(cr.interpreter(), -1);
      lua_pop(cr.interpreter(), 1);
      luabind::resume<void>(pThread, i);
    }
  }
  catch (std::exception & ex)
  {
    std::cout << ex.what();
  }

  return 0;
}


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user