Programming Language support in WML (was '[nowml] tag')

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Programming Language support in WML (was '[nowml] tag')

Post by toms »

The idea:

In a [nowml] tag, you can let the computer execute C++ commands. (or even other languages, depending if it´s possible)

Pros and cons:

For those who know C++, it can help to do some things WML can´t do. Or things may be done shorter.
Here are two examples of other people´s ideas where it can be used.
http://www.wesnoth.org/forum/viewtopic.php?t=11263
http://www.wesnoth.org/forum/viewtopic.php?t=11063


It may crash very hard, though. But maybe a part could be included that saves the computer from a crash.


What do you think?

EDIT: Have renamed thread something a bit clearer. --Irrevenant
Last edited by toms on May 20th, 2006, 6:25 am, edited 1 time in total.
First read, then think. Read again, think again. And then post!
User avatar
irrevenant
Moderator Emeritus
Posts: 3692
Joined: August 15th, 2005, 7:57 am
Location: I'm all around you.

Re: What about a [nowml] tag?

Post by irrevenant »

toms wrote:It may crash very hard, though. But maybe a part could be included that saves the computer from a crash.
Couldn't it be worse than that; couldn't someone use it to infect players computers with malware (viruses, trojans, etc.)?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Umm...no. Can't be done.
Woodwizzle
Posts: 719
Joined: December 9th, 2003, 9:31 pm
Contact:

Post by Woodwizzle »

Security issues asside, I believe this is borderline impossible. C++ is a compiled language not an interpreted one which means for code to work it need to be compiled (go figure). So A. we would need to bundle a compiler with wesnoth and B. it would have to be run to whenever this code was encoutered in WML. Absolutely crazy nuts impossible =). Something like Python or Lua would be more feasable, but still not likely as it would also require the interpreter to be bundled, there is a large risk of security issues, and it would still be a relatively massive undertaking for the dev team when WML has been functioning just fine without it.
Signature dropped due to use of img tag
User avatar
Maeglin Dubh
Moderator Emeritus
Posts: 1154
Joined: November 16th, 2005, 8:38 pm
Location: Valley of the Shadow of Death
Contact:

Post by Maeglin Dubh »

Alteration of lockage....
Standard two-page rule, gentlemen. This one seems iffy to me, on a security front, but I'll let it run it's course.
Carry on.
Leo
Posts: 54
Joined: January 19th, 2006, 5:08 pm
Location: St.Petersburg, Russia
Contact:

Post by Leo »

Problem: This will require C++ compiler embedding
Darth Fool
Retired Developer
Posts: 2633
Joined: March 22nd, 2004, 11:22 pm
Location: An Earl's Roadstead

Post by Darth Fool »

Well, there are C++ interpreters of sorts out there (look up ROOT at Cern), but if you are going to use an interpreted language, C++ is not really the best choice. With whatever interpreted language you use, you have to make available the data from within the wesnoth code for it to manipulate. The closest to doing something like this is the Python AI, and since python already needs to be included for the AI, despite my dislike of it as a language, it would be the natural thing to use for such a tag. That said, a lot of work needs to go on even with the AI interface for Python, and I don't see putting hooks in everywhere for python to get access to the wesnoth data, since that would be a big pain be a maintenance nightmare and not to mention have potential performance hits. So, basically, I don't see this happening.
Dacyn
Posts: 1855
Joined: May 1st, 2004, 9:34 am
Location: Texas

Post by Dacyn »

What about linking to a precompiled executable?
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

The idea of allowing one to use Python, or some other interpreted language has been around for a while.

This is actually not a bad idea, we'd just need someone to write an interface for Python, much like we have the existing AI interface.

Allowing C++ would not be feasible.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
zaimoni
Posts: 281
Joined: January 27th, 2005, 7:00 am
Location: Linn Valley, KS U.S.A.
Contact:

Post by zaimoni »

C++:
I wish.

I've considered this myself (for one of my internal projects), but it just won't work unless Wesnoth can compile itself. [The low-level ABI must be compatible, so outsourcing the compiler is not practical.] And that's a harder project than Wesnoth, so I just don't see it happening.

Python:
I suppose that if the WML interpreter was written in Python, then including native Python would be reasonable.

That's a pretty big if. I don't know how much of a speed hit would be involved, and maintaining two versions of the WML interpreter would be impractical without an automatically generated parser from a single machine representation of the (EBNF?) grammar.

Also, note that Python is not stable enough for long-term embedding. There are a number of planned changes (e.g., redefining what 3/2 gives as a result is scheduled for Python 3.0) that would play havoc with embedded Python in WML.
Woodwizzle
Posts: 719
Joined: December 9th, 2003, 9:31 pm
Contact:

Post by Woodwizzle »

Another posibility would be lua. Though python can be embedded into other programs, lua was more or less designed to be embedded into other programs. As I understand it you can pick and choose which bits and features of the language to include making it as lightweight or feature rich as Wesnoth would need it to be. It is also more lightweight and easier to embed than python. Its syntax is closer to C (for better or for worse). Angband is a free open source game that has included lua scripting. Lua is also used in commercial games such as FarCry and WoW.
Signature dropped due to use of img tag
zaimoni
Posts: 281
Joined: January 27th, 2005, 7:00 am
Location: Linn Valley, KS U.S.A.
Contact:

Post by zaimoni »

I've worked with Lua a bit (abortive Angband variant).

Lua's biggest disadvantage is that it doesn't have good support for reflecting C++ classes/objects...because it doesn't have objects (as of V5). This doesn't matter that much for Angband because it's written in C with a custom FORTRAN-like memory manager, but it gave me problems when trying to convert my variant to non-object-oriented C++.

Something that's truly object-oriented like Wesnoth...I don't see how you'd automate the reflection to LUA, or even do it cleanly by hand. [Boost's python module was designed to reflect C++ classes to Python 2.2, even in MSVC++ 6. It probably would need maintenance for more recent versions of Python.]

[ EDIT: just rechecked docs...Boost.Python is not multithread-aware. Latest version works with Python 2.4 API.]
User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Post by Viliam »

I did not work with Lua, only read a few tutorials, but it seems to me that Lua should support object-like syntax.

There is a Lua datatype called "userdata", which contains a C "void *" value -- from Lua's point of view it is a black box; you can assign it to another variable, and compare two Lua variables on equality. When you try to read or write a property on this variable, Lua provides a "fallback" mechanism to extend the syntax, and you can call e.g. a callback function "set_property(object, property, value)" or "get_property(object, property)". It looks complicated, but it means that you can write things like:

Code: Select all

i = unit.hitpoints
unit.hitpoints = i / 2
Where "unit" is a Lua userdata variable containing a pointer to unit, and "i" is Lua integer variable.

At least this is how the older versions of Lua worked. Now in version 5.1 there is some concept of "metatables", which seems to be a replacement of the "fallback" functions, providing a similar functionality.
zaimoni
Posts: 281
Joined: January 27th, 2005, 7:00 am
Location: Linn Valley, KS U.S.A.
Contact:

Post by zaimoni »

That confuses structs (data members) with classes (data members and methods). Lua handles C structs fine.

The only way I found to make Lua handle method invocations, was to rewrite the method invocation as a C function. This fails (catastrophically) when virtual member functions need to be rewritten...exactly when you want C++.
catwhowalksbyhimself
Posts: 411
Joined: January 23rd, 2006, 8:28 am

Post by catwhowalksbyhimself »

Check out lua's use in ToME 3 Alpha(a very complex Angband variant where most of the system's programing is entirely in Lua) and in the earlier, and more like what you'd need for Wesnoth, ToME 2. (t-o-m-e.net) That'll give you some idea over how these problems can be rather easily overcome.
Post Reply