C++向Lua传递数组
来源:互联网 发布:淘宝买主板靠谱吗 编辑:程序博客网 时间:2024/05/14 14:27
没什么解释,直接贴代码
cnid.lua 这个不是重点
--verify cnidfunction verify_cnid(id)--校验位local verifymap = {1, 0, 88, 9, 8, 7, 6, 5, 4, 3, 2}--加权因子local factor = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}--加权和local sum = 0local index = 1while index ~= 18 do --身份证长18位sum = sum + (id[index]) * factor[index]index = index + 1end--求模11local r = sum % 11if verifymap[r + 1] == id[18] thenreturn trueelsereturn falseendendluacnid.cpp
#include <cstdlib>#include <iostream>extern "C" {#include <lua.h>#include <lualib.h>#include <lauxlib.h>}typedef unsigned short wchar;//point to Lua Interpreter//lua_State *L;bool lua_verify(lua_State *L, wchar * id, int len){//get lua function namelua_getglobal(L, "verify_cnid");//get lua function parameter//create a new tablelua_newtable(L); lua_pushnumber(L, -1); //push -1 into stacklua_rawseti(L, -2, 0); //set array[0] by -1for(int i = 0; i < len; i++){lua_pushinteger(L, id[i]); //push lua_rawseti(L, -2, i+1); //}//call function, 1 parameter, 1 return valuelua_call(L, 1, 1);//get resultbool result = (bool)lua_toboolean(L, -1);lua_pop(L, 1);return result;}int main(){lua_State *L;//init LuaL = lua_open();//load Lua libsluaL_openlibs(L);//load lua fileluaL_dofile(L, "cnid.lua");//call Lua functionwchar id[] = {4,4,2,3,2,5,1,8,8,0,0,4,1,8,4,0,4,3};bool result = lua_verify(L, id, 18);std::cout << result << std::endl;//clear Lualua_close(L);return 0;}
0 0
- C++向Lua传递数组
- c 向函数传递多维数组
- c 向函数传递多维数组
- 向lua虚拟机传递信息
- C向LUA中写入多维数组(表)
- 向函数传递数组
- FreeSWITCH向lua脚本传递参数
- 向页面传递数组参数
- php向javascript传递数组
- 向函数传递二维数组
- Shell 向函数传递 数组
- ajax 向服务器传递数组
- C++ 向函数传递数组
- lua基础(sh向lua传递参数arg)
- 关于使用mxGetPr从MATLAB向C中传递数组的相关问题
- C专家编程 十五 使用指针向函数传递一个多维数组
- 使用python向C语言的链接库传递数组、结构体、指针类型的数据
- c.传递多维数组
- TestFileStream
- 只有程序员才有的十大烦恼
- 走楼梯 递归 动态规划
- 健健康康 快快乐乐就好
- 汇编语言中cs.ds.es.ss怎么用
- C++向Lua传递数组
- Task Gate (May 20)
- 分享一个.net技术论坛,http://bbs.netluntan.com
- jsp中表格,表格中的文字根据表格的大小自动换行
- 走楼梯 递归 动态规划
- 人见人爱A-B
- poj2586--Y2K Accounting Bug
- string 常用函数
- 复数类--重载运算符+