• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:34
CEST 15:34
KST 22:34
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
ByuL, and the Limitations of Standard Play1Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12TL.net Map Contest #22 - Voting & Ladder Map Selection7Code S Season 2 (2026) - RO8 Preview8
Community News
[TLMC] Summer 2026 Ladder Map Rotation05.0.16 patch for SC2 goes live (8 worker start)63ZeroSpace at Steam NextFest - Last free demo31Weekly Cups (June 8-14): Clem and Solar double, PTR tested0RSL: S6 Finals played at BlizzCon 202611
StarCraft 2
General
Mizenhauer's Douyu Cup Preview ByuL, and the Limitations of Standard Play Enough with this crap patch: boring and suck! Is the larve respawn broken? 5.0.16 patch for SC2 goes live (8 worker start)
Tourneys
Douyu Cup 2026: $20,000 Legends Event (June 26-28) INu's Battles#17 <BO.9> RSL Revival: Season 6 - Qualifiers and Main Event Sparkling Tuna Cup - Weekly Open Tournament GSL CK #4 20-21th June
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 531 Experimental Artillery Mutation # 530 One For All Mutation # 529 Opportunities Unleashed
Brood War
General
ASL 22 Proposed Map Pool Quality of life changes in BW that you will like ? [BSL22] Non-Korean Championship from 13 to 28 June BSL Season 22 BW General Discussion
Tourneys
[Megathread] Daily Proleagues The Casual Games of the Week Thread [BSL22] GosuLeague Casts - Tue & Thu 22:00 CEST CSLAN 4 is Coming!
Strategy
Why doesn't anyone use restoration? Simple Questions, Simple Answers Relatively freeroll strategies Creating a full chart of Zerg builds
Other Games
General Games
Beyond All Reason Nintendo Switch Thread ZeroSpace at Steam NextFest - Last free demo Stormgate/Frost Giant Megathread Games for Kids
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
Vanilla Mini Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread [H]Internet/Gaming Cafe Tips and Tricks
Fan Clubs
The HerO Fan Club! The herO Fan Club!
Media & Entertainment
Movie Discussion! Series you have seen recently... [Req][Books] Good Fantasy/SciFi books [TV/BOOK] *SPOILERS* Game of Thrones Discussion
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 McBoner: A hockey love story Formula 1 Discussion Cricket [SPORT]
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Facing Challenges in Mobile App Development
TL Community
The Automated Ban List
Blogs
How To Predict Tilt in Espor…
TrAiDoS
An Exploration of th…
waywardstrategy
I'm an arrogant trash talke…
FlaShFTW
Gauntlet SC2: A Retrospectiv…
Ctone23
Why RTS gamers make better f…
gosubay
Customize Sidebar...

Website Feedback

Closed Threads



Active: 10509 users

The Big Programming Thread - Page 74

Forum Index > General Forum
Post a Reply
Prev 1 72 73 74 75 76 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Craton
Profile Blog Joined December 2009
United States17291 Posts
August 18 2011 01:14 GMT
#1461
If something is O(n log n) and I'm sorting 1,000,000 numbers, how do I calculate that. I'm missing something.
twitch.tv/cratonz
Frigo
Profile Joined August 2009
Hungary1023 Posts
August 18 2011 15:06 GMT
#1462
On August 18 2011 10:14 Craton wrote:
If something is O(n log n) and I'm sorting 1,000,000 numbers, how do I calculate that. I'm missing something.

The constant term in the big O expression can be arbitrary, you need specific knowledge of how many steps does the algorithm take* and what are these steps, to calculate anything. In practice it is easier and better to measure the speed of the algorithm in msec instead of steps.

*: Also these steps can vary for the input data, so you are better off calculating maximum and average cases, assuming a specific distribution of the input data or extreme cases.

On August 15 2011 08:08 EvanED wrote:
Show nested quote +
On August 14 2011 14:49 Frigo wrote:
No sorry, the compiler is quite right about warning you, it simply can't be made safe. You need to know in advance whether the line fits in your buffer, and that is simply not possible with the standard input, only with files.

This is a bit of a red herring, which can be demonstrated two ways. First, calling fgets(buf, size, stdin) works fine, and is just like calling gets(buf) except that if it reads more than size bytes, it will stop early. (There's a difference in how it handles the trailing newline if it doesn't stop early, as well.) It's not like fgets is imbued with psychic powers to see what's coming up in the stream, it just makes a "best-effort" attempt to fit it in the given buffer. The second way you can see this is calling fgets on an actual file -- it doesn't figure out that the current line is too long to fit into the buffer and does nothing, it again makes that best-effort attempt.

