On Sat, Dec 24, 2011 at 09:26:13AM +0200, Kalle Olavi Niemitalo wrote:
> Because supporting exceptions only in liblua5.1.so and not in
> liblua5.1.a seems too risky (what happens when someone links with
> -static), I guess there should be separate C++ variants of both,
> like you already implemented, except with unmangled public symbols.

Please try the attached patch, I'm planning to upload this to unstable
as soon as possible. I've also added one more test to your test file,
and now it seems to be able to require C modules. Also note the include
<lua.hpp> that adds extern "C" and includes also auxiliary lua headers.

cheers
-- 
Enrico Tassi

Attachment: lua5.1_5.1.4-12.debian.tar.gz
Description: Binary data

Format: 3.0 (quilt)
Source: lua5.1
Binary: lua5.1-doc, lua5.1, liblua5.1-0-dev, liblua5.1-0, liblua5.1-0-dbg
Architecture: any all
Version: 5.1.4-12
Maintainer: John V. Belmonte <jbelmo...@debian.org>
Uploaders: Enrico Tassi <gareuselesi...@debian.org>
Homepage: http://www.lua.org
Standards-Version: 3.9.2
Vcs-Browser: http://svn.debian.org/viewsvn/pkg-lua/packages/lua5.1
Vcs-Svn: svn://svn.debian.org/pkg-lua/packages/lua5.1
Build-Depends: debhelper (>= 8.1.3), quilt (>= 0.40), libtool, libreadline-dev
Package-List: 
 liblua5.1-0 deb libs optional
 liblua5.1-0-dbg deb debug extra
 liblua5.1-0-dev deb libdevel optional
 lua5.1 deb interpreters optional
 lua5.1-doc deb doc optional
Checksums-Sha1: 
 2b11c8e60306efb7f0734b747588f57995493db7 216679 lua5.1_5.1.4.orig.tar.gz
 ec362e3375e2799a6ea081d4bb4fd767a9ce7b38 16047 lua5.1_5.1.4-12.debian.tar.gz
Checksums-Sha256: 
 b038e225eaf2a5b57c9bcc35cd13aa8c6c8288ef493d52970c9545074098af3a 216679 
lua5.1_5.1.4.orig.tar.gz
 6098a45ec62ad1a463506c4b280df298ab63de0863ae65eac2b6effc90f90f31 16047 
lua5.1_5.1.4-12.debian.tar.gz
Files: 
 d0870f2de55d59c1c8419f36e8fac150 216679 lua5.1_5.1.4.orig.tar.gz
 6adf49ee949debde587fc50ed209cf88 16047 lua5.1_5.1.4-12.debian.tar.gz
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
#include <lua.hpp>

struct Test
{
	static int refs;
	Test()
	{
		puts("Test::Test()");
		++refs;
	}

	Test(const Test &)
	{
		puts("Test::Test(const Test &)");
		++refs;
	}

	~Test()
	{
		puts("Test::~Test()");
		--refs;
	}
};

int Test::refs = 0;

void *
alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
	if (nsize == 0)
	{
		free(ptr);
		return NULL;
	}
	else
	{
		return realloc(ptr, nsize);
	}
}

int
inner(lua_State *lua)
{
	puts("entered inner");
	Test test;
	puts("before lua_pushstring");
	lua_pushstring(lua, "just testing");
	puts("before lua_error");
	lua_error(lua);
	puts("lua_error returned; impossible");
	return 1;
}

void check_error(lua_State* lua, int error){
	switch (error)
	{
	case 0:
		puts("success");
		break;
	case LUA_ERRRUN:
		puts("LUA_ERRRUN");
		puts(lua_tostring(lua,-1));
		break;
	case LUA_ERRMEM:
		puts("LUA_ERRMEM");
		puts(lua_tostring(lua,-1));
		break;
	case LUA_ERRERR:
		puts("LUA_ERRERR");
		puts(lua_tostring(lua,-1));
		break;
	default:
		printf("error %d\n", error);
		puts(lua_tostring(lua,-1));
		break;
	}
}

int
main()
{
	puts("before lua_newstate");
	lua_State *lua = lua_newstate(alloc, NULL);
	luaL_openlibs(lua);
	puts("before dostring(require curl)");
	check_error(lua,luaL_dostring(lua,"require 'curl'"));
	puts("before calling inner");
	check_error(lua,lua_cpcall(lua, inner, NULL));
	lua_close(lua);

	if (Test::refs == 0)
	{
		printf("Test::refs == %d (OK)\n", Test::refs);
		return EXIT_SUCCESS;
	}
	else
	{
		printf("Test::refs == %d (error)\n", Test::refs);
		return EXIT_FAILURE;
	}
}

Reply via email to