Lua在Visual Studio 2012中? [英] Lua in visual studio 2012?

查看:124
本文介绍了Lua在Visual Studio 2012中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始学习Lua,想知道是否可以在C ++环境中的Visual Studio 2012中编辑,运行和调试Lua代码.我已经查看并发现有用于Visual Studio 2008和2010的插件,但是目前似乎找不到我想要的任何信息.

I'm looking at beginning to learn Lua and was wondering if it is possible to edit, run and debug Lua code in Visual Studio 2012 in a C++ environment. I have looked about and found that there are plug-ins for visual studio 2008 and 2010, but currently cannot seem to find any information on what I am looking for.

一个好的起点是为Lua代码提供语法突出显示.与调试器的集成会很好.在Lua代码与C或C ++库代码之间进行无缝调试的能力将是理想的选择.

A good starting point would provide syntax highlighting for Lua code. Integration with the debugger would be nice. The ability to debug seamlessly between Lua code and C or C++ library code would be an ideal.

如果不是VS2012,那么应该考虑使用哪种IDE?

If not VS2012, then what IDE should be considered?

推荐答案

找到了一个:

使用Visual Studio 2010编译Lua

Compiling Lua with Visual Studio 2010

下载Lua

  1. http://www.lua.org/下载所需的Lua来源,在撰写本文时,可以在以下位置找到最新资源的链接: 页面顶部: http://www.lua.org/download.html

  1. Download the desired Lua sources from http://www.lua.org/ At the time of this post, a link to the latest sources can be found at the top of the page: http://www.lua.org/download.html

最新版本以gzip(.gz)格式压缩;如果您还没有可以解压缩的内容,则有很多 免费提供或收费很少的实用程序(我个人更喜欢 7-Zip).您可以将其解压缩以作为备份,否则您可以 在创建Visual Studio项目后直接将其解压缩.

The latest release is compressed in gzip (.gz) format; if you don’t already have something that can decompress this, there are a number of utilities available for free or little charge (personally, I prefer 7-Zip). You can decompress it somewhere as a backup, or else you can decompress it directly after creating a Visual Studio project.

创建VS2010 C ++项目

Create a VS2010 C++ Project

1)打开Visual Studio并创建一个新的Visual C ++项目.方式 要创建的项目集是Visual Studio 2010中列出的项目之一 如文件=>新建=>项目…=>​​ Visual C ++ =>常规=>空项目. 随便你叫什么,例如只要不与"Lua"冲突 您正在使用的任何其他版本的Lua,或者如果您愿意的话,也可以使用"Lua52" 跟踪版本.

1) Open Visual Studio and create a new Visual C++ project. The type of project you want to create is the one listed in Visual Studio 2010 as File => New => Project… => Visual C++ => General => Empty Project. Call it whatever you like, e.g. just "Lua" if it won’t conflict with any other version of Lua you’re using, or perhaps "Lua52" if you want to keep track of the version.

2)将Lua源文件复制或解压缩到默认位置 Visual Studio放置C ++文件的位置.在VS2010的VC ++中, 解决方案文件夹下的项目文件夹. (如果不确定,请创建一个 临时.h文件,然后查看VS放置在哪里.)

2) Copy or decompress the Lua source files into the default place where Visual Studio puts C++ files. In VC++ for VS2010 this is in the project folder under the solution folder. (If you’re unsure, create a temporary .h file and look at where VS has put it.)

3)现在返回Visual Studio,并将文件添加到解决方案中 在解决方案资源管理器窗口中,使用添加=>现有项目… 选项.在标题"下添加所有扩展名为.h或.hpp的文件 文件"以及源文件"下所有带有.c扩展名的文件.

3) Now go back into Visual Studio and add the files into the solution from the Solution Explorer window using the Add => Existing Item… option. Add all files with a .h or .hpp extension under "Header Files" and all the files with a .c extension under "Source Files."

编译Lua

1)如果您此时尝试编译项目,则会得到一个 错误消息类似于:

1) If you try to compile the project at this point, you’ll get an error message similar to:

luac.obj:错误LNK2005:_main已在lua.obj中定义

luac.obj : error LNK2005: _main already defined in lua.obj

这是因为Lua发行版中包含了 Lua REPL/文件解释器(lua.c)和字节码编译器 (luac.c).

This is because the Lua distribution includes main files for both the Lua REPL / file interpreter (lua.c) and the byte code compiler (luac.c).

2)为了当前的目的,您需要解释器"lua.c",因此删除 项目中的编译器"luac.c".现在进行全部重建.

2) For present purposes, you want the interpreter "lua.c," so remove the compiler "luac.c" from the project. Now do a rebuild all.

运行Lua

1)如果重建全部成功,则您应该能够运行 Lua REPL在Visual Studio中,从资源管理器或从命令 迅速的.结果应如下所示:

1) If the rebuild all succeeds, you should be able to run the Lua REPL either inside Visual Studio, from Explorer, or from a command prompt. The result should look something like this:

2)尝试输入几行作为测试:

2) Try entering a few lines as a test:

3)您还可以通过以下方式从命令行运行Lua程序文件: 在可执行文件的名称后面加上Lua程序文件名. 这里的所有都是它的.现在您可以开始探索Lua 语言和嵌入式翻译.毫无疑问,您会写一个 "hello world",斐波那契发生器等.如果您想尝试添加 C语言中语言本身的命令,您可以尝试创建一个 使用您的姓名等功能,并查看可用资源 来自Lua网站上的链接,包括包含的电池" 版本以及在Windows下使用其他编译Lua的技巧 配置(包括指向一些完整项目的链接).

3) You can also run Lua program files from the command line by following the name of the executable with the Lua program file name. That’s all there is to it. Now you can begin exploring Lua as a language and as an embeddable interpreter. No doubt you’ll write a "hello world," a Fibonacci generator, etc. If you want to try adding commands to the language itself in C code, you can try creating a function with your name, etc. And check out the resources available from links on the Lua site, including the "batteries included" versions, and tips for compiling Lua under Windows using other configurations (including links to a few complete projects).

这篇关于Lua在Visual Studio 2012中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