int main(int argc, char* argv[]) { // create a new Lua state. lua_State* L = luaL_newstate(); // load Lua libraries std::vector<luaL_Reg> lualibs = { {"base", luaopen_base} , {"io", luaopen_io} }; for(auto& it : lualibs) { // load the required lua libs and store it in the global space. luaL_requiref(L, it.name, it.func, 1); // clear the stack in case there is some remaining stuffs there. lua_settop(L, 0); } // load the script int status = luaL_loadfile(L, "function.lua"); if(status == 0) // okay { std::cout << "[C++] script loaded" << std::endl; } else { std::cout << "[C++] error loading script" << std::endl; return 1; } int result = result = lua_pcall(L, 0, LUA_MULTRET, 0); if(status == LUA_OK) { } else { std::cout << "[C++] Could not run the script." << std::endl; return 1; } Monster snake1("Snake1", 4, DamageFunction(L, "snake_damage_func")); Monster snake2("Snake2", 5, DamageFunction(L, "snake_damage_func")); Monster bear1("Bear1", 5, DamageFunction(L, "bear_damage_func")); std::cout << snake1.name << " : Str Value [" << snake1.strength << "] Dmg Value [" << snake1.getDamage()<< "]"<< std::endl; std::cout << snake2.name << " : Str Value [" << snake2.strength << "] Dmg Value [" << snake2.getDamage()<< "]"<< std::endl; std::cout << bear1.name << " : Str Value [" << bear1.strength << "] Dmg Value [" << bear1.getDamage()<< "]"<< std::endl; lua_close(L); return 0; }
void loop() { volume(); beat(); current = (float)analogRead(2)/ (1024/ 8)+1; // current = 8; switch (current) { case 1: stargase(); break; case 2: vol_meter(); break; case 3: vol_visual(); break; case 4: picture_move(); break; case 5: vol_wave(); break; case 6: snake(); break; case 7: snake2(); break; case 8: matrix(); break; } last_value = current; print(); }
void loop() { print(); current = (float)analogRead(4)/ (1024/ 7); current = 8; switch (current) { case 1: stargase(); break; case 2: vol_meter(); break; case 3: vol_visual(); break; case 4: picture_move(); break; case 5: vol_wave(); break; case 6: snake(); break; case 7: snake2(); break; case 8: mikro_disko(); break; } last_value = current; // }