(And as a third way: just because the runtime thinks something is a file doesn't mean it is -- it could be a device node, a fifo, etc. -- and doesn't mean it can seek randomly.)


Obviously the statement is true only for gets, fgets is completely different, it is not "just like" gets. This difference between gets and other methods makes it possible to employ various workarounds so you don't need to know the length of the line in advance to ensure safe operation. For the same reason it is also possible to use them on streams. I'd say the guy is best off by implementing an automatically growing vector structure and associated getline functions instead of sacrificing safety with gets or fooling around with a naked fgets.
http://www.fimfiction.net/user/Treasure_Chest
catamorphist
Profile Joined May 2010
United States297 Posts
August 18 2011 18:16 GMT
#1463
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Pigsquirrel
Profile Joined August 2009
United States615 Posts
August 18 2011 18:42 GMT
#1464
Quick Java question: Is it considered bad manner to have 600+ threads in a Java application?
Craton
Profile Blog Joined December 2009
United States17291 Posts
Last Edited: 2011-08-18 19:29:40
August 18 2011 19:29 GMT
#1465
Finished interview, went okay.

On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.
twitch.tv/cratonz
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-18 19:58:56
August 18 2011 19:49 GMT
#1466
On August 19 2011 04:29 Craton wrote:
Finished interview, went okay.

Show nested quote +
On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.


Well, yeah, I'm mostly talking about people who have some amount (maybe a year or two) of C# experience. But man, there's sure a lot of low-hanging fruit:

- Cruft from prior versions. Three separate framework ways to parse XML nowadays. Non-generic collections that are basically obsolete implementations of the generic ones. A ton of different threading APIs (i.e. Thread, ThreadPool, BackgroundWorker, Task, BeginInvoke, and to some degree the new C# 5 async) that all solve overlapping problems.

- Events and properties aren't first-class, which is frustrating. I can't even get a delegate pointing to the "get" method of a property without writing a big blob of reflection. I can't pass an event down to a method so that the method can fire it without making a wrapper function.

- Type inference is spotty. Why can it infer return types of initialized local variables, but not types of initialized class properties? Why can it infer return types of anonymous functions, but not named functions? These are just arbitrary decisions.

- While I'm at it, generic type constraints are crappy and limited. I can't even write public class X<T> where T : new(int, string) and make a constructor constraint. Come on!

- Reference types are nullable by default and can't be declared as permanently non-nullable, which may be the most crash-inducing design decision ever yet invented on this planet.

- No language support for purity or immutability constraints. I figured they would add an immutability check in 4.0 when they added generic covariance and contravariance, but nope.

- No language support for declaring or enforcing the thread safety of methods or declaring a method atomic with respect to callers. No language or library support for any kind of STM.

- No language support for pattern matching or destructuring function arguments.

- No language support to make tuples easier to work with (e.g. as they have in F#.)

A lot of the problems with .NET and C# won't seem like problems until you have some experience and encounter them a few times, or unless you have used other languages that do a better job of tackling them. But if someone can't think of *any* significant problems, then I get concerned, because I worry that the person in question just doesn't know what good code is and what's a hacky workaround.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
themikeman
Profile Joined July 2011
United States8 Posts
August 19 2011 02:20 GMT
#1467
What is inheritance by reference and how do you design a class implementing inheritance by reference?
There isn't a man in history that's led a life of leisure that has been worth remembering.
Sachem
Profile Joined May 2011
United States116 Posts
August 19 2011 02:43 GMT
#1468
You should add this as a guide to obfuscation, old, but I still get a great laugh out of it: http://thc.org/root/phun/unmaintain.html
rabidch
Profile Joined January 2010
United States20289 Posts
August 19 2011 03:05 GMT
#1469
On August 19 2011 11:43 Sachem wrote:
You should add this as a guide to obfuscation, old, but I still get a great laugh out of it: http://thc.org/root/phun/unmaintain.html

i spent 5 minutes laughing at the lisp code
LiquidDota StaffOnly a true king can play the King.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
August 19 2011 22:43 GMT
#1470
A project I'm contributing to at work involves parsing a WSDL using C#. I read about XMLReader being the best option in terms of performance, so at the moment have used that. What we want to be able to do is parse the WSDL once and get all the nodes, elements and attributes then. My main question is - how to best store all this information? I was thinking dynamic arrays, and have some experience doing it with ArrayLists (using Java), but I've heard recommendations for using List<T>. Perhaps there's a better way?

I'm back home now so I do not have access to the actual code being used, but this is the pseudocode for what we're trying to do:

User selects which WSDL they want to work with

After selecting the WSDL
- parse the WSDL for the operation names (CreateCart/ModifyCart/etc)
- display the operation names in a drop-down box

After selecting the operation names..
- other stuff involving the operation they want to do, and what course to follow based on the WSDL information for that operation

There will be a lot of information to parse through to display the options to the user for how to proceed from there. Oh, and the users will be internal quality assurance testers (it's a program to help them produce tests for the constantly changing software going out to customers)

Again, I just want to know what you think would be the best way to store these different types of information after parsing the WSDL (preferably just once), and perhaps if you think there's a better way to parse the WSDL than doing XMLReader in C#.
Undefeated TL Tecmo Super Bowl League Champion
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-19 23:40:28
August 19 2011 23:37 GMT
#1471
On August 20 2011 07:43 EscPlan9 wrote:
A project I'm contributing to at work involves parsing a WSDL using C#. I read about XMLReader being the best option in terms of performance, so at the moment have used that. What we want to be able to do is parse the WSDL once and get all the nodes, elements and attributes then. My main question is - how to best store all this information? I was thinking dynamic arrays, and have some experience doing it with ArrayLists (using Java), but I've heard recommendations for using List<T>. Perhaps there's a better way?

I'm back home now so I do not have access to the actual code being used, but this is the pseudocode for what we're trying to do:

User selects which WSDL they want to work with

After selecting the WSDL
- parse the WSDL for the operation names (CreateCart/ModifyCart/etc)
- display the operation names in a drop-down box

After selecting the operation names..
- other stuff involving the operation they want to do, and what course to follow based on the WSDL information for that operation

There will be a lot of information to parse through to display the options to the user for how to proceed from there. Oh, and the users will be internal quality assurance testers (it's a program to help them produce tests for the constantly changing software going out to customers)

Again, I just want to know what you think would be the best way to store these different types of information after parsing the WSDL (preferably just once), and perhaps if you think there's a better way to parse the WSDL than doing XMLReader in C#.


XmlReader is very low-level. The typical way to parse XML in C# nowadays is using the XDocument API, which is built on top of XmlReader. I don't really see why the parser's performance would be relevant when parsing a handful of WSDL files; one wouldn't expect them to be very large.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
August 20 2011 01:53 GMT
#1472
Wow XDocument looks really handy and easy to use compared to XMLReader thanks for the suggestion!

Good point about the performance part - the largest WSDL is maybe 1 MB? Either way its not like hundreds of MBs. I don't think there would be enough of a difference for that to be such a huge factor in the decision.

This application is going to be dynamically creating labels, text fields and checkboxes based on information it receives from the WSDL (i.e. checkboxes on boolean), so I will need to organize a lot of information parsed from the WSDL for later use. Is there any significant difference between storing a lot of this information in ArrayList rather than List<t> ? I suspect this question might be too context specific for what I'm working with. If that's the case, I'm more familiar with working on ArrayLists, so I would just choose that.
Undefeated TL Tecmo Super Bowl League Champion
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-20 02:07:56
August 20 2011 02:06 GMT
#1473
On August 20 2011 10:53 EscPlan9 wrote:
Wow XDocument looks really handy and easy to use compared to XMLReader thanks for the suggestion!

Good point about the performance part - the largest WSDL is maybe 1 MB? Either way its not like hundreds of MBs. I don't think there would be enough of a difference for that to be such a huge factor in the decision.

This application is going to be dynamically creating labels, text fields and checkboxes based on information it receives from the WSDL (i.e. checkboxes on boolean), so I will need to organize a lot of information parsed from the WSDL for later use. Is there any significant difference between storing a lot of this information in ArrayList rather than List<t> ? I suspect this question might be too context specific for what I'm working with. If that's the case, I'm more familiar with working on ArrayLists, so I would just choose that.


The only significant difference is that ArrayList will be more of a pain in the ass to deal with, since it's not generic. (There's a performance problem with big ArrayLists containing value types due to boxing, but it wouldn't be significant unless you had much more data.)

I personally have literally never used an ArrayList since C# 3.0 came out, and I can't think of any reason to ever recommend it. List<T> is basically strictly better. But if you don't mind casting your data every time you access the list, then I guess you can use whatever you please.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Craton
Profile Blog Joined December 2009
United States17291 Posts
August 20 2011 02:07 GMT
#1474
Lists are basically the superior form of ArrayLists.
twitch.tv/cratonz
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 15:09 GMT
#1475
I just want to start this off with: I have no idea how to script or code. I've never done either and I've never taken classes or anything.

Having said that my question should be pretty simple.

Let me explain myself a bit, I'm working as a networking engineer for a company, we have this software called Paessler Network Monitor. We are using it to track devices on our network that are installed remotely, and to track their data usage.

This network monitoring software also comes with a separate application called the billing tool, this tool comes with a few scripts and templates scripted in lua.

Basically it has these scripts stored in a directory. You open up the billing tool, create a new customer name, and associate a template with it. Now the templates I'm guessing are customizable. And I've been playing around with it for a while, because I'm honestly not retarded, but I can't for the life of me get it to generate any kind of billing report.

If someone could explain to me specifically what I am able to modify in the script and possible values and things like that I would be eternally grateful

Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

if SensorChannel(1) ~= nil then
freeVolumeGB = 15
costPerGB = 50
currency = "$"
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024))
calculateGB = sumGB - freeVolumeGB
if calculateGB <= 0 then
calculateGB = 0
end

invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


I know it's probably very simple for one of you guys in here, but it's just not clicking for me.

Any help or advice is appreciated.
Craton
Profile Blog Joined December 2009
United States17291 Posts
Last Edited: 2011-08-22 19:21:31
August 22 2011 19:09 GMT
#1476
On August 23 2011 00:09 TadH wrote:
Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool") //load code
invoice = GetInvoice() //get invoice then stores it as 'invoice'

if SensorChannel(1) ~= nil then //dunno what sensorchannel is
freeVolumeGB = 15
costPerGB = 50
currency = "$" //probably sets as USD
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024)) //calculates total gigabytes
calculateGB = sumGB - freeVolumeGB //calculates unused gigabytes
if calculateGB <= 0 then //GB can't be negative
calculateGB = 0
end

//these lines seem to add text to the invoice being made
invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

//seems to calculate the USD cost per Kilobit
if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

//adds text to invoice
invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


Added comments. You should have documentation about what else you're able to use.
twitch.tv/cratonz
Sentient
Profile Joined April 2010
United States437 Posts
Last Edited: 2011-08-22 20:06:33
August 22 2011 20:04 GMT
#1477
On August 19 2011 04:49 catamorphist wrote:
Show nested quote +
On August 19 2011 04:29 Craton wrote:
Finished interview, went okay.

On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.


Well, yeah, I'm mostly talking about people who have some amount (maybe a year or two) of C# experience. But man, there's sure a lot of low-hanging fruit:


I've done C# exclusively for about six years, and I want to criticize some of your low-hanging fruit decisions, but first let me offer my own.

I can't stand how the DependencyProperty system in WPF and Silverlight so flagrantly violates type safety. Consider the following cases:


int a = 5;
double b = a; // totally fine
SetValue(SomeDependencyPropertyOfTypeInt, a); // success
SetValue(SomeDependencyPropertyOfTypeInt, b); // exception! b is a double, int was expected
SetValue(SomeDependencyPropertyOfTypeDouble, 5); // exception! 5 is an int. Need to pass 5.0 instead.


Worse yet, GetValue(SomeDependencyPropertyOfTypeInt) returns type object! You have to cast it to the appropriate type. More than once my head has exploded trying to refactor a DependencyProperty from one type to another, because it requires hunting down every single cast operation. I don't understand why you can't do SetValue<type>(SomeDependencyProperty, a) and GetValue<type>(SomeDependencyProperty). Then the compiler could warn you and even disambiguate the 5/5.0 issue.

About some of your examples:

- Reference types are nullable by default and can't be declared as permanently non-nullable, which may be the most crash-inducing design decision ever yet invented on this planet.

This is the one that prompted me to reply. It is not a crash-inducing design decision, but a crash-prevention design decision.

If you ever have a null reference exception, then it means your program is in a state that the programmer didn't anticipate. You can cover it up with a valid reference, but ultimately the state is still undefined. Worse, your program will probably still crash anyway, but it will happen later and in a place where it is difficult to find the original cause. Null reference exceptions pinpoint the exact place the programmer went wrong, so I make it a point to never catch them. I throw them as exceptions all the time because they are a symptom, not the cause.

