博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lua学习例子
阅读量:7228 次
发布时间:2019-06-29

本文共 1061 字,大约阅读时间需要 3 分钟。

extern "C"{#include 
#include
#include
}#include
#include
#include
#pragma comment(lib,"lua.lib") void error(lua_State* L, const char* fmt, ...){ va_list argp; va_start(argp, fmt); vfprintf(stderr, fmt, argp); va_end(argp); lua_close(L); exit(EXIT_FAILURE);}void load(char* filename, int* width, int* height){ lua_State* L = luaL_newstate(); luaopen_base(L); luaopen_io(L); luaopen_string(L); luaopen_math(L); if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0)) error(L, "cannot run configuration file:%s", lua_tostring(L, -1)); lua_getglobal(L, "width");//每次调用将相应变量压入栈顶 lua_getglobal(L, "height"); if (!lua_isnumber(L, -2))//lua_isnumber函数判断每个值是否为数字 error(L, "width should be a number"); if (!lua_isnumber(L, -1)) error(L, "height should be a number"); *width = (int)lua_tonumber(L, -2);//lua_tonumber函数将得到的数值转换成double类型并用(int)强制转换成整型 *height = (int)lua_tonumber(L, -1); lua_close(L);}int main(){ int width = 0; int height = 0; load("pp.lua", &width, &height); return 0;}

 

转载地址:http://crdfm.baihongyu.com/

你可能感兴趣的文章
放开那个程序员
查看>>
构建高性能数据库缓存之Redis(一)
查看>>
测试驱动开发
查看>>
解决MySQL不允许从远程访问
查看>>
puppet介绍及基于httpd实例部署
查看>>
UML常用工具之三--RSA
查看>>
iis7 appcmd的基础命令及简单用法
查看>>
用脚本实现移动某目录下文件名符合指定规则的文件到另一个目录的功能
查看>>
关于SQL镜像配置报错
查看>>
终于找到解决方案了,Qt的Model/View Framework解析
查看>>
线程信息的获取和设置
查看>>
Databricks Scala 编程风格指南
查看>>
Tkinter,label内容随多选框变化
查看>>
PHP开发中的数据类型 ( 第3篇 ) :Heaps
查看>>
网络七层协议
查看>>
4种删除Word空白页的小技巧,都是你需要用到的!
查看>>
单服务器MySQL主从复制实践
查看>>
CentOS 7 root口令恢复
查看>>
| 刘知远:让计算机听懂人话
查看>>
苹果收购初创公司Tueo Health,哮喘监测或将应用到Apple Watch
查看>>