Lua revisited
Eric ColemanI've been learning LUA and it's not designed to be a standalone scripting engine but to be something that's embedded in the game or application that uses it. I've been working on some "stuff" and I decided to use LUA as the scripting engine, so I've been learning a lot about it, mostly on my own since it's very difficult to find updated information. The only way to use LUA in a VB program is to write a C or C++ wrapper. Is anyone interested in learning how to do this? I should point out that there is no way to create a LUA dll for everyone to use. The scripting engine is EXTREMLY small and bare, so you have to write application specific code if you want to use it in your games. However, the embedding of any scripting language requires some sort of special interface for the scripts. Even the MS script control object is pretty useless unless you expose internal objects to the script control that allow the scripts to manipulate your program. There really is no way around having to write a scripting interface between the scripting engine and the program.
VBBRActually I started writing a wrapper sometime ago, and managed to get some things working. I managed to run a LUA line like MyFunc() so it calls MyFunc in a module showing an MsgBox succesfully. Unfortunately when it came to parameters and return values (which work with the LUA stack) everything started crashing and I gave up. I've learned a lot of C++ from there though, so maybe now I'm able to get this working (it would be something for a 0.1 alpha version [:D]). At the time I looked at it I found the LUA header file too confusing, also because I didn't know things like pointers should be passed as ByRef, so I just shot for ByRef and ByVal for every parameter until it worked =p. (actualy I still don't know if VB strings should be passed ByRef, ByVal, VarPtr or whatever) I'm really interested in making this thing work. I'll see if I find these files and take a look at them.
VBBROn another topic, but linked to this, how am I supposed to create a DLL in Dev-C++ that can be used in VB? I tried creating the DEF file and everything but it doesn't work. The exact same procedure works fine is VC++ (.NET). (but I'd like to use Dev-C++ because my HD is so full I can't even install VC++ now [:P])
VBBRLooks like I lost the original C++ source files (altough I still have some notes and the VB declarations). I was looking trough lua.h and here is a question... typedef struct lua_State lua_State; if lua_State is defined like this, would it work if I put (in VB) all the lua_State variables declared as Any? (it seems I had declared them as Long but I'm not sure if it's right)
Eric ColemanI've never used Dev-C++, so I can't answer any of those questions. What version of LUA are you using? 4 or 5? The lua state is LONG in VB (32bit integer). Actually, it's a pointer to a struct and pointers on a 32 bit system are 32bit numbers which are LONG data types in VB.
VBBRHm, that's what I thought. I have both LUA 4 and 5 here, and have been trying to get this to work in 5 (since it should be better as it's a newer version... altough I think 4 is easier... whatever) Also tutorials on LUA v5 seem to be a lot harder to find.
Eric ColemanI guess I'll get started on a LUA tutorial [:)]
VBBRFrom a VB programmer's point of view, even for C/C++, that would be fantastic. [:D] I could learn from your tutorial then do all the dirty work of porting the functions so they work in VB.
maxhamnerthe definitive online book (also available in paper form) PIL (programming in Lua), available here
Eric ColemanI've read that, but it does lack a lot of information. It describes the LUA language more than it describes how to hack the source code to embed it in an application. In my opinion, I don't think it adequately expresses how make the transition from tags to meta tables. Tags in LUA 4 were really nice and easy to understand. It took me a really long time to get a program working that used meta tables for my data structures. That book you mention uses tables instead of extending the program with meta tables, and the syntax you get from using tables for structures is just ugly IMHO. Using meta tables kind of allows you to overload the operaters, and that's quite handy, especially for math. Right now I'm working on some image processing stuff, and being able to define a color like C = RGBA(1,0.5,.3,0) is nice, but what's even nicer is to use syntax like C.R to get the red value or C.H to get the HUE. Meta tables are sweet :-)
Eric ColemanI noticed you live in Austin. I lived there for 3 years. I sure do miss having a Mexican Martini. Oh, and Amy's. That stuff is so damn good. I'm getting all nostalgic now, lol.
maxhamnerThere's just too much to love about Austin, Chuy's, Jovita's, Antones, Steamboat, the view at the Oasis (and avoiding their food), all the live music, Kerby Lane, Magnolia Cafe, the really wierd late night crowd at Star Seeds Cafe, and of course amys... Whew... think I need to get out more? LOL... I'll drop an Amy's cone in the mail to you... look for a soggy package in a week or so! LOL
Eric ColemanI hope you're keeping Austin wierd for me!