Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // script.lua
- printChoices("Would you like to...", {"YES", "NO", "MAYBE"})
- // main.cpp
- #include <LuaBridge.h>
- #include <iostream>
- extern "C" {
- # include "lua.h"
- # include "lauxlib.h"
- # include "lualib.h"
- }
- using namespace luabridge;
- void printChoices(const std::string& s, LuaRef table) {
- std::cout << s << std::endl;
- for (int i = 1; i < table.length() + 1; ++i) {
- LuaRef choice = table[i];
- std::cout << "* " << choice.cast<std::string>() << std::endl;
- }
- }
- int main() {
- lua_State* L = luaL_newstate();
- luaL_openlibs(L);
- getGlobalNamespace(L).addFunction("printChoices", printChoices);
- luaL_dofile(L, "script.lua");
- lua_pcall(L, 0, 0, 0);
- system("pause");
- }
- // output:
- // Would you like to...
- // * YES
- // * NO
- // * MAYBE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement