
lua
知秋一叶123
嵌入式linux开发
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
冒泡排序(lua实现)
function bubble_sort(arr) -- body local tmp = 0 for i=1,#arr-1 do for j=1,#arr-i do if arr[j] > arr[j+1] then tmp = arr[j] arr[j] = arr[j+1] arr[j+1] = tmp end end endend原创 2015-10-19 15:08:20 · 5532 阅读 · 0 评论 -
lua和c交互用到的c api介绍
lua和c进行数据换时,使用堆栈,相关的操作接口如下:1.压入元素void lua_pushnil (lua_State *L); //压入空值到栈中void lua_pushboolean (lua_State *L,int bool); //布尔void lua_pushnumber (lua_State *L,double n); //doublev原创 2015-10-13 13:57:29 · 469 阅读 · 0 评论 -
lua对sqlite数据库操作封装
DB = {}db_e = require "luasql.sqlite3"function open_db( ... )-- bodyenv = assert(db_e.sqlite3())db =assert(env:connect("test.db"))endfunction DB.query(sql)-- bodyopen_db()loc原创 2015-10-10 08:37:02 · 1750 阅读 · 2 评论 -
lua调用c函数
1.c函数封装成库,代码如下:#include #include #include #include //2 args static int add(lua_State* L){ double a = luaL_checknumber(L,1); double b = luaL_checknumber(L,2); lua_pushnumber(L,a+b); retu原创 2015-10-15 08:26:27 · 410 阅读 · 0 评论 -
c调用lua函数
1.lua函数如下:--add.luafunction add(a,b) return a+bend2.c调用lua的函数,代码如下:#include #include "lua.h"int main(int argc, char const *argv[]){ /* code */ lua_State* L = luaL_newstate(); if原创 2015-10-14 13:14:37 · 734 阅读 · 0 评论 -
lua面向对象
lua面向对象的一种写法:local function _init(class,...) -- body local o = setmetatable({},{__index = class}) if o.__init__ then o:__init__(...) end return oendfunction class(base) -- body return s原创 2016-03-04 16:37:23 · 475 阅读 · 0 评论