Mark Gossage patch 1295168
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7470 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
dbcae3b00c
commit
39119b2d07
7 changed files with 61 additions and 34 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
# see top-level Makefile.in
|
# see top-level Makefile.in
|
||||||
class
|
class
|
||||||
|
constants
|
||||||
|
functest
|
||||||
|
pointer
|
||||||
simple
|
simple
|
||||||
variables
|
variables
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
-- This file illustrates class C++ interface generated
|
-- This file illustrates class C++ interface generated
|
||||||
-- by SWIG.
|
-- by SWIG.
|
||||||
|
|
||||||
-- importing (lua does not have a nice way to do this)
|
---- importing ----
|
||||||
loadlibrary = loadlib("example.so","Example_Init")
|
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||||
if loadlibrary == nil then
|
-- lua5.0 doesnt have a nice way to do this
|
||||||
loadlibrary = loadlib("example.dll","Example_Init")
|
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||||
|
assert(lib)()
|
||||||
|
else
|
||||||
|
-- lua 5.1 does
|
||||||
|
require('example')
|
||||||
end
|
end
|
||||||
assert(loadlibrary, "could not find dynamic libray")
|
|
||||||
loadlibrary()
|
|
||||||
|
|
||||||
----- Object creation -----
|
----- Object creation -----
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
-- file: runme.lua
|
---- importing ----
|
||||||
|
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||||
-- importing (lua does not have a nice way to do this)
|
-- lua5.0 doesnt have a nice way to do this
|
||||||
loadlibrary = loadlib("example.so","Example_Init")
|
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||||
if loadlibrary == nil then
|
assert(lib)()
|
||||||
loadlibrary = loadlib("example.dll","Example_Init")
|
else
|
||||||
|
-- lua 5.1 does
|
||||||
|
require('example')
|
||||||
end
|
end
|
||||||
assert(loadlibrary, "could not find dynamic libray")
|
|
||||||
loadlibrary()
|
|
||||||
|
|
||||||
-- Call our gcd() function
|
-- Call our gcd() function
|
||||||
print("hello world")
|
|
||||||
|
|
||||||
x = 42
|
x = 42
|
||||||
y = 105
|
y = 105
|
||||||
g = example.gcd(x,y)
|
g = example.gcd(x,y)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
-- file: example.lua
|
---- importing ----
|
||||||
|
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||||
-- importing (lua does not have a nice way to do this)
|
-- lua5.0 doesnt have a nice way to do this
|
||||||
loadlibrary = loadlib("example.so","Example_Init")
|
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||||
if loadlibrary == nil then
|
assert(lib)()
|
||||||
loadlibrary = loadlib("example.dll","Example_Init")
|
else
|
||||||
|
-- lua 5.1 does
|
||||||
|
require('example')
|
||||||
end
|
end
|
||||||
assert(loadlibrary, "could not find dynamic libray")
|
|
||||||
loadlibrary()
|
|
||||||
|
|
||||||
-- Try to set the values of some global variables
|
-- Try to set the values of some global variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -318,6 +318,15 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
|
||||||
%enddef
|
%enddef
|
||||||
#endif // SWIGCSHARP
|
#endif // SWIGCSHARP
|
||||||
|
|
||||||
|
#ifdef SWIGLUA
|
||||||
|
|
||||||
|
%{
|
||||||
|
#define SWIG_exception(a,b)\
|
||||||
|
{ lua_pushfstring(L,"%s:%s",#a,b);SWIG_fail; }
|
||||||
|
%}
|
||||||
|
|
||||||
|
#endif // SWIGLUA
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
/*
|
/*
|
||||||
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
|
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
%typemap(out) char
|
%typemap(out) char
|
||||||
%{ lua_pushfstring(L,"%c",$1); SWIG_arg++;%}
|
%{ lua_pushfstring(L,"%c",$1); SWIG_arg++;%}
|
||||||
|
|
||||||
// byref
|
// by const ref
|
||||||
%typemap(in,checkfn="lua_isstring") const char& (char temp)
|
%typemap(in,checkfn="lua_isstring") const char& (char temp)
|
||||||
%{temp = ((char*)lua_tostring(L, $input))[0]; $1=&temp;%}
|
%{temp = ((char*)lua_tostring(L, $input))[0]; $1=&temp;%}
|
||||||
|
|
||||||
|
|
@ -81,7 +81,6 @@
|
||||||
|
|
||||||
// pointers and references
|
// pointers and references
|
||||||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE*,SWIGTYPE&,SWIGTYPE[]
|
%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");%}
|
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
|
||||||
|
|
||||||
%typemap(out) SWIGTYPE*,SWIGTYPE&
|
%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
|
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
|
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,
|
%typemap(throws) int,unsigned int,signed int,
|
||||||
long,unsigned long,signed long,
|
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);
|
%{lua_pushfstring(L,"exception thrown of value %d",(long)$1);
|
||||||
SWIG_fail; %}
|
SWIG_fail; %}
|
||||||
|
|
||||||
#include "exception.h"
|
// strings are just sent as errors
|
||||||
#define SWIG_exception(a,b)\
|
%typemap(throws) char*, const char*
|
||||||
{ lua_pushfstring(L,"%s thrown:%s",#a,b);SWIG_fail; }
|
%{lua_pushstring(L,$1);SWIG_fail;%}
|
||||||
|
|
||||||
|
|
||||||
|
// anything else is sent as an object
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
%typemap(throws) SWIGTYPE
|
%typemap(throws) SWIGTYPE
|
||||||
{
|
{
|
||||||
|
|
@ -444,6 +446,17 @@ SWIGEXPORT int SWIG_init(lua_State* L)
|
||||||
return 1;
|
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 */
|
/* 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);
|
String *init_name = NewStringf("%(title)s_Init",module);
|
||||||
Printf(f_header, "#define SWIG_init %s\n", init_name);
|
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_cmd_tab, "\nstatic swig_lua_command_info swig_commands[] = {\n");
|
||||||
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
|
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue