# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../lua-curses/compile.patch
# Copyright (C) 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# This patch file is dual-licensed. It is available under the license the
# patched project is licensed under, as long as it is an OpenSource license
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
# of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# --- SDE-COPYRIGHT-NOTE-END ---

diff -ur lcurses-0.1-devel/Makefile lcurses-0.1-devel-t2/Makefile
--- lcurses-0.1-devel/Makefile	2004-08-29 22:22:05.000000000 +0200
+++ lcurses-0.1-devel-t2/Makefile	2006-02-12 23:08:39.000000000 +0100
@@ -5,19 +5,25 @@
 TMP=/tmp
 
 # change these to reflect your Lua installation
-LUA=../lua-5.0.2
-LUAINC= $(LUA)/include
-LUALIB= $(LUA)/lib
-LUABIN= $(LUA)/bin
+LUA    = $(shell lua-config --prefix)
+LUAINC = $(shell lua-config --includedir)
+LUALIB = $(shell lua-config --libdir)
+LUABIN = lua
 #LUABIN= /mingw/bin
 
+LUALIBDIR = $(shell lua-config --pkglibdir)
+LUADATADIR =$(shell lua-config --pkgdatadir)
+
+NCURSESINC=-I/usr/include
+NCURSESLIB=-lpanel -lncurses
+
 # no need to change anything below here
-SHFLAGS= #-fPIC
+SHFLAGS= -fPIC
 CFLAGS= $(INCS) $(DEFS) $(WARN) $(SHFLAGS) -O2
-DEFS= # -DDEBUG
-WARN= -Wall -Werror -ansi #-ansi -pedantic -Wall
-INCS= -I$(LUAINC) #-I../curses
-LIBS= -L$(LUALIB) -lpanel -lcurses #../curses/panel.a ../curses/pdcurses.a -llualib -llua
+DEFS= -DINCLUDEPANEL
+WARN= -Wall -Werror -ansi
+INCS= -I$(LUAINC) $(NCURSESINC)
+LIBS= -L$(LUALIB) $(NCURSESLIB)
 
 MYNAME= curses
 MYLIB= l$(MYNAME)
@@ -37,6 +43,10 @@
 	cui.lua cui.ctrls.lua testcui.lua \
 	firework.lua interp.lua
 
+INSTALL = install
+INSTALL_DATA = $(INSTALL) -m 644
+INSTALL_EXEC = $(INSTALL) -m 755
+
 all: $T
 
 lua: lcurses.c lua.c
@@ -64,3 +74,10 @@
 	@rm -fr $(TMP)/$(MYLIB)-$(VER)
 	@lsum $(TARFILE) $(DISTDIR)/md5sums.txt
 	@echo 'Done.'
+
+install: $T
+	$(INSTALL_EXEC) -d $(DESTDIR)$(LUALIBDIR)/
+	$(INSTALL_EXEC) -d $(DESTDIR)$(LUADATADIR)/cui/
+	$(INSTALL_EXEC) lcurses.so $(DESTDIR)$(LUALIBDIR)/
+	$(INSTALL_DATA) cui.lua curses.lua $(DESTDIR)$(LUADATADIR)/
+	$(INSTALL_DATA) cui/*.lua $(DESTDIR)$(LUADATADIR)/cui/
diff -ur lcurses-0.1-devel/cui/__core.lua lcurses-0.1-devel-t2/cui/__core.lua
--- lcurses-0.1-devel/cui/__core.lua	2004-08-27 10:19:45.000000000 +0200
+++ lcurses-0.1-devel-t2/cui/__core.lua	2006-02-10 03:19:54.000000000 +0100
@@ -222,8 +222,7 @@
 
 --[[ load curses binding ]------------------------------------------------]]
 
-require('requirelib')
-local curses = requirelib('lcurses', 'luaopen_curses', true)
+local curses = require('lcurses')
 
 
 --[[ local utils ]--------------------------------------------------------]]
diff -ur lcurses-0.1-devel/cui/memory.lua lcurses-0.1-devel-t2/cui/memory.lua
--- lcurses-0.1-devel/cui/memory.lua	2004-05-22 19:17:26.000000000 +0200
+++ lcurses-0.1-devel-t2/cui/memory.lua	2006-02-10 14:03:03.000000000 +0100
@@ -55,7 +55,7 @@
     local w = self:window()
     local str = _cui.new_chstr(self.size.x)
     local t, l = gcinfo()
-    local info = t..':'..l
+    local info = t..':'..(l or "nil")
     local pad = self.size.x - string.len(info)
     str:set_str(0, ' ', self.color, pad)
     str:set_str(pad, info, self.color)
diff -ur lcurses-0.1-devel/cui.lua lcurses-0.1-devel-t2/cui.lua
--- lcurses-0.1-devel/cui.lua	2004-05-22 19:04:45.000000000 +0200
+++ lcurses-0.1-devel-t2/cui.lua	2006-02-10 03:17:59.000000000 +0100
@@ -3,4 +3,4 @@
 assert(not cui, 'library already loaded!?')
 
 -- load the cui system
-require 'cui/__core.lua'
+require 'cui/__core'
diff -ur lcurses-0.1-devel/curses.lua lcurses-0.1-devel-t2/curses.lua
--- lcurses-0.1-devel/curses.lua	2004-07-22 21:13:42.000000000 +0200
+++ lcurses-0.1-devel-t2/curses.lua	2006-02-10 03:18:40.000000000 +0100
@@ -13,6 +13,5 @@
 
 --]]------------------------------------------------------------------------
 
-require('requirelib')
+require('lcurses')
 
-curses = requirelib('lcurses', 'luaopen_curses', true)
diff -ur lcurses-0.1-devel/lcurses.c lcurses-0.1-devel-t2/lcurses.c
--- lcurses-0.1-devel/lcurses.c	2004-08-29 22:22:05.000000000 +0200
+++ lcurses-0.1-devel-t2/lcurses.c	2006-02-10 13:28:48.000000000 +0100
@@ -649,14 +649,13 @@
 static int lc_initscr(lua_State *L)
 {
     WINDOW *w;
-
     /* initialize curses */
     w = initscr();
 
     /* no longer used, so clean it up */
     lua_pushstring(L, RIPOFF_TABLE);
     lua_pushnil(L);
