`
lua
  • 浏览: 74800 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

How to create c extension for lua and pass complex structure step by step

阅读更多

Original link: http://sunxiunan.com/?p=1498

 

You could download the project from http://groups.google.com/group/lua5/web/luautil.rar

At first, create a windows dll application. The IDE I used is VC2008.

 

I suggest you download and install the "Lua for windows " from luaforge.net, it contains most useful packages for Lua windows development. You could copy "include" and "lib" directory under the installation directory to your project.

 

 

image

 

In the beginning, you should include Lua header files.

 

Please note, you should use extern "C" to declare the header for Lua. In linker’s input, set the lua51.lib.

 

image

 

The project should have a function like luaopen_xxx (in my code, it is luaopen_luautil), and have strings=>functions map structure like "lua_util". Then you could call your extension like require "luautil".

 

image

 

The L_MSleep will call windows’ api Sleep().

 

Another function L_NewTable will generate a complex table for Lua script. It will call lua_settable() and lua_setfield() function to manipulate the table in Lua. lua_pushstring() and lua_pushnumber() could push string type and number type data to Lua. You could find the document about these functions in Lua 5.1 manual.

 

image

 

The table that Lua get will like:

 

local table1 = { 
           userName1 = "hahaha", 
           serialNumber1 = "1234613423", 
           tbl = {userName2 = "wwwww", serialNumber2 = "asdfasdadf", "5566", "wowowo"}}

 

After you build the project, copy the dll to lua installation folder "lua\5.1\clibs".

 

In the end, we could test the extension like:

 

require "luautil"
 local newtable =luautil.newtable()

for k, v in pairs(newtable) do
            print(k, v)
            if type(v) == "table" then
                for k2, v2 in pairs(v) do
                    print("–", k2, v2)
               end
           end
        end

 

– sleep 5 seconds.
 luautil.msleep(5000)

分享到:
评论

相关推荐

    Apress.Learn.Lua.for.iOS.Game.Development.2012

    then shows you how to create games using the top Lua frameworks like Corona SDK, Gideros, Moai, and even how to create games on the iPad (not just for the iPad) with Codea. You aren't tied to Xcode ...

    STEP-BY-STEP--LUA.zip_lua_lua脚本_step by step

    Lua脚本语方学习笔记,作为学习lua的参考

    How.to.program.ESP8266.in.Lua

    it’s a development kit made out of ESP8266, which is a cheap Wi-Fi microcontroller, and in this book you can find How to program the Nodemcu using Lua Programming language, This book will teach you ...

    Apress.Learn.Lua.for.iOS.Game.Development

    then shows you how to create games using the top Lua frameworks like Corona SDK, Gideros, Moai, and even how to create games on the iPad (not just for the iPad) with Codea. You aren’t tied to Xcode...

    Create Mobile Games with Corona: Build with Lua on iOS and Android

    You'll learn how to write clean, easily maintainable, easily expandable game code, and to create online leaderboards for your games. You'll also find out how to make money with games: enabling in-app...

    LuaForWindows_v5.1.5-52 安装包

    lua for windows其实是一整套Lua的开发环境.Lua for Windows 为 Windows 系统下提供了 Lua 脚本语言的开发和运行环境。Lua 是一个小巧的脚本语言。作者是巴西人。该语言的设计目的是为了嵌入应用程序中,从而为应用...

    LuaForWindows_v5.1.4

    Lua for Windows is a 'batteries included environment' for the Lua scripting language on Windows. Lua for Windows (LfW) combines Lua binaries, Lua libraries with a Lua-capable editor in a single ...

    Using LUA with Visual C++ (Introduction)

    In order to execute LUA scripts you have to load them first and call them afterwarts, this is done by respectivily calling the lua_load and the lua_call or lua_pcall function. The lua_load function ...

    C语言头文件 LUA_C

    C语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 LUA_CC语言头文件 ...

    Programming in Lua 4th.pdf

    Lua is a small and simple language, partly because it does not try to do what C is already good for, such as sheer performance and interface with third-party software. Lua relies on C for these tasks...

    C语言调用Lua代码

    在Linux底下,从C语言调用Lua代码的一个简单例子。

    LuaUnicode icu-lua

    For example, you should be able to extract a Unicode string from a database and pass it to a Unicode-aware graphics library. But see the sections below on pattern matching and string equality. ...

    LUAC脚本解密_luac解密在线_luac4加密_luac反编译_luac4解密工具_luac解密工具

    LUAC 脚本加密 , 用于LUAC 脚本反编译,有用得同学可以下载,

    VS Studio lua插件

    Visual Studio Extension for Lua is a free, open source plugin that turns Visual Studio into a Lua development environment. It is designed, developed, and supported by Microsoft and the community. The...

    Programming In Lua

    his book is a detailed and authoritative introduction to all aspects of Lua programming written by Lua's chief architect. Programming in Lua provides a solid base to any programmer who wants to use ...

    lua加密成luac工具

    ios版本将lua加密成luac

    Beginning Lua Programming

    The authors present the fundamentals of programming, explain standard Lua functions, and explain how to take advantage of free Lua community resources. Complete code samples are integrated throughout...

    luabind (helps you create bindings between C++ and Lua)

    luabind is a library, inspired by and similar to Boost.Python, that helps you create bindings between C++ and Lua. It has the ability to expose functions and classes, written in C++, to Lua.

    mac下使用的luac 编译lua 基于5.1版本

    mac下使用的luac编译lua luac文件支持64位 基于5.1版本 mac下使用的luac编译lua luac文件支持64位 基于5.1版本 mac下使用的luac编译lua luac文件支持64位 基于5.1版本

Global site tag (gtag.js) - Google Analytics