Haruyuki Mohri

毛利春幸のブログです。

lua53.dll to execute in C++Builder.

lua53.dll to execute in C++Builder(Win64).

http://luabinaries.sourceforge.net/download.html

lua-5.3_Win64_dllw4_lib.zip Download from the above URL.
The lua-5.3_Win64_dllw4_lib.zip exists dll and include files.
f:id:mojeld:20150827132626p:plain

new project, it will through the "path" of the include files and uLuaDll.hpp

lua53.dll implemented in the project

function lua_function_string(s)
    return "lua " .. s;
end

function lua_function_int(i)
    return 5050 + i;
end

To prepare the above lua script.
Call the function of the lua from C++Builder

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    lua_State* lua1 = luaL_newstate_();

    luaL_openlibs_(lua1);

    if (luaL_dofile_(lua1, "func.lua") == LUA_OK)
    {
        String s = "";
        int ret = lua_getglobal_(lua1, "lua_function_string");//Internal script, call the function
        lua_pushstring_(lua1, "string");
        ret = lua_call_(lua1, 1, 1);
        s = lua_tostring_(lua1, -1);

        ret = lua_getglobal_(lua1, "lua_function_int");//Internal script, call the function
        lua_pushinteger_(lua1, 100);
        lua_call_(lua1, 1, 1) ;
        ret = lua_tointeger_(lua1, -1);

        ShowMessage(Format(" (%s, %d)", ARRAYOFCONST((s, ret))) );
    }

    lua_close_(lua1);

    FreeLibrary(luaa);
}
//---------------------------------------------------------------------------

How to use lua53.dll in C++Builder · GitHub

Also over the argument to the function.
Of after calling the function, return was also confirmed.
f:id:mojeld:20150827134020p:plain

Reference

基本的なDLLの使用方法 DLLを読み込む(動的なロード) - C++Builder Tips
Luaでファイルの読み書きを行なう - Symfoware
八角研究所 : 高速スクリプト言語「Lua」を始めよう!(5) - 高速スクリプト言語「Lua」を始めよう!(5)