Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiruiLi committed Sep 2, 2021
1 parent 0d4a15a commit 9e2b431
Show file tree
Hide file tree
Showing 18 changed files with 599 additions and 15 deletions.
2 changes: 1 addition & 1 deletion categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name=author content="Zhirui Li">
<meta property="og:url" content="https://zhiruili.github.io/categories/">
<link rel=canonical href=https://zhiruili.github.io/categories/><link rel=alternate type=application/atom+xml href=https://zhiruili.github.ioindex.xml title="简单易懂的现代魔法 - Zhirui Li">
<script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/zhiruili.github.io"},"articleSection":"categories","name":"Categories","headline":"Categories","description":"","inLanguage":"en-US","author":"Zhirui Li","creator":"Zhirui Li","publisher":"Zhirui Li","accountablePerson":"Zhirui Li","copyrightHolder":"Zhirui Li","copyrightYear":"2021","datePublished":"2021-08-27 00:00:00 \u002b0000 UTC","dateModified":"2021-08-27 00:00:00 \u002b0000 UTC","url":"https:\/\/zhiruili.github.io\/categories\/","keywords":[]}</script>
<script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/zhiruili.github.io"},"articleSection":"categories","name":"Categories","headline":"Categories","description":"","inLanguage":"en-US","author":"Zhirui Li","creator":"Zhirui Li","publisher":"Zhirui Li","accountablePerson":"Zhirui Li","copyrightHolder":"Zhirui Li","copyrightYear":"2021","datePublished":"2021-09-01 00:00:00 \u002b0000 UTC","dateModified":"2021-09-01 00:00:00 \u002b0000 UTC","url":"https:\/\/zhiruili.github.io\/categories\/","keywords":[]}</script>
<title>Categories</title>
<meta property="og:title" content="Categories">
<meta property="og:type" content="article">
Expand Down
2 changes: 1 addition & 1 deletion categories/index.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Categories on 简单易懂的现代魔法 - Zhirui Li</title><link>https://zhiruili.github.io/categories/</link><description>Recent content in Categories on 简单易懂的现代魔法 - Zhirui Li</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Fri, 27 Aug 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://zhiruili.github.io/categories/index.xml" rel="self" type="application/rss+xml"/><item><title>Notes</title><link>https://zhiruili.github.io/categories/notes/</link><pubDate>Fri, 27 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/categories/notes/</guid><description/></item><item><title>Articles</title><link>https://zhiruili.github.io/categories/articles/</link><pubDate>Sat, 07 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/categories/articles/</guid><description/></item><item><title>Translations</title><link>https://zhiruili.github.io/categories/translations/</link><pubDate>Wed, 17 May 2017 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/categories/translations/</guid><description/></item></channel></rss>
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Categories on 简单易懂的现代魔法 - Zhirui Li</title><link>https://zhiruili.github.io/categories/</link><description>Recent content in Categories on 简单易懂的现代魔法 - Zhirui Li</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Wed, 01 Sep 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://zhiruili.github.io/categories/index.xml" rel="self" type="application/rss+xml"/><item><title>Notes</title><link>https://zhiruili.github.io/categories/notes/</link><pubDate>Wed, 01 Sep 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/categories/notes/</guid><description/></item><item><title>Articles</title><link>https://zhiruili.github.io/categories/articles/</link><pubDate>Sat, 07 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/categories/articles/</guid><description/></item><item><title>Translations</title><link>https://zhiruili.github.io/categories/translations/</link><pubDate>Wed, 17 May 2017 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/categories/translations/</guid><description/></item></channel></rss>
14 changes: 13 additions & 1 deletion categories/notes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name=author content="Zhirui Li">
<meta property="og:url" content="https://zhiruili.github.io/categories/notes/">
<link rel=canonical href=https://zhiruili.github.io/categories/notes/><link rel=alternate type=application/atom+xml href=https://zhiruili.github.ioindex.xml title="简单易懂的现代魔法 - Zhirui Li">
<script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/zhiruili.github.io"},"articleSection":"categories","name":"Notes","headline":"Notes","description":"","inLanguage":"en-US","author":"Zhirui Li","creator":"Zhirui Li","publisher":"Zhirui Li","accountablePerson":"Zhirui Li","copyrightHolder":"Zhirui Li","copyrightYear":"2021","datePublished":"2021-08-27 00:00:00 \u002b0000 UTC","dateModified":"2021-08-27 00:00:00 \u002b0000 UTC","url":"https:\/\/zhiruili.github.io\/categories\/notes\/","keywords":[]}</script>
<script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/zhiruili.github.io"},"articleSection":"categories","name":"Notes","headline":"Notes","description":"","inLanguage":"en-US","author":"Zhirui Li","creator":"Zhirui Li","publisher":"Zhirui Li","accountablePerson":"Zhirui Li","copyrightHolder":"Zhirui Li","copyrightYear":"2021","datePublished":"2021-09-01 00:00:00 \u002b0000 UTC","dateModified":"2021-09-01 00:00:00 \u002b0000 UTC","url":"https:\/\/zhiruili.github.io\/categories\/notes\/","keywords":[]}</script>
<title>Notes</title>
<meta property="og:title" content="Notes">
<meta property="og:type" content="article">
Expand Down Expand Up @@ -50,6 +50,18 @@ <h1 class=taxonomy-term>Notes</h1>
<h1 class=site-date-catalog>2021</h1>
<div class="row posts-line">
<div class="posts-date col-xs-2">
<time datetime="2021-09-01 00:00:00 UTC">Sep 01</time>
</div>
<div class="posts-title col-xs-10">
<div class=row>
<div class=col-xs-12>
<a href=/posts/unity_with_android/>Unity 和 Android 模块交互</a>
</div>
</div>
</div>
</div>
<div class="row posts-line">
<div class="posts-date col-xs-2">
<time datetime="2021-08-27 00:00:00 UTC">Aug 27</time>
</div>
<div class="posts-title col-xs-10">
Expand Down
6 changes: 5 additions & 1 deletion categories/notes/index.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Notes on 简单易懂的现代魔法 - Zhirui Li</title><link>https://zhiruili.github.io/categories/notes/</link><description>Recent content in Notes on 简单易懂的现代魔法 - Zhirui Li</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Fri, 27 Aug 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://zhiruili.github.io/categories/notes/index.xml" rel="self" type="application/rss+xml"/><item><title>错误使用 C++ 模板特化产生的坑</title><link>https://zhiruili.github.io/posts/cpp-template-specialization/</link><pubDate>Fri, 27 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/cpp-template-specialization/</guid><description>今天在群里看到了一个错误使用 C++ 模板特化产生的坑,有点意思,这里记录一下。
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Notes on 简单易懂的现代魔法 - Zhirui Li</title><link>https://zhiruili.github.io/categories/notes/</link><description>Recent content in Notes on 简单易懂的现代魔法 - Zhirui Li</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Wed, 01 Sep 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://zhiruili.github.io/categories/notes/index.xml" rel="self" type="application/rss+xml"/><item><title>Unity 和 Android 模块交互</title><link>https://zhiruili.github.io/posts/unity_with_android/</link><pubDate>Wed, 01 Sep 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/unity_with_android/</guid><description>有时候,我们需要在 Unity 里调用一些 Android 的功能,这些功能在 Unity 中可能并没有提供接口,需要在 Android 平台上实现。此时,我们需要有一个方法来让 Android 代码和 Unity 代码互交互。这里记录一下操作方法,并提供一个工具来简化这个过程。
示例工程 下面的记录可以参考示例工程。其中,根目录是 Unity 工程,可以直接用 Unity 打开。根目录下的 AndroidSample 子目录是 Android 工程,可以用 Android Studio 打开。运行后如下图左所示,点击其中的按钮,就会触发 Unity 到 Anrdoid 的调用,在主界面上产生一个 toast,同时,触发一次从 Anrdoid 到 Unity 的调用,主界面上的 text 变为「Hello From Android」:
具体操作方式 新建一个 Android 工程 这里随便用 Android Studio 建立一个工程就行了。建立好工程后,参考官方文档在工程里添加一个自定义的模块:
菜单栏点击 「File」-「New」-「New Module&amp;hellip;」 弹出窗口中左侧选「Android Library」 右侧填入相关信息后创建模块 假设创建的模块名为「mod」会在工程根目录下新增一个名为 mod 的目录。此时可以删除工程根目录中默认创建的 app 目录,并将工程根目录中 settings.gradle 文件里的 include ':app' 这一行删除。
添加 Unity jar 依赖 为了在 Android 中和 Unity 互交互,我们需要引入 Unity 提供的库,这个库以 jar 包的形式提供。以下目录中都有这个 classes.</description></item><item><title>错误使用 C++ 模板特化产生的坑</title><link>https://zhiruili.github.io/posts/cpp-template-specialization/</link><pubDate>Fri, 27 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/cpp-template-specialization/</guid><description>今天在群里看到了一个错误使用 C++ 模板特化产生的坑,有点意思,这里记录一下。
问题是这样的:
有一个名为 A 的库,包含如下的头文件 a.h 和代码文件 a.cc
1 2 3 4 5 6 7 8 9 10 11 12 13 // a.h #pragma once #include &amp;lt;iostream&amp;gt;template &amp;lt;class T&amp;gt; struct A { void print() { std::cout &amp;lt;&amp;lt; &amp;#34;normal&amp;#34; &amp;lt;&amp;lt; std::endl; } }; // a.cc #include &amp;#34;a.h&amp;#34;template &amp;lt;&amp;gt; void A&amp;lt;int&amp;gt;::print() { std::cout &amp;lt;&amp;lt; &amp;#34;specialization&amp;#34; &amp;lt;&amp;lt; std::endl; } 有如下代码文件 main.cc 使用了这个库:
Expand Down
Binary file added images/2021-09-02-15-30-47.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 35 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name=author content="Zhirui Li">
<meta property="og:url" content="https://zhiruili.github.io/">
<link rel=canonical href=https://zhiruili.github.io/><link rel=alternate type=application/atom+xml href=https://zhiruili.github.ioindex.xml title="简单易懂的现代魔法 - Zhirui Li">
<script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/zhiruili.github.io"},"articleSection":"","name":"简单易懂的现代魔法 - Zhirui Li","headline":"简单易懂的现代魔法 - Zhirui Li","description":"","inLanguage":"en-US","author":"Zhirui Li","creator":"Zhirui Li","publisher":"Zhirui Li","accountablePerson":"Zhirui Li","copyrightHolder":"Zhirui Li","copyrightYear":"2021","datePublished":"2021-08-27 00:00:00 \u002b0000 UTC","dateModified":"2021-08-27 00:00:00 \u002b0000 UTC","url":"https:\/\/zhiruili.github.io\/","keywords":[]}</script>
<script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/zhiruili.github.io"},"articleSection":"","name":"简单易懂的现代魔法 - Zhirui Li","headline":"简单易懂的现代魔法 - Zhirui Li","description":"","inLanguage":"en-US","author":"Zhirui Li","creator":"Zhirui Li","publisher":"Zhirui Li","accountablePerson":"Zhirui Li","copyrightHolder":"Zhirui Li","copyrightYear":"2021","datePublished":"2021-09-01 00:00:00 \u002b0000 UTC","dateModified":"2021-09-01 00:00:00 \u002b0000 UTC","url":"https:\/\/zhiruili.github.io\/","keywords":[]}</script>
<title>简单易懂的现代魔法 - Zhirui Li</title>
<meta property="og:title" content="简单易懂的现代魔法 - Zhirui Li">
<meta property="og:type" content="website">
Expand Down Expand Up @@ -49,6 +49,23 @@
<h1 class=site-date-catalog>2021</h1>
<div class="row posts-line">
<div class="posts-date col-xs-3 col-sm-2">
<time datetime="2021-09-01 00:00:00 UTC">Sep 01</time>
</div>
<div class="posts-title col-xs-9 col-sm-10">
<div class=row>
<div class="col-xs-11 col-sm-10">
<a href=/posts/unity_with_android/>Unity 和 Android 模块交互</a>
</div>
<div class="col-xs-1 col-sm-2 posts-categories">
<div class=posts-category>
<a href=/categories/notes/><strong>Notes</strong></a>
</div>
</div>
</div>
</div>
</div>
<div class="row posts-line">
<div class="posts-date col-xs-3 col-sm-2">
<time datetime="2021-08-27 00:00:00 UTC">Aug 27</time>
</div>
<div class="posts-title col-xs-9 col-sm-10">
Expand Down Expand Up @@ -400,6 +417,23 @@ <h1 class=site-date-catalog>2016</h1>
</div>
</div>
</section>
<section>
<h1 class=site-date-catalog>0001</h1>
<div class="row posts-line">
<div class="posts-date col-xs-3 col-sm-2">
<time datetime="0001-01-01 00:00:00 UTC">Jan 01</time>
</div>
<div class="posts-title col-xs-9 col-sm-10">
<div class=row>
<div class="col-xs-11 col-sm-10">
<a href=/posts/unity-with-android/></a>
</div>
<div class="col-xs-1 col-sm-2 posts-categories">
</div>
</div>
</div>
</div>
</section>
</div>
<div class=site-footer>
</div>
Expand Down
8 changes: 6 additions & 2 deletions index.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>简单易懂的现代魔法 - Zhirui Li</title><link>https://zhiruili.github.io/</link><description>Recent content on 简单易懂的现代魔法 - Zhirui Li</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Fri, 27 Aug 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://zhiruili.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>错误使用 C++ 模板特化产生的坑</title><link>https://zhiruili.github.io/posts/cpp-template-specialization/</link><pubDate>Fri, 27 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/cpp-template-specialization/</guid><description>今天在群里看到了一个错误使用 C++ 模板特化产生的坑,有点意思,这里记录一下。
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>简单易懂的现代魔法 - Zhirui Li</title><link>https://zhiruili.github.io/</link><description>Recent content on 简单易懂的现代魔法 - Zhirui Li</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Wed, 01 Sep 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://zhiruili.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>Unity 和 Android 模块交互</title><link>https://zhiruili.github.io/posts/unity_with_android/</link><pubDate>Wed, 01 Sep 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/unity_with_android/</guid><description>有时候,我们需要在 Unity 里调用一些 Android 的功能,这些功能在 Unity 中可能并没有提供接口,需要在 Android 平台上实现。此时,我们需要有一个方法来让 Android 代码和 Unity 代码互交互。这里记录一下操作方法,并提供一个工具来简化这个过程。
示例工程 下面的记录可以参考示例工程。其中,根目录是 Unity 工程,可以直接用 Unity 打开。根目录下的 AndroidSample 子目录是 Android 工程,可以用 Android Studio 打开。运行后如下图左所示,点击其中的按钮,就会触发 Unity 到 Anrdoid 的调用,在主界面上产生一个 toast,同时,触发一次从 Anrdoid 到 Unity 的调用,主界面上的 text 变为「Hello From Android」:
具体操作方式 新建一个 Android 工程 这里随便用 Android Studio 建立一个工程就行了。建立好工程后,参考官方文档在工程里添加一个自定义的模块:
菜单栏点击 「File」-「New」-「New Module&amp;hellip;」 弹出窗口中左侧选「Android Library」 右侧填入相关信息后创建模块 假设创建的模块名为「mod」会在工程根目录下新增一个名为 mod 的目录。此时可以删除工程根目录中默认创建的 app 目录,并将工程根目录中 settings.gradle 文件里的 include ':app' 这一行删除。
添加 Unity jar 依赖 为了在 Android 中和 Unity 互交互,我们需要引入 Unity 提供的库,这个库以 jar 包的形式提供。以下目录中都有这个 classes.</description></item><item><title>错误使用 C++ 模板特化产生的坑</title><link>https://zhiruili.github.io/posts/cpp-template-specialization/</link><pubDate>Fri, 27 Aug 2021 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/cpp-template-specialization/</guid><description>今天在群里看到了一个错误使用 C++ 模板特化产生的坑,有点意思,这里记录一下。
问题是这样的:
有一个名为 A 的库,包含如下的头文件 a.h 和代码文件 a.cc
1 2 3 4 5 6 7 8 9 10 11 12 13 // a.h #pragma once #include &amp;lt;iostream&amp;gt;template &amp;lt;class T&amp;gt; struct A { void print() { std::cout &amp;lt;&amp;lt; &amp;#34;normal&amp;#34; &amp;lt;&amp;lt; std::endl; } }; // a.cc #include &amp;#34;a.h&amp;#34;template &amp;lt;&amp;gt; void A&amp;lt;int&amp;gt;::print() { std::cout &amp;lt;&amp;lt; &amp;#34;specialization&amp;#34; &amp;lt;&amp;lt; std::endl; } 有如下代码文件 main.cc 使用了这个库:
Expand Down Expand Up @@ -108,4 +112,4 @@ I call it my billion-dollar mistake. It was the invention of the null reference
$$ \begin{array}{rcl} \text{(expression)} &amp;amp; := &amp;amp; \text{(name) | (function) | (application)} \newline \text{(function)} &amp;amp; := &amp;amp; \lambda~\text{(name).(expression)} \newline \text{(application)} &amp;amp; := &amp;amp; \text{(expression)(expression)} \newline \end{array} $$
至于变换规则则总共有三条,更加具体的描述可参考维基百科 2:
α - conversion: 改变绑定变量的名称不影响函数本身;β - reduction: 将函数应用于其参数;η - conversion: 两个函数对于所有的参数得到的结果都一致,当且仅当它们是同一个函数。
本文后面的部分均使用 Scheme 语言来描述这些计算,在 Scheme 中,有非常类似 λ 演算中表达式的表示,例如一个函数 $\lambda x.y$ 将在 Scheme 中表示为 (lambda (x) y),而将函数应用于参数 $x~y$ 将在 Scheme 中表示为 (x y)。最大的区别可能在于,在 λ 演算中,(x) 和 x 一样,而在 Scheme 中,前者会变成一个对函数 x 的调用,而后面则是 x 本身。</description></item></channel></rss>
本文后面的部分均使用 Scheme 语言来描述这些计算,在 Scheme 中,有非常类似 λ 演算中表达式的表示,例如一个函数 $\lambda x.y$ 将在 Scheme 中表示为 (lambda (x) y),而将函数应用于参数 $x~y$ 将在 Scheme 中表示为 (x y)。最大的区别可能在于,在 λ 演算中,(x) 和 x 一样,而在 Scheme 中,前者会变成一个对函数 x 的调用,而后面则是 x 本身。</description></item><item><title/><link>https://zhiruili.github.io/posts/unity-with-android/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://zhiruili.github.io/posts/unity-with-android/</guid><description/></item></channel></rss>
Loading

0 comments on commit 9e2b431

Please sign in to comment.