If you really need a value type then use struct, not class. Or, if the object is well encapsulated, you can do something like this:

class MyClass
{
private ObjectOfSomeType myObject = new ObjectOfSomeType(); // myObject will never be null unless you set it explicitly

public MyClass()
{
// Constructor doesn't need to initialize MyObject
}
}



[The rest is spoilered so as not to clutter the thread. The ones I don't mention I either agree with (especially the type constraints with new) or am neutral on.]
+ Show Spoiler +

- Events and properties aren't first-class, which is frustrating. I can't even get a delegate pointing to the "get" method of a property without writing a big blob of reflection. I can't pass an event down to a method so that the method can fire it without making a wrapper function.

I'm not sure why you would want to do this. For events, it seems like a bad idea to release control of your events. If you really need to, you can pass an Action object via lambda with () => MyEvent(...), which saves a lot of typing. I agree it would be nice to have access to the property getters and setters, but this is only useful in the context of reflection anyway, and it doesn't take all that much to get the MethodInfo for the property's getter and setter.



- Cruft from prior versions. Three separate framework ways to parse XML nowadays. Non-generic collections that are basically obsolete implementations of the generic ones. A ton of different threading APIs (i.e. Thread, ThreadPool, BackgroundWorker, Task, BeginInvoke, and to some degree the new C# 5 async) that all solve overlapping problems.

The threading pool examples all serve very different problems that overlap only tangentially. The XML parsers make more sense in the context of mobile platforms and Silverlight where they aren't all available simultaneously.


- Type inference is spotty. Why can it infer return types of initialized local variables, but not types of initialized class properties? Why can it infer return types of anonymous functions, but not named functions? These are just arbitrary decisions.

I'm confused. It can do all of those things.

public int Blah()
{
return 5;
}

public void Blarg()
{
var a = Blah(); // works fine, a is type int
}



- No language support for purity or immutability constraints. I figured they would add an immutability check in 4.0 when they added generic covariance and contravariance, but nope.

There is the readonly keyword, which is perfectly suitable if your data is truly immutable.
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 20:04 GMT
#1478
On August 23 2011 04:09 Craton wrote:
Show nested quote +
On August 23 2011 00:09 TadH wrote:
Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool") //load code
invoice = GetInvoice() //get invoice then stores it as 'invoice'

if SensorChannel(1) ~= nil then //dunno what sensorchannel is
freeVolumeGB = 15
costPerGB = 50
currency = "$" //probably sets as USD
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024)) //calculates total gigabytes
calculateGB = sumGB - freeVolumeGB //calculates unused gigabytes
if calculateGB <= 0 then //GB can't be negative
calculateGB = 0
end

//these lines seem to add text to the invoice being made
invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

//seems to calculate the USD cost per Kilobit
if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

//adds text to invoice
invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


Added comments. You should have documentation about what else you're able to use.



I actually just found the readme file with the templates.

+ Show Spoiler +


PRTG Billing Tool Scripting Documentation
2011

