LUA 02

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值