Post subject: Improve the Lua framework
Joined: 1/26/2009
Posts: 558
Location: Canada - Québec
Hi there, Note: this is still a work in progress Lately I've been (re)working on a Lua project and as the project grow bigger and bigger and thought it would be nice take a break with writing barely readable script with some fuzzy logic, like we can find a lot on this site. So I did some research to learn how to get thing done with an OO lua way and after I the wall several time to actually understand what's going on with object lua from a library to an another, I found the Koneki project. Basicly, it's a Lua IDE based on Eclipse, but it has a couple a cool features that make it worth using it, rather than some other IDE/text editor. Now, I don't want to show off useless stuff, but this is still a big deal to help new comer to Lua with ambitious project. But here is the major feature that hooked my interest:
    * Using luadoc as way to trigger autocompletion over severals modules.
This is simply genius. Not only you have to actually think about how to structure the lua code in an OO fashion, but you have to do it while adding doc, so other can directly understand. So here's my idea for now: encourage lua user to stop doing trial and error with the lua console from his favorite emulator and make them try to actually run the code on a IDE that running with a standalone lua 5.1 for a completly new programming experience. But as you might expect, the major encombrance here's is that the core function from the emulator aren't avalaible, so we have to provide them. Here's a picture about what I'm talking about. The following code describe how to handle the embedded module that try to mimic the emulator API...
Language: lua

---The gui Library -- Functions mainly for drawing on the screen are in the gui library. -- @module gui if _G.gui then return _G.gui; end local gui={}; --- Register a function to be called between a frame being prepared for displaying -- on your screen and it actually happening. Used when that 1 frame delay for -- rendering is not acceptable. function gui.register(func) end ---Returns a screen shot as a string in gd's v1 file format. -- This allows us to make screen shots available without gd installed locally. -- Users can also just grab pixels via substring selection. -- @usage Usage examples: -- gd.createFromGdStr(gui.gdscreenshot()):png("outputimage.png") -- @return #string function gui.gdscreenshot() end --more luadoc return gui;
So, how neat is that? Basicly, just "mock" all the functions and your good to go. The script will run fine on both standalone lua and your favorite emulator. You can see a project here that try to use this kind of framework. Also, I did a couple of testing with iup library and I believe we can easily create interactive windows form that doesn't lag while the emulator is running with any emulator(even those that doesn't support the fceux auxlibs). Here's an implemention that does work. So yeah, I'm pretty sure this the kind of stuff that could become very handy for some project. I do have a couple other idea, such as adding advanced math function like integral(f,x,a,b), so it make it easier for user trying to program some cool algorithms, etc. So that's about it, if there's any interest I'll probably make a quick tutorial about how to setup Koneki, since like any Eclipse-based IDE... there's 2-3 thing to config first, before been able to use it correctly.
Skilled player (1743)
Joined: 9/17/2009
Posts: 4986
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Hm.... Can it be expanded so that you can also test bot scripts and other memory reading functions while scripting on a IDE?
Joined: 1/26/2009
Posts: 558
Location: Canada - Québec
Yes, it can definitly be extended to this point! Back then, there used to be something called LuaBot, but that was kinda a pain to understand how to actually use it. The framework should be able to improve some stuff about this. Thought, since every game is different, I seriously believe it's better to simply offer a common library of toolset, so the TASer can design his own bot and experiment by himself. In order to perform massive test inside the IDE, the memory function is indeed a problem since it return a default value. To solve this, we can try to mimic the possibles values to be generated according to a "fake emulator state"(good enough for testing a lot of use case). The other solution would be to plug the IDE with the emulator via a communication interface such as luasocket, but this can get a bit over-complicated here, I wouldn't this recommand at the moment. Right now, the framework simply seek to provide help for someone that want design his bot or any other project efficiently(with OO) and doesn't mind to test the "real thing" separately on the emulator. In general, the standalone lua interpreter should be used for debugging purpose.