浏览代码

docs: Add 'Extending supported types' section to 'Basics'

Ole 9 年之前
父节点
当前提交
6543dda1f3
共有 4 个文件被更改,包括 47 次插入1 次删除
  1. 23 0
      docs/mkdocs/basics.md
  2. 23 0
      docs/output/basics/index.html
  3. 1 1
      docs/output/index.html
  4. 0 0
      docs/output/mkdocs/search_index.json

+ 23 - 0
docs/mkdocs/basics.md

@@ -38,6 +38,29 @@ std::map<K, V>                   | yes      | yes      | table
 **Note:** Some numeric types have a different size than their matching Lua type - they will be
 truncated during push or read operations.
 
+## Extending supported types
+If you are missing a type that cannot be used as a [user type](/user-types), you can add a
+specialization of [Value][luwra-value]. All you need to do is modify the following snippet for your
+type `T`.
+
+```c++
+namespace luwra {
+	template <>
+	struct Value<T> {
+		static inline
+		T read(State* state, int index) {
+			return /* Return the instance of T that you have read at the given index */;
+		}
+
+		static inline
+		size_t push(State* state, const T& value) {
+			// Push the given value on top of the stack
+			return /* Return how many values you have pushed onto the stack */;
+		}
+	};
+}
+```
+
 ## Pushing C++ values
 When pushing values onto the stack you can either use [Value&lt;T&gt;::push][luwra-value-push] or
 the more convenient [push][luwra-push].

+ 23 - 0
docs/output/basics/index.html

@@ -72,6 +72,8 @@
             
                 <li class="toctree-l3"><a href="#stack-interaction">Stack Interaction</a></li>
                 
+                    <li><a class="toctree-l4" href="#extending-supported-types">Extending supported types</a></li>
+                
                     <li><a class="toctree-l4" href="#pushing-c-values">Pushing C++ values</a></li>
                 
                     <li><a class="toctree-l4" href="#reading-lua-values">Reading Lua values</a></li>
@@ -310,6 +312,27 @@ Useful implementations are provided out of the box:</p>
 </table>
 <p><strong>Note:</strong> Some numeric types have a different size than their matching Lua type - they will be
 truncated during push or read operations.</p>
+<h2 id="extending-supported-types">Extending supported types</h2>
+<p>If you are missing a type that cannot be used as a <a href="../user-types">user type</a>, you can add a
+specialization of <a href="../reference/structluwra_1_1Value.html">Value</a>. All you need to do is modify the following snippet for your
+type <code>T</code>.</p>
+<pre><code class="c++">namespace luwra {
+    template &lt;&gt;
+    struct Value&lt;T&gt; {
+        static inline
+        T read(State* state, int index) {
+            return /* Return the instance of T that you have read at the given index */;
+        }
+
+        static inline
+        size_t push(State* state, const T&amp; value) {
+            // Push the given value on top of the stack
+            return /* Return how many values you have pushed onto the stack */;
+        }
+    };
+}
+</code></pre>
+
 <h2 id="pushing-c-values">Pushing C++ values</h2>
 <p>When pushing values onto the stack you can either use <a href="../reference/structluwra_1_1Value.html#aa376d68285606c206562b822e8187384">Value&lt;T&gt;::push</a> or
 the more convenient <a href="../reference/namespaceluwra.html#ae8e7eab11fc2cf3f258ffd81571066fa">push</a>.</p>

+ 1 - 1
docs/output/index.html

@@ -193,5 +193,5 @@ your preference.</p>
 
 <!--
 MkDocs version : 0.15.3
-Build Date UTC : 2016-05-20 20:38:19.958763
+Build Date UTC : 2016-05-20 20:49:36.625613
 -->

文件差异内容过多而无法显示
+ 0 - 0
docs/output/mkdocs/search_index.json


部分文件因为文件数量过多而无法显示