-    lua_settable(L, LUA_REGISTRYINDEX);
+    lua_settable(L, LUA_REGISTRYINDEX); 
 
     /* failed to initialize */
     if (w == NULL)
@@ -664,10 +663,10 @@
 
     #if defined(PDCURSES)
     /* PDCurses does not enable echo at startup! */
-    echo();
+    echo(); 
     /* so we don't hang up after user presses a
        modifier key until a normal key is pressed */
-    PDC_return_key_modifiers(TRUE);
+    PDC_return_key_modifiers(TRUE); 
     /*PDC_save_key_modifiers(TRUE);*/
     #endif
 
@@ -677,7 +676,7 @@
     #endif
 
     /* return stdscr - main window */
-    lcw_new(L, w);
+    lcw_new(L, w); 
 
     /* save main window on registry */
     lua_pushstring(L, STDSCR_REGISTRY);
@@ -687,10 +686,10 @@
     /* setup curses constants - curses.xxx numbers */
     register_curses_constants(L);
     /* setup ascii map table */
-    init_ascii_map();
+    init_ascii_map(); 
 
     /* install cleanup handler to help in debugging and screen trashing */
-    atexit(cleanup);
+    atexit(cleanup); 
     /* disable interrupt signal
     signal(SIGINT, SIG_IGN);
     signal(SIGBREAK, SIG_IGN);
@@ -2350,7 +2349,7 @@
 };
 
 
-int luaopen_curses(lua_State *L)
+int luaopen_lcurses(lua_State *L)
 {
     /*
     ** create new metatable for window objects
@@ -2379,7 +2378,7 @@
     ** create global table with curses methods/variables/constants
     */
     lua_newtable(L);
-    #if 0
+    #if 1
     lua_pushliteral(L, "curses");
     lua_pushvalue(L, -2);
     lua_settable(L, LUA_GLOBALSINDEX);
@@ -2387,6 +2386,35 @@
     lua_pushvalue(L, -1);
     luaL_openlib(L, NULL, curseslib, 1);
 
+
+
+
+#ifdef INCLUDEPANEL
+    /* metatable with used panels and associated windows */
+    lua_newtable(L);
+
+    /*
+    ** create new metatable for window objects
+    */
+    luaL_newmetatable(L, PANELMETA);
+    lua_pushliteral(L, "__index");
+    lua_pushvalue(L, -2);               /* push metatable */
+    lua_rawset(L, -3);                  /* metatable.__index = metatable */
+
+    lua_pushvalue(L, -2);               /* upvalue table */
+    luaL_openlib(L, NULL, panellib, 1);
+
+    lua_pop(L, 1);                      /* remove metatable from stack */
+
+    /*
+    ** create global table with curses methods/variables/constants
+    */
+    lua_pop(L, 1);
+    luaL_openlib(L, "curses", cursespanellib, 1);
+#endif
+
+
+
     return 1;
 }
 
Only in lcurses-0.1-devel-t2/: lcurses.o
Only in lcurses-0.1-devel-t2/: lcurses.so
diff -ur lcurses-0.1-devel/lpanel.c lcurses-0.1-devel-t2/lpanel.c
--- lcurses-0.1-devel/lpanel.c	2003-12-31 05:27:04.000000000 +0100
+++ lcurses-0.1-devel-t2/lpanel.c	2006-02-10 13:26:43.000000000 +0100
@@ -328,6 +328,7 @@
     {NULL, NULL}
 };
 
+#ifndef INCLUDEPANEL
 /*
 ** TODO: add upvalue table with lightuserdata keys and weak keyed
 ** values containing WINDOWS and PANELS used in above functions
@@ -357,3 +358,4 @@
     luaL_openlib(L, "curses", cursespanellib, 1);
     return 1;
 }
+#endif
diff -ur lcurses-0.1-devel/test.lua lcurses-0.1-devel-t2/test.lua
--- lcurses-0.1-devel/test.lua	2004-08-29 22:22:05.000000000 +0200
+++ lcurses-0.1-devel-t2/test.lua	2006-02-10 14:16:27.000000000 +0100
@@ -1,5 +1,4 @@
---require('bit')
-
+require('curses')
 local _topw = {}
 local top_lines = 10
 curses.slk_init(2)
@@ -122,7 +121,7 @@
     curses.doupdate()
 end
 
-local ok, msg = xpcall(_main, _TRACEBACK)
+local ok, msg = xpcall(_main, debug.traceback)
 
 curses.done()
 
diff -ur lcurses-0.1-devel/testcui.lua lcurses-0.1-devel-t2/testcui.lua
--- lcurses-0.1-devel/testcui.lua	2004-08-27 01:28:57.000000000 +0200
+++ lcurses-0.1-devel-t2/testcui.lua	2006-02-10 13:29:53.000000000 +0100
@@ -224,7 +224,7 @@
     app:close()
 end
 
-local ok, msg = xpcall(run, _TRACEBACK)
+local ok, msg = xpcall(run, debug.traceback)
 
 if (not ok) then
     if (not cui.isdone()) then