参考:その5 LuaからC言語の関数を呼び出す
test.cpp
#include <iostream>
#include <lua.hpp>
void test()
{
auto L = luaL_newstate();
auto lerp = [](lua_State* L)
{
auto from = static_cast<float>(lua_tonumber(L, 1));
auto to = static_cast<float>(lua_tonumber(L, 2));
auto time = static_cast<float>(lua_tonumber(L, 3));
lua_pop(L, lua_gettop(L));
lua_pushnumber(L, from + time * (to - from));
return 1;
};
lua_register(L, "lerp", lerp);
luaL_openlibs(L);
if (luaL_dofile(L, "test.lua"))
{
std::cout << lua_tostring(L, lua_gettop(L));
lua_close(L);
return;
}
lua_close(L);
}
int main(int argc, char* argv[])
{
test();
getchar();
return 0;
}
for i = 0, 10 do
print(lerp(0, 10, i * 0.1))
end