LUA 02
来源:互联网 发布:康熙王朝 知乎 编辑:程序博客网 时间:2024/06/05 08:23
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#pragma comment(lib,"lua5.1.lib")
}
/* Lua解释器指针 */
lua_State* L;
int main ( int argc, char *argv[] )
{
/* 初始化Lua */
L = lua_open();
/* 载入Lua基本库 */
luaL_openlibs(L);
/* 载入语句块 */
if(luaL_loadfile(L, "1.lua") || lua_pcall(L, 0, 0, 0))
{
printf("载入错误\n");
printf("%s\n",lua_tostring(L, -1));
goto EXIT;
}
lua_getglobal(L, "whatfuck");
lua_getglobal(L, "b");
/* lua_to* 不会POP数据 */
printf("%s\n",lua_tostring(L, -2));
printf("%s\n",lua_tostring(L, -1));
lua_pop(L, -1);
lua_pop(L, -1);
//lua_settop(L, 1);
//lua_pop(L, -1);
lua_getglobal(L, "whatfucktable");
lua_pushstring(L, "a");
/* 调用会POP掉KEY PUSH相应的值 */
/*
table.value:whatfucktable.a
table:whatfucktable
*/
lua_gettable(L, -2);
printf("%s\n",lua_tostring(L, -1));
//printf("%s\n",lua_istable(L, -2)?"true":"false");
//lua_pop(L, -2);
//lua_pushstring(L, "b");
//lua_gettable(L, -3);
printf("%s\n",lua_tostring(L, -1));
//printf("%d\n",lua_gettop(L));
///* 运行脚本 */
////luaL_dofile(L, "print.lua");
//string file;
//cin>>file;
//getchar();
//getchar();
//file.push_back('.');
//file.push_back('l');
//file.push_back('u');
//file.push_back('a');
//luaL_dofile(L, file.c_str());
EXIT:
/* 清除Lua */
lua_close(L);
/* 暂停 */
printf( "Press enter to exit…" );
getchar();
return 0;
}
#include <string>
#include <cstdio>
using namespace std;
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#pragma comment(lib,"lua5.1.lib")
}
/* Lua解释器指针 */
lua_State* L;
int main ( int argc, char *argv[] )
{
/* 初始化Lua */
L = lua_open();
/* 载入Lua基本库 */
luaL_openlibs(L);
/* 载入语句块 */
if(luaL_loadfile(L, "1.lua") || lua_pcall(L, 0, 0, 0))
{
printf("载入错误\n");
printf("%s\n",lua_tostring(L, -1));
goto EXIT;
}
lua_getglobal(L, "whatfuck");
lua_getglobal(L, "b");
/* lua_to* 不会POP数据 */
printf("%s\n",lua_tostring(L, -2));
printf("%s\n",lua_tostring(L, -1));
lua_pop(L, -1);
lua_pop(L, -1);
//lua_settop(L, 1);
//lua_pop(L, -1);
lua_getglobal(L, "whatfucktable");
lua_pushstring(L, "a");
/* 调用会POP掉KEY PUSH相应的值 */
/*
table.value:whatfucktable.a
table:whatfucktable
*/
lua_gettable(L, -2);
printf("%s\n",lua_tostring(L, -1));
//printf("%s\n",lua_istable(L, -2)?"true":"false");
//lua_pop(L, -2);
//lua_pushstring(L, "b");
//lua_gettable(L, -3);
printf("%s\n",lua_tostring(L, -1));
//printf("%d\n",lua_gettop(L));
///* 运行脚本 */
////luaL_dofile(L, "print.lua");
//string file;
//cin>>file;
//getchar();
//getchar();
//file.push_back('.');
//file.push_back('l');
//file.push_back('u');
//file.push_back('a');
//luaL_dofile(L, file.c_str());
EXIT:
/* 清除Lua */
lua_close(L);
/* 暂停 */
printf( "Press enter to exit…" );
getchar();
return 0;
}
- LUA 02
- LUA 学习笔记 02
- lua学习笔记02
- lua基础02
- lua tutorial 02
- Lua 教程-02
- 02,Lua 程序块
- LUA
- Lua
- LUA
- lua
- Lua
- lua
- lua
- lua
- lua
- lua
- lua
- 字典树(Trie查找单词再也不用担心超时了)
- Android 移植oprofil性能监测工具
- ZOJ 3687
- usaco 4.3.4 letter game
- 基于MapReduce的HBase开发(续)
- LUA 02
- 获取JAVA文件路径
- Jlink和jtag的区别
- 又到一年开学季,新生培训第一讲,南工csdn俱乐部介绍
- GetDlgItem
- C#多线程学习笔记之(abort与join配合使用)
- 参加完电赛的一点小感想
- 编程模仿boost::function和boost::bind
- My97DatePicker控件显示时分秒