Mark Gossage patch 1295168
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7470 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
92c5d2a22b
commit
afda89dc49
7 changed files with 61 additions and 34 deletions
|
|
@ -1,4 +1,7 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
constants
|
||||
functest
|
||||
pointer
|
||||
simple
|
||||
variables
|
||||
|
|
|
|||
|
|
@ -3,13 +3,15 @@
|
|||
-- This file illustrates class C++ interface generated
|
||||
-- by SWIG.
|
||||
|
||||
-- importing (lua does not have a nice way to do this)
|
||||
loadlibrary = loadlib("example.so","Example_Init")
|
||||
if loadlibrary == nil then
|
||||
loadlibrary = loadlib("example.dll","Example_Init")
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
require('example')
|
||||
end
|
||||
assert(loadlibrary, "could not find dynamic libray")
|
||||
loadlibrary()
|
||||
|
||||
----- Object creation -----
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
-- file: runme.lua
|
||||
|
||||
-- importing (lua does not have a nice way to do this)
|
||||
loadlibrary = loadlib("example.so","Example_Init")
|
||||
if loadlibrary == nil then
|
||||
loadlibrary = loadlib("example.dll","Example_Init")
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
require('example')
|
||||
end
|
||||
assert(loadlibrary, "could not find dynamic libray")
|
||||
loadlibrary()
|
||||
|
||||
-- Call our gcd() function
|
||||
print("hello world")
|
||||
|
||||
x = 42
|
||||
y = 105
|
||||
g = example.gcd(x,y)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
-- file: example.lua
|
||||
|
||||
-- importing (lua does not have a nice way to do this)
|
||||
loadlibrary = loadlib("example.so","Example_Init")
|
||||
if loadlibrary == nil then
|
||||
loadlibrary = loadlib("example.dll","Example_Init")
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
require('example')
|
||||
end
|
||||
assert(loadlibrary, "could not find dynamic libray")
|
||||
loadlibrary()
|
||||
|
||||
-- Try to set the values of some global variables
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ SWIGINTERN void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) {
|
|||
SWIGINTERN void SWIG_exception_(int code, const char *msg) {
|
||||
char msg_buf[OCAML_MSG_BUF_LEN];
|
||||
sprintf( msg_buf, "Exception(%d): %s\n", code, msg );
|
||||
failwith( msg_buf );
|
||||
failwith( msg_buf );
|
||||
}
|
||||
#define SWIG_exception(a,b) SWIG_exception_((a),(b))
|
||||
%}
|
||||
|
|
@ -318,6 +318,15 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
|
|||
%enddef
|
||||
#endif // SWIGCSHARP
|
||||
|
||||
#ifdef SWIGLUA
|
||||
|
||||
%{
|
||||
#define SWIG_exception(a,b)\
|
||||
{ lua_pushfstring(L,"%s:%s",#a,b);SWIG_fail; }
|
||||
%}
|
||||
|
||||
#endif // SWIGLUA
|
||||
|
||||
#ifdef __cplusplus
|
||||
/*
|
||||
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
|
||||
|
|
@ -330,11 +339,11 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
|
|||
catch (my_except& e) {
|
||||
...
|
||||
}
|
||||
SWIG_CATCH_STDEXCEPT // catch std::exception
|
||||
SWIG_CATCH_STDEXCEPT // catch std::exception
|
||||
catch (...) {
|
||||
SWIG_exception(SWIG_UnknownError, "Unknown exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
%{
|
||||
#include <stdexcept>
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
%typemap(out) char
|
||||
%{ lua_pushfstring(L,"%c",$1); SWIG_arg++;%}
|
||||
|
||||
// byref
|
||||
// by const ref
|
||||
%typemap(in,checkfn="lua_isstring") const char& (char temp)
|
||||
%{temp = ((char*)lua_tostring(L, $input))[0]; $1=&temp;%}
|
||||
|
||||
|
|
@ -81,7 +81,6 @@
|
|||
|
||||
// pointers and references
|
||||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE*,SWIGTYPE&,SWIGTYPE[]
|
||||
//%{if(SWIG_ConvertPtr(L,$input,(void**)(&$1),$descriptor,SWIG_POINTER_EXCEPTION) == -1) SWIG_fail; %}
|
||||
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
|
||||
|
||||
%typemap(out) SWIGTYPE*,SWIGTYPE&
|
||||
|
|
@ -353,6 +352,9 @@ Therefore I have not bothered to try doing much in this
|
|||
On top of this I an not clear on how best to do this is Lua
|
||||
|
||||
Therefore currently its just enough to get a few test cases running ok
|
||||
|
||||
note: if you wish to throw anything related to std::exception
|
||||
use %include <std_except.i> instead
|
||||
*/
|
||||
%typemap(throws) int,unsigned int,signed int,
|
||||
long,unsigned long,signed long,
|
||||
|
|
@ -364,11 +366,11 @@ Therefore currently its just enough to get a few test cases running ok
|
|||
%{lua_pushfstring(L,"exception thrown of value %d",(long)$1);
|
||||
SWIG_fail; %}
|
||||
|
||||
#include "exception.h"
|
||||
#define SWIG_exception(a,b)\
|
||||
{ lua_pushfstring(L,"%s thrown:%s",#a,b);SWIG_fail; }
|
||||
|
||||
// strings are just sent as errors
|
||||
%typemap(throws) char*, const char*
|
||||
%{lua_pushstring(L,$1);SWIG_fail;%}
|
||||
|
||||
// anything else is sent as an object
|
||||
#ifdef __cplusplus
|
||||
%typemap(throws) SWIGTYPE
|
||||
{
|
||||
|
|
@ -444,6 +446,17 @@ SWIGEXPORT int SWIG_init(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Lua 5.1 has a different name for importing libraries
|
||||
// luaopen_XXX, where XXX is the name of the module (not capitalised)
|
||||
// this function will allow Lua 5.1 to import correctly
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
SWIGEXPORT int SWIG_import(lua_State* L)
|
||||
{
|
||||
return SWIG_init(L);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
/* Note: the initialization function is closed after all code is generated */
|
||||
|
|
|
|||
|
|
@ -213,7 +213,9 @@ NEW LANGUAGE NOTE:END ************************************************/
|
|||
|
||||
String *init_name = NewStringf("%(title)s_Init",module);
|
||||
Printf(f_header, "#define SWIG_init %s\n", init_name);
|
||||
Printf(f_header, "#define SWIG_name \"%s\"\n\n", module);
|
||||
Printf(f_header, "#define SWIG_name \"%s\"\n", module);
|
||||
/* SWIG_import is a special function name for importing within Lua5.1 */
|
||||
Printf(f_header, "#define SWIG_import luaopen_%s\n\n", module);
|
||||
|
||||
Printf(s_cmd_tab, "\nstatic swig_lua_command_info swig_commands[] = {\n");
|
||||
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue