.cc把函数传入.lua

#include 
#include 
#include 

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

你可能感兴趣的:(.cc把函数传入.lua)