To customize the billing calculations and output it is necessary to edit or write
scripts in the Lua scripting language (see Lua documentation:
http://www.lua.org/docs.html).

There are already some example scripts in the “\scripts” folder as well as example
templates in the “\templates” folder. The Billing Tool executes the script to
assign data to the template placeholders. The templates will be rendered as HTML
and PDF files afterwards.


Load Lua assembly
-----------------
To access the Billing Tool functions and data in Lua scripts, the Lua assembly
needs to be loaded:

luanet.load_assembly("Paessler.Billingtool")


Available Lua functions
-----------------------

After this step the following functions are available:

SensorChannel([channel_ID]):GetRawSum()
- Return the total bytes of the selected sensor channel for the specified
period.
- The [channel_ID] can to be found in the PRTG web interface under the
channels tab in the sensor details view.

SensorChannel([channel_ID]).Name
- Return the name of the selected sensor channel.

SensorChannel([channel_ID]).Id
- Return the ID of the selected sensor channel.

GetPercentile()
- Return the calculated percentile value for the spcified period if
available.

invoice = GetInvoice()
- Save the invoice object in the invoice variable to access invoice
functions later.

invoice:AddItem([name], [value])
- Add an item to the <#itemtable> placeholder in the template.
- With style sheets it is possible to customize the layout. Each item is
seperated into 2 columns (<td> tags).
- The columns are accessible via the CSS class "itemkey" for [name] and
"itemvalue" for [value].

invoice:SetTotal([totaltext], [totalvalue])
- Add the total value to the <#itemtable> placeholder in the template.
- The <tr> tag in the generated HTML file is accessible via the CSS ID
"total".
- Via the CSS class "totalvalue" it is possible to style the <span> tag
where the [value] will be visible.


Itemtable HTML
--------------

The following HTML is generated for the <#itemtable> placeholder:

<tr>
<td class="itemkey">
[name]
</td>
<td class="itemvalue">
[value]
</td>
</tr>
<tr id="total">
<td class="itemkey" >
[totaltext]
</td>
<td class="itemvalue">
<span class="totalvalue">[totalvalue]</span>
</td>
</tr>


So for example it says: SensorChannel([channel_ID]):GetRawSum()

Do I need to add the [ and ] or do I just add the sensor channel between the () so does it look like ([sensor channel]) or (sensor channel)

(sensor channel is the device name we're using to pull the data from, so it could be a router or a 3G card etc)

Also this: invoice:AddItem([name], [value])
- Add an item to the <#itemtable> placeholder in the template.

There is no "<#itemtable> int he template. Would I just type in <#itemtable> at the bottom of the script?

I'm just really confused, I've never had to do anything like this before. And I know it's only a basic script lol

Thanks for the help.
UltimateHurl
Profile Blog Joined September 2010
Ireland591 Posts
August 22 2011 20:19 GMT
#1479
How did I just see this thread? Did my undergrad in software engineering, about to learn lua in my spare time just because.
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 20:22 GMT
#1480
On August 23 2011 05:19 UltimateHurl wrote:
How did I just see this thread? Did my undergrad in software engineering, about to learn lua in my spare time just because.



You wanna give me a hand then? :D
Prev 1 72 73 74 75 76 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 27m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko956
Ryung 766
Rex 56
StarCraft: Brood War
Britney 36182
Sea 1417
Light 899
Mini 702
EffOrt 696
Horang2 666
Hyuk 590
Soma 570
firebathero 258
actioN 240
[ Show more ]
BeSt 225
Snow 207
Last 180
Soulkey 176
Rush 119
Leta 117
Zeus 111
hero 108
Sharp 73
NaDa 70
ToSsGirL 69
Hyun 61
JYJ 51
Movie 46
Aegong 39
Free 34
yabsab 30
GoRush 24
sorry 18
JulyZerg 16
Hm[arnc] 16
Bale 15
Sacsri 14
IntoTheRainbow 14
ajuk12(nOOB) 14
scan(afreeca) 12
zelot 10
NotJumperer 10
Rock 10
Icarus 8
Dota 2
Gorgc8918
Dendi873
XaKoH 344
BananaSlamJamma157
XcaliburYe98
Counter-Strike
x6flipin1218
zeus462
kRYSTAL_41
Other Games
singsing1742
B2W.Neo1380
hiko903
DeMusliM322
crisheroes276
Sick223
Pyrionflax166
Mew2King105
QueenE24
MindelVK3
Organizations
Dota 2
PGL Dota 2 - Main Stream18920
StarCraft: Brood War
UltimateBattle 1085
Other Games
BasetradeTV236
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 6
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• TFBlade962
Upcoming Events
OSC
2h 27m
Douyu Cup 2020
15h 27m
Neeb vs Impact
MacSed vs Cyan
Scarlett vs Kelazhur
INnoVation vs Dear
Douyu Cup 2020
1d 15h
Maestros of the Game
1d 22h
herO vs Classic
Maru vs Serral
BSL22 NKC (BSL vs China)
2 days
Douyu Cup 2020
2 days
BSL22 NKC (BSL vs China)
3 days
Online Event
3 days
RSL Revival
3 days
WardiTV Weekly
3 days
[ Show More ]
RSL Revival
4 days
RSL Revival
5 days
Kung Fu Cup
5 days
OSC
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-06-24
WardiTV Spring 2026
Heroes Pulsing #2

Ongoing

IPSL Spring 2026
Acropolis #4
CSCL: Masked Kings S4
YSL S3
BSL 22 Non-Korean Championship
CSL Season 21: Qualifier 1
CSL Season 21: Qualifier 2
SCTL 2026 Spring
Douyu Cup 2026
Maestros of the Game 2
Murky Cup 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026

Upcoming

CSL 2026 Summer (S21)
CSLAN 4
Blizzard Classic Cup 2026
Kung Fu Cup 2026 Grand Finals
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
HSC XXIX
BCC 2026
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E1
Heroes Pulsing #3
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.