Jump to content

Lua and Framework


Paul Thomas
 Share

Recommended Posts

I had spent hours converting my project from 2.27/2.28 to 2.3. One of the important portions of the project move to me was the render classes, which was basically a full customized version of the 2.27 framewerk. I was able to get everything running as it should except of course the Lua scripts. "fw" was never nil but things like "fw.renderer" failed.

 

I then decided to just grab the newest framework from the 2.3 folders, get Lua working properly, and then I can rewrite the framework for my project needs (cloud/weather system, custom post-processing effects, etc.). That didn't go very well because of how the project is overall structured. I can't understand why either and that is the point of this post.

 

The normal way is to do the following:

 

import "framework.bmx"

global fw:tframework = tframework.create()
setscriptobject("fw", fw)

 

fw.main.world would work, fw.renderer would work, and so forth. However, since my project is structured a certain way, doing it this way would destroy the organization, so my first attempt (and I will be skipping all my other two+ hours of other attempts) was the following (with some explanation of my projects structure for clarity):

 

'//-- main.bmx/main.exe
global E:engine = new engine

E.initialize()

while not E.S.Quit()
 E.update()
 E.draw()
wend

E.unload()

End

 

'//-- engine.bmx

include "database/manager.bmx"
include "debug/manager.bmx"
include "content/manager.bmx"
'//-- etc
include "render/manager.bmx"
'//-- etc

type engine

 field DB:databasemanager = new databasemanager
 field DM:debugmanager = new debugmanager
 field CM:contentmanager = new contentmanager
 '//-- etc
 field RM:tframework = new tframework ' -- tried multiple variations and naming
 '//-- etc

 method initialize()
   DB.initialize()
   DM.initialize()
   CM.initialize()
   '//-- etc
   RM.initialize() ' -- does the same as tframework.create() does
 endmethod

endtype

 

RM.main.world works fine, RM.renderer works fine, but this will completely fail:

 

setscriptobject("fw", RM)

 

Having Lua give error about "fw.renderer" or "fw.transparency.world" and so forth, even though RM.renderer and RM.transparency.world work just fine in bmax.

 

Not really sure what I'm missing. Anyone know who has tried the same thing? Anyone know why my version doesn't exactly work correctly?

Link to comment
Share on other sites

I'm probably missing something obvious but I've tried multiple things. Even if I got this done correctly I would have to expand the "commands.bmx" portion for any additional methods I create. This is honestly becoming less ideal for programs that are going the more custom route when it comes to framework. Either it is very lenient and I'm missing something, or it isn't.

 

Lua is really fun so I'm desperately trying to get this to work. Not to mention Lua could make multiple things easier for the project instead of hard-coding every single aspect of the project.

Link to comment
Share on other sites

I am assuming you imported the framework.bmx?

 

And you put your

setscriptobject("fw", RM)

sometime after E.initialize:

'//-- main.bmx/main.exe
global E:engine = new engine

E.initialize()

while not E.S.Quit()
 E.update()
 E.draw()
wend

E.unload()

End

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

I have, the setscriptobject() is being called and is passing the object to Lua. In Lua "fw" isn't nil but methods like "fw.main.camera" don't work.

 

I had first tried using my own framework which is several weeks worth of programming to use different types of effects, cloud system, weather system, etc., so I was attempting to salvage my last framework. I ended up with the same problem, Lua couldn't use the "fw" global correctly.

 

So then I tried using the new framework and ended up with the same problem.

 

It only seems to work successfully using the "normal" way of using framework. Worse case scenario I'll reprogram my whole framework/engine/client for this but it isn't ideal. It's a lot of reprogramming simply because I can't pass the framework object correctly to Lua.

 

I'm hoping I'm just missing something.

Link to comment
Share on other sites

This issue has been solved and I'm attempting to figure out how exactly.

 

I had rebuilt the whole project adding file by file attempting to find the problem. I first started with a simple program that did nothing but quickly setup the abstract path, graphics, and the loop. I added the "setobjectscript()" functions as well.

 

I first included the framework files that I had in the last project, made them a Lua global, recreated the lugi.generator generated file and bam; worked fine without a problem. I eventually erased the quickly added code and slowly added file by file determined to find what the issue was. I added the last file and still no error.

 

The only difference is that I didn't use lugi.generator with the file "framework/commands.bmx" included. This is the only difference between the two projects. Within the lugi.generator generated bmx file, there is no TFrameworkCommands and everything works perfectly fine.

 

Thanks everyone for your help. In these forum replies as well as in PM's.

Link to comment
Share on other sites

Yeah, BlitzMax import/include files are very difficult to understand and to get to work. That's why I switched to C++, since it's so much easier there :)

 

BlitzMax could be made much easier too, if it would have a decent header file for the engine.dll, and not trying to call mod files directly.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...