lua和v8 JavaScript环境搭建什么的,,,我就不说了,,,,
直接上案列,,,哈哈,,,
分别用lua和v8 JavaScript新建文件,写入hello world
一.先看lua吧,,,,
1.lua文件,,新建一个hello.lua文件
function createfile()
local hFile=io.open("hello.txt",r);
if (hFile==false)
then
hFile=io.open("hello.txt",w)
end
io.output("hello.txt")
io.write("hello world!")
io.close()
end
createfile()
2.把lua文件放入执行文件的地方,要不可能会出错。
3.打开vs2010,新建一个空的.cpp文件,,,
#include <stdio.h>
extern "C"{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
};
lua_State *L;//lua解释器指针
void createfiles(){
lua_getglobal(L,"createfile");//执行LUA中的函数
}
int main(int argc,char *argv[]){
int sum=0;
L=lua_open();//打开Lua
luaopen_base(L);//
luaL_openlibs(L);//载入lua基本库
luaL_loadfile(L,"hello.lua");//加载Lua文件
lua_pcall(L,0,LUA_MULTRET,0);//调用函数,实例化变量
createfiles();
lua_close(L);
return 0;
}
代码就是这个,,然后运行就OK了,,哈哈哈