summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-05-11 10:47:44 +1200
committerOlly Betts <olly@survex.com>2023-05-17 13:23:16 +1200
commit73872022fb46bf804c0ced2b37b0d84385236cc3 (patch)
treed0c02296a931346274d393a0e2475486e38bbb93
parent59fa42a7516a73cbbb1f810603c57ad418145dd2 (diff)
downloadswig-73872022fb46bf804c0ced2b37b0d84385236cc3.tar.gz
[tcl] Add string_view support
See #1567
-rw-r--r--CHANGES.current2
-rw-r--r--Examples/test-suite/cpp17_string_view.i2
-rw-r--r--Examples/test-suite/tcl/cpp17_string_view_runme.tcl35
-rw-r--r--Lib/tcl/std_string_view.i2
-rw-r--r--Lib/typemaps/std_string_view.swg16
5 files changed, 55 insertions, 2 deletions
diff --git a/CHANGES.current b/CHANGES.current
index e20d72d89..a528b663c 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -30,7 +30,7 @@ Version 4.2.0 (in progress)
2023-05-08: olly
#1567 Add support for std::string_view (new in C++17) for C#, Java,
- Lua and PHP.
+ Lua, PHP and Tcl.
2023-05-08: olly
[PHP] #2544 Wrap overloaded method with both static and non-static
diff --git a/Examples/test-suite/cpp17_string_view.i b/Examples/test-suite/cpp17_string_view.i
index 864cc97eb..a1d3ea9cc 100644
--- a/Examples/test-suite/cpp17_string_view.i
+++ b/Examples/test-suite/cpp17_string_view.i
@@ -1,5 +1,5 @@
%module cpp17_string_view
-#if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP
+#if defined SWIGCSHARP || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP || defined SWIGTCL
%include <std_string_view.i>
// throw is invalid in C++17 and later, only SWIG to use it
diff --git a/Examples/test-suite/tcl/cpp17_string_view_runme.tcl b/Examples/test-suite/tcl/cpp17_string_view_runme.tcl
new file mode 100644
index 000000000..a63c25ee8
--- /dev/null
+++ b/Examples/test-suite/tcl/cpp17_string_view_runme.tcl
@@ -0,0 +1,35 @@
+
+if [ catch { load ./cpp17_string_view[info sharedlibextension] cpp17_string_view} err_msg ] {
+ puts stderr "Could not load shared object:\n$err_msg"
+}
+
+test_value "Fee"
+
+if {[test_value "Fi"] != "Fi"} { error "bad test_value"}
+
+test_const_reference "Fo"
+
+if {[test_const_reference "Fum"] != "Fum"} { error "bad test_const_reference"}
+
+set stringPtr [test_pointer_out]
+
+test_pointer $stringPtr
+
+set stringPtr [test_const_pointer_out]
+
+test_const_pointer $stringPtr
+
+set stringPtr [test_reference_out]
+
+test_reference $stringPtr
+
+# Global variables
+if {$ConstGlobalString != "const global string"} { error "bad ConstGlobalString_get"}
+
+# Member variables
+Structure s
+if {[s cget -ConstMemberString] != "const member string"} { error "bad ConstMemberString"}
+
+if {$Structure_ConstStaticMemberString != "const static member string"} { error "bad ConstStaticMemberString"}
+
+test_const_reference_returning_void "foo"
diff --git a/Lib/tcl/std_string_view.i b/Lib/tcl/std_string_view.i
new file mode 100644
index 000000000..9d922bccd
--- /dev/null
+++ b/Lib/tcl/std_string_view.i
@@ -0,0 +1,2 @@
+%include <typemaps/std_string_view.swg>
+
diff --git a/Lib/typemaps/std_string_view.swg b/Lib/typemaps/std_string_view.swg
new file mode 100644
index 000000000..eee86306b
--- /dev/null
+++ b/Lib/typemaps/std_string_view.swg
@@ -0,0 +1,16 @@
+//
+// string_view
+//
+
+
+%include <typemaps/std_strings.swg>
+
+%fragment("<string_view>");
+
+namespace std
+{
+ %naturalvar string_view;
+ class string_view;
+}
+
+%typemaps_std_string(std::string_view, char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, %checkcode(STRINGVIEW));