Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58430 Members - Latest Member: Jesse Webb

April 27, 2024, 04:12:13 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Lua and code::blocks
Pages: [1]
Print
Author Topic: Lua and code::blocks  (Read 7857 times)
kafka
Guest
« on: February 02, 2009, 10:52:40 PM »

Has anyone tried to use Lua on code::blocks. Or LuaPlus or Google's V8. I don't really know, how to install any of these.  Sad
Logged
increpare
Guest
« Reply #1 on: February 02, 2009, 11:00:37 PM »

i got lua to work fine with codeblocks; was a matter of setting the includes directory and linking to the right libs.  Unless you mean building lua, which I haven't tried...

if you know how to install stuff in general, you'll be ok (though, I'm guessing you don't?); as i recall, finding examples to compile can be somewhat harder....
Logged
kafka
Guest
« Reply #2 on: February 02, 2009, 11:07:20 PM »

i got lua to work fine with codeblocks; was a matter of setting the includes directory and linking to the right libs.  Unless you mean building lua, which I haven't tried...

if you know how to install stuff in general, you'll be ok (though, I'm guessing you don't?); as i recall, finding examples to compile can be somewhat harder....
Well yeah. I put lua include and library files in the right places and stuff. And then... I tried to run a lua file... Nothing happens. I try to use the print -command in the .lua file. Nothing shows up in the screen. Can you post some example code you got to work? It's frustrating when I'm trying to learn from tutorials and the codes won't even work.  Grin
Logged
increpare
Guest
« Reply #3 on: February 02, 2009, 11:13:34 PM »

here's my lua config file loader, that loads variables from a file

Code:
#include <iostream>
#include <math.h>

#include "config.hpp"


float C_MAXDEPTH=500;
float C_MAXREALDEPTH=50;

int C_SCREEN_WIDTH=640;
int C_SCREEN_HEIGHT=480;
bool C_FULLSCREEN=1;
bool C_ASPECTFLAG=0;

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <stdlib.h>
#include <stdio.h>
}

float getmaxdepth(){return C_MAXDEPTH;}
float getmaxrealdepth(){return C_MAXREALDEPTH;}
int getscreenwidth(){return C_SCREEN_WIDTH;}
int getscreenheight(){return C_SCREEN_HEIGHT;}
bool getfullscreen(){return C_FULLSCREEN;}
bool getaspectflag(){return C_ASPECTFLAG;}

void load_config_vars()
{
    int status, result;
    lua_State *L;

    /*
     * All Lua contexts are held in this structure. We work with it almost
     * all the time.
     */
    L = luaL_newstate();

    luaL_openlibs(L);

    /* Load the file containing the script we are going to run */
    status = luaL_loadfile(L, "settings/config.txt");
    if (status) {
        /* If something went wrong, error message is at the top of */
        /* the stack */
        fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
        exit(1);
    }

/* Ask Lua to run our little script */
    result = lua_pcall(L, 0, LUA_MULTRET, 0);

    lua_getglobal(L,"screenwidth");
    C_SCREEN_WIDTH = (int)(lua_tonumber(L, -1));

    lua_getglobal(L,"screenheight");
    C_SCREEN_HEIGHT = (int)(lua_tonumber(L, -1));

    lua_getglobal(L,"fullscreen");
    C_FULLSCREEN = (int)(lua_toboolean(L, -1));

    lua_getglobal(L,"maxdepth");
    C_MAXDEPTH = (int)(lua_tonumber(L, -1));

    lua_getglobal(L,"maxrealdepth");
    C_MAXREALDEPTH = (int)(lua_tonumber(L, -1));

    lua_close(L);   /* Cya, Lua */

}

Logged
kafka
Guest
« Reply #4 on: February 02, 2009, 11:30:30 PM »

Hmm. Thanks. I'll try this one out, when I get home from work. I'm making a engine, that uses Lua for scripting etc. so is this the right choice for using Lua or does somebody have better ideas?  Smiley
Logged
TeaAndBiscuits
Level 0
***


View Profile
« Reply #5 on: February 03, 2009, 07:56:56 AM »

Quote
so is this the right choice for using Lua or does somebody have better ideas? 

I assume you mean is Code::Blocks a good IDE for editing LUA? Good question! I always use Notepad++ for my LUA which is ok... not great. I'd much prefer a more complete environemnt.

-T&B
Logged
dklon
TIGBaby
*


View Profile
« Reply #6 on: February 03, 2009, 03:18:59 PM »

I've been using Lua right now for some simple programs with Code::Blocks as the main IDE.  However I use Notepad++ for the Lua code, and CB for all of the C stuff.  It seems to be a good relationship, even if it can get confusing at times switching back and forth.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic