加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua

发布时间:2020-12-14 22:06:13 所属栏目:大数据 来源:网络整理
导读:#include "lua.hpp"lua_State *L;int main(){L = luaL_newstate(); luaL_openlibs( L ); string str = "print("Hello world!")"; luaL_loadbuffer( L,str.c_str(),str.length(),"line" ); lua_pcall( L,0 ); const char *scriptName = ""; int ret = luaL_
#include "lua.hpp"

lua_State *L;
int main()
{
	L = luaL_newstate();
    luaL_openlibs( L );
    string str = "print("Hello world!")";
    luaL_loadbuffer( L,str.c_str(),str.length(),"line" );
    lua_pcall( L,0 );

    const char *scriptName = "";
    int ret = luaL_dofile( L,scriptName ) ;
    if( ret != 0 )
    {
        string sErr = "lua_pcall failed: ";
        sErr += lua_tostring( L,-1 );
    }


	const char *fc;
    const char *fullPath;
    lua_getglobal( L,"g_fnCRC" ); //获取全局函数
    lua_pushstring( L,fc ); //参数压栈
    lua_pushstring( L,fullPath );
    lua_call( L,2,1 ); //函数调用: 2参数 1返回值
    int ret = lua_tonumber( L,-1 ); //获取返回结果 ret: 0 success !0 failed
    lua_pop( L,lua_gettop( L ) ); //清空
    
    int n = lua_gettop( L ); //返回栈中元素的个数
    vector<int> vec;

    for( int i=1; i<=n; i++ )
    {
        if( lua_isinteger( L,i ) )
        {
            vec.push_back( lua_tointeger( L,i ) );
        }
    }

    lua_pop( L,n );//清空
    lua_close( L ); //cleanup Lua
}


?

负责处理业务流程的a.lua? b.lua

在项目project中,调用a.lua? b.lua,只需编译一次。如果业务流程有变动,只需在a.lua? b.lua中修改,而无需再编译project本身。

a.lua? b.lua在处理业务流程的时候,可以调用project中的预留的特定方法。

?

脚本使用的好处是:灵活

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读