【Lua】行列
行列を多次元配列を使用して実装する
test.lua
-- 3x3の行列を生成する row = 3 -- 行 column = 3 -- 列 matrix = {} for i = 1, row do matrix[i] = {} for j = 1, column do matrix[i][j] = 0 end end
test.cpp
#include <iostream> #include <lua.hpp> using namespace std; void test(char *file) { auto L = luaL_newstate(); luaL_openlibs(L); if (luaL_dofile(L, file)) { cout << lua_tostring(L, lua_gettop(L)) << endl; lua_close(L); getchar(); return; } lua_close(L); getchar(); } int main(int argc, char *argv[]) { test("test.lua"); return 0; }