Skip to content

Instantly share code, notes, and snippets.

@fireyang
Last active August 4, 2016 10:40
Show Gist options
  • Save fireyang/a9463711cba1585999da to your computer and use it in GitHub Desktop.
Save fireyang/a9463711cba1585999da to your computer and use it in GitHub Desktop.
在windows下使用vs 2012编译lua.dll

在windows下使用vs 2012编译lua.dll

  1. 下载lua源码

首先去lua的官网下载lua:http://www.lua.org/ftp/ 这里测试用的是:1.5.5

  1. 编译脚本

保存下来脚本到mylua.bat到lua的目录下,然后用Visual Studio Tools》Developer Command Prompt来运行这个bat就可以了,会在src下面生产一个lua515vc.dll

cd src
cl /02 /W3 /c /DLUA_BUILD_AS_DLL  l*.c
del lua.obj luac.obj
link /DLL /out:lua515vc.dll l*.obj
cl /02 /W3 /c /DLUA_BUILD_AS_DLL lua.c
link /out:lua.exe lua.obj lua515vc.lib
cd ..
  1. unity调用

因为是在win32的系统下测试,将生成的dll,放到unity的Plugins/x86下。 参考:https://github.com/phardera/unity3d_lua 类似如下代码,就可以直接使用了:

[DllImport("lua514vc")] private static extern IntPtr luaL_newstate();

ps:官方文档有说明:win32必须放在Plugins/x86下面,否则会出现DLL找不到的错误提示 http://docs.unity3d.com/Manual/PluginsForDesktop.html

使用示例

参考文章

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment