---
title: "Lua runtime code reading Lua运行期源代码分析阅读"
author: "lua"
date: "2009-11-19T13:25:28Z"
tags: []
slug: "lua-runtime-code-reading-lua"
draft: false
lastmod: "2009-11-19T13:26:13Z"
id: 520300
url: "https://lua.iteye.com/blog/520300"
---

**[http://sunxiunan.com/?p=1477](http://sunxiunan.com/?p=1477)**

 

 

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image7_thumb.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image71.png)  

You could download the project for VC2008 in [http://groups.google.com/group/lua5/web/lua\_vc2008.rar](http://groups.google.com/group/lua5/web/lua_vc2008.rar "http://groups.google.com/group/lua5/web/lua_vc2008.rar")

The project will use parameter like "c:\\test.lua", and the lua script like above image.

The code starting point is pmain().

 

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image_thumb5.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image5.png)

lua parser will parse the code file, and use LexState \*ls to store the information.

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image_thumb6.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image6.png)

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image_thumb7.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image7.png)

After the binary code generating, opcodes will run in function luaV\_execute().

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image_thumb8.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image8.png)

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image_thumb9.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image9.png)

for the code in standard library (c function), it will be called in function luaD\_precall().

[![image](http://sunxiunan.com/wp-content/uploads/2009/11/image_thumb10.png "image")](http://sunxiunan.com/wp-content/uploads/2009/11/image10.png)