brew linkapps macvim
生成一个链接到Applications目录之后,我立马敲了mvim
来启动Macvim, 让我吃惊的是,居然报错了!
Fatal Python error: PyThreadState_Get: no current thread
.vimrc
中用到了Python的插件以排查问题的时候,把YCM注释掉了Python就不报错了。
于是google了一下报错信息,果然在YCM的issue里有关于这个问题的讨论,YCM作者一直在甩锅:
Just tried using the latest MacVim on my OS X Mountain Lion and everything works. So this is somehow caused by your machine configuration in some way, sorry.大意就是:”别特么来烦我,这明显是你Mac系统配置问题,去换一个官方最新的Macvim版本吧。” 看了好几个关于这个问题的issue最后看到了YCM作者最关键的一个回答:
The version of Python that YCM is linked to when being built and the version of Python linked into your Vim binary have to match, yes. If they don’t, a problem like the one you’re experiencing might ensue.意思是:”构建YCM使用的Python版本必须和构建Vim使用的Python版本必须匹配,否则就可能出来这个问题。” ...
ps: 2016年6月的WWDC上,Mac操作系统正式更名为macOS, 与iOS, watchOS, tvOS的命名风格终于统一了。
luaopen_mylib
添加到luaL_openlibs
会打开的标准库列表里。(在linit.c中)
经过我在mac上的实践,第二种方式顺利搞定。毕竟lua源码中的README和INSTALL文档已经把编译lua讲的很明白了。
至于这第一种方式,别看书里一笔带过,这实践起来还真是。。。。。。 一言不合就翻车了。
...
自从13年开始做手游接触lua,始终是边写边学,缺乏对lua更加全面系统的学习,这几篇文章开始“重识lua”, 把欠下的帐还回来。这个系列侧重于总结lua作为扩展程序的用法,不会着重介绍lua的语法。
function f(var)
return var * var + 2 * var + 100
end
自从13年开始做手游接触lua,始终是边写边学,缺乏对lua更加全面系统的学习,这几篇文章开始“重识lua”, 把欠下的帐还回来。这个系列侧重于总结lua作为扩展程序的用法,不会着重介绍lua的语法。
monster_type = "Ghost"
blood = 99.9
#include "lua_51/lua.hpp"
#include "include/inc.h"
#include <string>
using namespace elloop;
using namespace std;
int main() {
string scriptName("res/config.lua");
lua_State* lua = luaL_newstate();
int luaError = luaL_loadfile(lua, scriptName.c_str()); // 加载lua文件
if (luaError) {
error(lua, "fail to load script: %s, %s", scriptName.c_str(), lua_tostring(lua, -1));
}
luaError = lua_pcall(lua, 0, 0, 0); // 执行这个lua文件, 三个0依次表示:输入0个参数,返回0个结果,需要0个错误处理函数
if (luaError) {
error(lua, "fail to run script: %s", lua_tostring(lua, -1));
}
lua_getglobal(lua, "blood"); // 获取全局变量blood
lua_getglobal(lua, "monster_type"); // 获取全局变量monster_type
double blood = lua_tonumber(lua, 1); // 读取两个全局变量
const char* type = lua_tostring(lua, 2);
psln(blood); // 打印 blood = 99.9
psln(type); // type = Ghost
lua_close(lua);
return 0;
}
自从13年开始做手游接触lua,始终是边写边学,缺乏对lua更加全面系统的学习,这几篇文章开始“重识lua”, 把欠下的帐还回来。这个系列侧重于总结lua作为扩展程序的用法,不会着重介绍lua的语法。
extern "C" {
#include "lua_51/lua.h" // C API函数声明所在的文件
#include "lua_51/lauxlib.h" // luaL_ 开头的函数所在的头文件, 比如luaL_newstate
}
#include <iostream>
int main()
{
lua_State* lua = luaL_newstate(); // 创建一个lua state
lua_pushstring(lua, "hello world"); // 入栈一个字符串
std::cout << lua_tostring(lua, 1) << std::endl; // 从栈中读取字符串
lua_close(lua); // 关闭lua state
return 0;
}