.cc把函数传入.lua

#include <iostream>
#include <luabind/luabind.hpp>
#include <luabind/function.hpp>

extern "C"
{
#include "lua5.1/lua.h"
#include "lua5.1/lualib.h"
#include "lua5.1/lauxlib.h"
}
using namespace std;

void print_hello( int number )
{
    cout << "hello world " << number << endl;
}

int main()
{
    lua_State* myLuaState = luaL_newstate();
    luaL_openlibs( myLuaState );
    luabind::open( myLuaState );
    luabind::module( myLuaState )[luabind::def( "print_hello", print_hello )];
    luaL_dofile( myLuaState, "demo2.lua" );

    lua_close( myLuaState );
}
print_hello(123)
hello world 123
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容