Code: Select all
#include "lua.h"
Code: Select all
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
Moderator: Coders of Rage
Code: Select all
#include "lua.h"
Code: Select all
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
Code: Select all
print("Hello World")
Code: Select all
#include <stdio.h>
#include <iostream>
using namespace std;
//this part is very important since lua is written in C we have to include it as C but if you want to use straight C instead of C++ then just remove the extern "C". but other than that we're including the lua header files for the calls to lua such as lua_open()
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
//This is the lua interpreter you need this for your program to understand the lua
//functions that you use.
lua_State* L;
int main ( int argc, char *argv[] )
{
//here we initilize lua with lua_open();
L = lua_open();
//here we open the libraries with luaL_openlibs(L)
luaL_openlibs(L);
//this is where we call the lua script for the lua interpreter to interpert
luaL_dofile(L, "hello.lua");
//and with lua_close(L); we clean up lua because its been a dirty whore
lua_close(L);
//and here you should recognize this peice of code ^_^
cout << "Press enter to exit" << endl;
getchar();
return 0;
}
hmm...seems like there is a checking of the lua file when it is run. Interpreter checks it to be valid lua file,only then executes.spum wrote:bassically what happens is we load the lua script with luaL_dofile(L, "hello.lua") what this does is not only loads it. but its able to execute the code becuase the L's in the dofile point to the lua interpreter we declared in the top of the prgram lua_State* L . the lua interpreter executes the lua file and then goes onto the rest of the program. its almost like a function in C++
coooooool..........i will be waiting. :Dspum wrote:ok thats fine, but i'm still learning lua as well so i expect to be corrected if i'm wrong. But i should have another tutorial soon about calling lua functions from C/C++ and calling C/C++ functions from lua(which in my opinion is the pride and joy of lua
I will also be waiting..hellknight wrote:coooooool..........i will be waiting. :Dspum wrote:ok thats fine, but i'm still learning lua as well so i expect to be corrected if i'm wrong. But i should have another tutorial soon about calling lua functions from C/C++ and calling C/C++ functions from lua(which in my opinion is the pride and joy of lua
I'm pretty sure that when compiling lua as C++ code, exceptions are enabled as the main error handling mechanism (it checks for #ifdef __cplusplus)hellknight wrote:ohhh damn....i was thinking to it throwing something....my bad.......
(me->remeberCstyleCoding()....ok now i m good :P.)
just saw something very strange...(P.S. i m new to lua...so help me out plz :P)
if the source lua file is ok,only then it gets executed.(and i thought interpreters work one line at a time....nvr md me)
......so how does that api actually work?.......does the lua file get converted to a compiled code first or it is just interpreted on fly? and if it happens on the fly,then how can it know that the source lua file is "bad"? is it possible to modify the lua source file during run time?
(just saw the video where falco created that lua debug window..and was wondering how he did it........my guess was to create a lua file (empty if possible). make it call every frame during the "heart beat" (as falco says).then use a saprate thread to modify its content (yeah i know syncronisation problem :P),but will it work?
(P.S i have this annoying problem of putting "....." during chating ,forums etc.....dont mind me)
dude its called luaL_dostring. Sorry Falco you've no longer got the edgehellknight wrote:ohhh damn....i was thinking to it throwing something....my bad.......
(me->remeberCstyleCoding()....ok now i m good :P.)
just saw something very strange...(P.S. i m new to lua...so help me out plz :P)
if the source lua file is ok,only then it gets executed.(and i thought interpreters work one line at a time....nvr md me)
......so how does that api actually work?.......does the lua file get converted to a compiled code first or it is just interpreted on fly? and if it happens on the fly,then how can it know that the source lua file is "bad"? is it possible to modify the lua source file during run time?
(just saw the video where falco created that lua debug window..and was wondering how he did it........my guess was to create a lua file (empty if possible). make it call every frame during the "heart beat" (as falco says).then use a saprate thread to modify its content (yeah i know syncronisation problem :P),but will it work?
(P.S i have this annoying problem of putting "....." during chating ,forums etc.....dont mind me)
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
Eh, whatever. I'm still the original badass.M_D_K wrote:dude its called luaL_dostring. Sorry Falco you've no longer got the edgehellknight wrote:ohhh damn....i was thinking to it throwing something....my bad.......
(me->remeberCstyleCoding()....ok now i m good :P.)
just saw something very strange...(P.S. i m new to lua...so help me out plz :P)
if the source lua file is ok,only then it gets executed.(and i thought interpreters work one line at a time....nvr md me)
......so how does that api actually work?.......does the lua file get converted to a compiled code first or it is just interpreted on fly? and if it happens on the fly,then how can it know that the source lua file is "bad"? is it possible to modify the lua source file during run time?
(just saw the video where falco created that lua debug window..and was wondering how he did it........my guess was to create a lua file (empty if possible). make it call every frame during the "heart beat" (as falco says).then use a saprate thread to modify its content (yeah i know syncronisation problem :P),but will it work?
(P.S i have this annoying problem of putting "....." during chating ,forums etc.....dont mind me)
That is so true dude.GyroVorbis wrote: And it's not so much about the function that calls it as much as having a Lua system that is integrated badassed-ly enough to allow you to do cool things from a debug prompt. That's the real challenge.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.