// mytest.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <stdio.h> #include <windows.h>
extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" }/* Lua解释器指针 */
//function for Lua to call //return a integer array to the script //C里面的函数由lua脚本调用 static int getarr (lua_State *Lo) { lua_newtable(Lo);//create table
lua_pushnumber(Lo,11);//push the value lua_rawseti(Lo,-2,1);//set t[1]=v
lua_pushnumber(Lo,22); lua_rawseti(Lo,-2,2);
lua_pushnumber(Lo,33); lua_rawseti(Lo,-2,3);
lua_pushnumber(Lo,44); lua_rawseti(Lo,-2,4); return 1; }
//lua 脚本里面的函数由C调用 int use_lua_add (lua_State *L,const char * func_name ,int x, int y ) { int sum; /* 通过名字得到Lua函数 */ lua_getglobal(L, func_name); /* 第一个参数 */ lua_pushnumber(L, x); /* 第二个参数 */ lua_pushnumber(L, y); /*