collapse collapse

* Who's Online

  • Dot Guests: 72
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: 1: How to execute Lua files from C++  (Read 2437 times)

0 Members and 1 Guest are viewing this topic.

Offline spum789

  • Limited_C++_Learner
  • Jr. Member
  • *
  • Posts: 65
  • Reputation 97
  • Gender: Male
    • View Profile
1: How to execute Lua files from C++
« on: August 11, 2009, 04:38:16 pm »
OK, so after that first lesson your probablly wondering "But how do i code in Lua?". I promise you after these 3 lessons we'll get right into coding with lua.

First copy and paste this code into notepad and title it hello.lua
save the file in then same directory as your main.cpp file in your project
Code: [Select]
print("hello world in lua!!!!!")
here is the C++ code.
Code: [Select]
#include <stdio.h>
#include <iostream>
using namespace std;

/*Because lua is mainly for "C" we need to include it as such.*/
extern "C" {
   #include "lua.h"
   #include "lualib.h"
   #include "lauxlib.h"
}

/*this lua functiion makes a call to the lua interpreter. initializes it, runs the files that we need, and then closes it.*/
void lua() {
        /* these calls to lua are kinda tricky with the "L" but once you type them enough you'll get used to it
        so if you have a problem compiling lua ALWAYS check here first*/
lua_State* L;//call the lua interpreter
L = lua_open();//init lua
luaL_openlibs(L);//init lua libs
luaL_dofile(L, "hello.lua");//do lua files
lua_close(L);//close lua
}

int main (int argc, char** argv)
{
   lua();//call lua function
   cout << "Press enter to exit" << endl;
   getchar();//duh
   return 0;
}

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: 1: How to execute Lua files from C++
« Reply #1 on: March 21, 2010, 06:28:19 pm »
print("Lua is epic")

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]