Delegating to C in Lua, 'require' functionality and RunScript

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
thispolo
Posts: 2
Joined: Thu Mar 24, 2022 3:03 pm

Delegating to C in Lua, 'require' functionality and RunScript

Post by thispolo »

Hi there! First, I'd like to congratulate the team on Command: Modern Operations. Really excellent stuff! The amount of work you have put into this software is very admirable :D

Just some clarification... I'm somewhat familiar with Lua and have only just started using it within CMO for some of my scenarios and I had some questions:
  • Is the Lua 'require' function supported at all? If not, why?
  • It's possible to call in to C functions from Lua, provided it has been enabled on the Lua-side. Is it possible to run C from Lua in the CMO implementation? This would be very useful for more intensive sorts of analysis.
  • Lastly, I've noticed when executing an external script via ScenEdit_RunScript that syntax errors are not reported in any way back to the main lua console, which makes it a bit awkward to bug test. Something I am missing?
Once again, many thanks!
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Delegating to C in Lua, 'require' functionality and RunScript

Post by KnightHawk75 »

Lua require is not permitted.
Any namespace\function that allowed access to IO are disabled in the non-professional version, the reason claimed is security concerns. It is not possible to call anything external without professional edition, be that C or anything else, you are limited to pure Lua and CMO Api only. You're not missing anything, they get suppressed in that RunScript context, you can usually view the actual error via monitoring the exception or lua log for that session, but no the console.
thispolo
Posts: 2
Joined: Thu Mar 24, 2022 3:03 pm

Re: Delegating to C in Lua, 'require' functionality and RunScript

Post by thispolo »

Ah, this makes sense. Thanks. Right now I am forced to simulate 'require' by using 'RunScript' and to prevent duplicated execution using global variables.

I've looked into the Lua log for 'RunScript' and the only thing that gets logged, if a script has a syntax error, is that the script was "ran" and nothing else. As far as I can tell, this isn't something pcall can pick up either, which would be fine if it were a runtime error. Not to mention, the lua script continues to run as if nothing happened which means if you're relying on 'RunScript' to initialise some variables, then the nil values will propagate much further down the tree and break the script in unexpected places.

For what reason are they surpressed in the RunScript context?
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Delegating to C in Lua, 'require' functionality and RunScript

Post by KnightHawk75 »

For what reason are they surpressed in the RunScript context?
---
Have to ask Michael for the real answer, it may just be fallout from how lua,nlua and cmo are interacting wrapped and where things bomb, or it may have to do with runscript in console context vs runscript under the event context.
Post Reply

Return to “Lua Legion”