【发布时间】:2023-03-17 11:39:01
【问题描述】:
我刚刚成功创建了一个 lua 项目。 (到目前为止运行 lua 脚本的简单代码。)
但是我现在如何为 lua 脚本提供一个 c++ 函数和一个 c++ 变量呢?
举个例子:
int Add(int x, int y) {
return x + y;
}
和
float myFloatValue = 6.0
我对 c++ 很陌生,所以我真的希望它不会太复杂。这是我到目前为止得到的代码:
#include "stdafx.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
using namespace System;
int main(array<System::String ^> ^args)
{
lua_State* luaInt;
luaInt = lua_open();
luaL_openlibs (luaInt);
luaL_dofile (luaInt, "abc.lua");
lua_close(luaInt);
return 0;
}
【问题讨论】: