From c8cb14d9de7f95b196a605750e813d4661a5ca0f Mon Sep 17 00:00:00 2001 From: cameronrich Date: Thu, 14 Jun 2007 23:36:01 +0000 Subject: [PATCH] improvements to Lua binding git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@108 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- bindings/generate_SWIG_interface.pl | 25 ++++++++++++++++++++++--- bindings/lua/Makefile | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bindings/generate_SWIG_interface.pl b/bindings/generate_SWIG_interface.pl index 653829ebf..b1fbb3981 100755 --- a/bindings/generate_SWIG_interface.pl +++ b/bindings/generate_SWIG_interface.pl @@ -37,11 +37,17 @@ sub transformSignature $line =~ s/const uint8_t \*(\w+)/const signed char $1\[\]/g; $line =~ s/uint8_t/signed char/g; } - else + elsif ($ARGV[0] eq "-perl") { $line =~ s/const uint8_t \*(\w+)/const unsigned char $1\[\]/g; $line =~ s/uint8_t/unsigned char/g; } + else # lua + { + $line =~ s/const uint8_t \*session_id/const unsigned char session_id\[\]/g; + $line =~ s/const uint8_t \*\w+/unsigned char *INPUT/g; + $line =~ s/uint8_t/unsigned char/g; + } } return $line; @@ -144,8 +150,8 @@ open(DATA_IN, $data_file) || die("Could not open file ($data_file)!"); open(DATA_OUT, ">$interfaceFile") || die("Cannot Open File"); # -# I wish I could say it was easy to generate the Perl/Java bindings, but each -# had their own set of challenges... :-(. +# I wish I could say it was easy to generate the Perl/Java/Lua bindings, +# but each had their own set of challenges... :-(. # print DATA_OUT << "END"; %module $module\n @@ -317,6 +323,9 @@ JNIEXPORT jint JNICALL Java_axTLSj_axtlsjJNI_getFd(JNIEnv *env, jclass jcls, job /* Some SWIG magic to make the API a bit more Lua friendly */ #ifdef SWIGLUA +SWIG_NUMBER_TYPEMAP(unsigned char); +SWIG_TYPEMAP_NUM_ARR(uchar,unsigned char); + /* for ssl_session_id() */ %typemap(out) const unsigned char * { int i; @@ -328,6 +337,7 @@ JNIEXPORT jint JNICALL Java_axTLSj_axtlsjJNI_getFd(JNIEnv *env, jclass jcls, job SWIG_arg++; } +/* for ssl_read() */ %typemap(in) unsigned char **in_data (unsigned char *buf) { \$1 = &buf; } @@ -343,6 +353,15 @@ JNIEXPORT jint JNICALL Java_axTLSj_axtlsjJNI_getFd(JNIEnv *env, jclass jcls, job SWIG_arg++; } } + +/* for ssl_client_new() */ +%typemap(in) const unsigned char session_id[] { + if(!lua_isnumber(L,\$input)) + \$1 = NULL; + else + \$1 = SWIG_get_uint_num_array_fixed(L,\$input, SSL_SESSION_ID_SIZE); +} + #endif END diff --git a/bindings/lua/Makefile b/bindings/lua/Makefile index d256c7ddf..69c5c7b15 100644 --- a/bindings/lua/Makefile +++ b/bindings/lua/Makefile @@ -36,6 +36,9 @@ CONFIG_HOME=$(AXTLS_HOME)/config OBJ:=axTLSl_wrap.o include ../../config/makefile.post +# there are a few static functions that aren't used +CFLAGS += -funit-at-a-time + # libaxtls has to be linked in as a single object for this (TODO: see if this is completely necessary) $(TARGET) : $(OBJ) $(LD) $(LDFLAGS) -L$(CONFIG_LUA_CORE)/lib $(LDSHARED) -o $@ $(OBJ) ../../$(STAGE)/libaxtls.a -llua