title: PostgreSQL and pllua
body: <p>I'm trying to build the pllua module but I'm having some trouble.</p>
  
  <p>I think that the problem is on the wrong PostgreSQL version but I'm not sure, I'd be grateful if someone could help me.</p>
  
  <p>Postgres location: <strong>/opt/PostgreSQL/9.3/bin</strong>  (is the enterpricedb version without support)</p>
  
  <p>Lua location: <strong>/opt/myLua</strong> (build with luaDist)</p>
  
  <pre><code>root@lua:/opt/BootstrapLuaDist/LuaDist/bin# ./luadist /opt/myLua/ list
  
  Installed modules:
  ==================
  
    bit32-5.2.0   (Ubuntu-x86_64)  [provided by luajit-2.0.3]
    lua-5.1.5 (Ubuntu-x86_64)  [provided by luajit-2.0.3]
    luaffi-1.0    (Ubuntu-x86_64)  [provided by luajit-2.0.3]
    luafilesystem-1.6.2   (Ubuntu-x86_64)
    luajit-2.0.3  (Ubuntu-x86_64)
    luasocket-3.0-rc1 (Ubuntu-x86_64)
    srlua-5.1 (Ubuntu-x86_64)
    zlib-1.2.6    (Ubuntu-x86_64)
  </code></pre>
  
  <p>I've modified the pllua makefile:</p>
  
  <pre><code># Makefile for PL/Lua
  # $Id: Makefile,v 1.12 2009/09/20 14:20:48 carvalho Exp $
  
  # Lua specific
  
  # General
  #LUAINC = -I/usr/local/include
  #LUALIB = -L/usr/local/lib -llua
  
  # LuaJIT
  #LUAINC = -I/usr/local/include/luajit-2.0
  #LUALIB = -L/usr/local/lib -lluajit-5.1
  
  #myLuaJit 2.0.3
  LUAINC= -I/opt/myLua/include
  LUALIB = -L/op/myLua/lib -lliblua
  
  
  # Debian/Ubuntu
  #LUAINC = -I/usr/include/lua5.1
  #LUALIB = -llua5.1
  
  # Fink
  #LUAINC = -I/sw/include -I/sw/include/postgresql
  #LUALIB = -L/sw/lib -llua
  
  # Lua for Windows
  #LUAINC = -IC:/PROGRA~1/Lua/5.1/include
  #LUALIB = -LC:/PROGRA~1/Lua/5.1/lib -llua5.1
  
  
  # no need to edit below here
  MODULE_big = pllua
  EXTENSION = pllua
  DATA = pllua--1.0.sql
  #DATA_built = pllua.sql
  
  REGRESS = plluatest
  OBJS = pllua.o plluaapi.o plluaspi.o
  PG_CPPFLAGS = $(LUAINC)
  SHLIB_LINK = $(LUALIB)
  
  #PG_CONFIG = /usr/local/pgsql/bin/pg_config
  PG_CONFIG = /opt/PostgreSQL/9.3/bin/pg_config
  #PG_CONFIG = pg_config
  PGXS := $(shell $(PG_CONFIG) --pgxs)
  include $(PGXS)
  </code></pre>
  
  <p>but the copilation rise an error and warnings:</p>
  
  <pre><code>root@lua:/opt/pllua-1.0# make
  gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I/opt/myLua/include -I. -I. -I/opt/PostgreSQL/9.3/include/postgresql/server -I/opt/PostgreSQL/9.3/include/postgresql/internal -D_GNU_SOURCE -I/opt/local/20140108/fc7f8f12-7861-11e3-aaff-000c29d23b02/include/libxml2  -I/usr/local/include/libxml2 -I/usr/local/include  -c -o pllua.o pllua.c
  gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I/opt/myLua/include -I. -I. -I/opt/PostgreSQL/9.3/include/postgresql/server -I/opt/PostgreSQL/9.3/include/postgresql/internal -D_GNU_SOURCE -I/opt/local/20140108/fc7f8f12-7861-11e3-aaff-000c29d23b02/include/libxml2  -I/usr/local/include/libxml2 -I/usr/local/include  -c -o plluaapi.o plluaapi.c
  In file included from plluaapi.c:8:0:
  rowstamp.h: In function ‘rowstamp_set’:
  rowstamp.h:26:2: warning: implicit declaration of function ‘HeapTupleHeaderGetXmin’ [-Wimplicit-function-declaration]
    stamp-&gt;xmin = HeapTupleHeaderGetXmin(tup-&gt;t_data);
    ^
  plluaapi.c: At top level:
  plluaapi.c:41:3: error: unknown type name ‘int2’
     int2 len;
     ^
  plluaapi.c: In function ‘luaP_gettypeinfo’:
  plluaapi.c:149:5: warning: implicit declaration of function ‘GETSTRUCT’ [-Wimplicit-function-declaration]
       typeinfo = (Form_pg_type) GETSTRUCT(type);
       ^
  plluaapi.c:149:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       typeinfo = (Form_pg_type) GETSTRUCT(type);
                  ^
  plluaapi.c: In function ‘luaP_modinit’:
  plluaapi.c:350:11: warning: implicit declaration of function ‘heap_getattr’ [-Wimplicit-function-declaration]
             lua_pushstring(L, text2string(heap_getattr(SPI_tuptable-&gt;vals[i],
             ^
  plluaapi.c: In function ‘luaP_newfunction’:
  plluaapi.c:637:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     procst = (Form_pg_proc) GETSTRUCT(proc);
              ^
  plluaapi.c: In function ‘luaP_pusharray’:
  plluaapi.c:753:9: warning: implicit declaration of function ‘fetch_att’ [-Wimplicit-function-declaration]
           luaP_pushdatum(L, fetch_att(*p, ti-&gt;byval, ti-&gt;len), typeelem);
           ^
  plluaapi.c:755:9: warning: implicit declaration of function ‘att_addlength_pointer’ [-Wimplicit-function-declaration]
           *p = att_addlength_pointer(*p, ti-&gt;len, *p);
           ^
  plluaapi.c:755:12: warning: assignment makes pointer from integer without a cast [enabled by default]
           *p = att_addlength_pointer(*p, ti-&gt;len, *p);
              ^
  plluaapi.c:756:9: warning: implicit declaration of function ‘att_align_nominal’ [-Wimplicit-function-declaration]
           *p = (char *) att_align_nominal(*p, ti-&gt;align);
           ^
  plluaapi.c:756:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
           *p = (char *) att_align_nominal(*p, ti-&gt;align);
                ^
  plluaapi.c: In function ‘luaP_toarray’:
  plluaapi.c:954:13: warning: implicit declaration of function ‘store_att_byval’ [-Wimplicit-function-declaration]
               store_att_byval(*p, PointerGetDatum(v), ti-&gt;len);
               ^
  plluaapi.c: In function ‘luaP_todatum’:
  plluaapi.c:1047:15: warning: implicit declaration of function ‘heap_form_tuple’ [-Wimplicit-function-declaration]
                 dat = PointerGetDatum(SPI_returntuple(heap_form_tuple(ti-&gt;tupdesc,
                 ^
  plluaapi.c:1047:15: warning: passing argument 1 of ‘SPI_returntuple’ makes pointer from integer without a cast [enabled by default]
  In file included from pllua.h:18:0,
                   from plluaapi.c:7:
  /opt/PostgreSQL/9.3/include/postgresql/server/executor/spi.h:113:24: note: expected ‘HeapTuple’ but argument is of type ‘int’
   extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
                          ^
  make: *** [plluaapi.o] Error 1
  </code></pre>
  
  <p>Thanks a lot</p>
  
  ### -- update ----
  
  <p>I fixed (only in part) the problem. Dowloaded postgreSQL 9.2 from enterpricedb, now compilation is fine and pllua.so is installed in /opt/PostgreSQL/9.2/lib/postgresql.</p>
  
  <p>When I run : root@lua:/opt/PostgreSQL/9.2/bin# ./psql -U postgres -p 5435 -c "CREATE EXTENSION pllua" postgres</p>
  
  <p>it raises an error:</p>
  
  <p>ERROR: could not load library "/opt/PostgreSQL/9.2/lib/postgresql/pllua.so": /opt/PostgreSQL/9.2/lib/postgresql/pllua.so: undefined symbol: luaopen_math</p>
  
  <p>Now what's the problem with luaopen_math ? May be I need to load some luaJit library before compilation ?</p>