Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 Apr 2011
Offline Last Active Today, 01:50 AM

#5185767 Lines of code language comparisons

Posted by AzureBlaze on 08 October 2014 - 09:49 AM

You can spend time to make your code cost less line/character, and than spend even more time to make it look good.

For example:



definitely shorter than normal c code, also definitely more time coding unless you're copying it by hand.

and a day of eternity to maintain it.


I prefer longer code than shorter code, as it will be easier to read and understand. If you are doing any real programming job, you will always spend more time thinking, reading than actually typing.


Ancient Chinese literature use a different language then the spoken one. As paper was expensive, they compressed the language so they can talk about more nonsense with less money. The result is some cryptic dialect that took us years to learn and still very difficult.


If George RR Martin zip his novel in his head before writing it down and have the publisher decompress it, could he finish The Winds of Winter quicker? He'll need less finger movement. Or maybe he should learn ancient Chinese?


I think LOC is only meaningful while on logarithm scale, to help estimate the size of a project. There's definitely difference between a 1K LOC project and a 100K LOC project, but doesn't mean 200K LOC project will be always more complex than a 100K project.


Other than this, the only use of LOC is to intimidate non-programmers. Telling your designer that feature will cost 1M LOC (citation needed) will probably shut him up.

#5185707 [Solved] Lua "require" other files when loaded from memory

Posted by AzureBlaze on 08 October 2014 - 02:48 AM

Some shorter example

int MyLoader(lua_State *L){
	//load the first parameter
	//which is the name of the file, or whatever string identifier for a resource that you passed in with require()
	string filename = lua_tostring(state,1);
	if( exist_in_container(filename)){
		buffer = get_data_from_container(filename);
		//load the buffer
		luaL_loadbuffer(L,buffer.data,buffer.size, filename.c_str());
		return 1;
		lua_pushstring(L, "Error: file not found");
		return 1;

// when you initialize your lua state...

//locate the package.loaders table

//for convienice, we just replace the first one with our loader
//package.loaders[1] = MyLoader
//balance the stack.

Although I'll still recommend you to try to understand the Lua stack and interfacing with C.

#5185680 [Solved] Lua "require" other files when loaded from memory

Posted by AzureBlaze on 07 October 2014 - 10:20 PM

Lua require() uses a table called package.loaders to store functions to load modules.

The function take a file name string as parameter, and return a function (like the result of luaL_loadbuffer ) if it succeeded and a error string if failed.

require() will call these functions one by one to find a match.


you can get more info from



it will be difficult to implement such loader functions if you don't know how to write c functions for Lua

you should have a look at chapter 26 of Programming in Lua


#5177193 Font Rendering Woes (FreeType)

Posted by AzureBlaze on 31 August 2014 - 07:12 AM

I think

byte intensity = ftBitmap->buffer[y * ftBitmap->pitch + x];

should be something like

float intensity = ftBitmap->buffer[y * ftBitmap->pitch + x] / 255.0f;


#5146450 Inline for clone() function

Posted by AzureBlaze on 11 April 2014 - 10:02 PM

inline still have its' uses. Just not much for optimization


Consider if you are writing a header only library:

#pragma once
class bar;

class foo{
	bar *b;

class bar{
	bar(foo *_f):
	foo *f;

inline foo::foo()
	:b(new bar(this))

inline on foo::foo() is mandatory. it ensures the compiler and liker that no matter how many times it see the definition of foo::foo(), it will refer to a completely same function. Remove inline and you'll get a linker error because of multiple definitions.

#5146346 DRM protection

Posted by AzureBlaze on 11 April 2014 - 11:41 AM

Story: Back when I was in college we have a legit 500 user license for some expensive CAD software (donated, I think for tax reasons). But we, including the computer room, all use a cracked version which is given by the dealer. Setting up and maintaining a key server is simply too much trouble.


Some DRM cause so much trouble even legal users have to use cracked ones.

#5146244 Intellua - a Lua Editor with auto-complete support

Posted by AzureBlaze on 11 April 2014 - 07:26 AM

Recently my Lua scripts started to get out of hand because I'm adding more and more common utility functions and custom Lua classes. Remembering function signatures became more difficult and using classes without auto-complete is pure pain. I decided to improve my original Lua editor (was designed originally only to auto-complete APIs exposed from my game), and I think more people could benefit from it. I present Intellua:




Intellua is a open source (although the code is still messy and undocumented now so it is not recommended to look at it now.) C# project base on scintilla and scintillaNET that provides auto-complete via static code analysis.


Features are:

  • Auto-completion and brief document for functions, variables, class and class members.
  • Game APIs and classes can be documented with Doxygen and import into Intellua (specifically designed for those binded by luabind, but others might also apply)
  • Lua functions and classes can be declared and documented with special lua comments.
  • Object type deduction through assignments and function return type.
  • Manually assigning type for objects.
  • Independent from execution environment.

Most other Lua editors seems to support auto-complete via dynamically inspecting tables. From my past experience (might be wrong since years has past and it could improve.) the result might be messy(unneeded private stuff appears) or inacurrate(inherited members through meta-table missing). By using static analysis Intellua believe a object is what you told Intellua it is, this gives more control over the result.


Here's a demo of writing and using a simple class in Intellua


The Intellua project is hosted at http://code.google.com/p/intellua/

#5144676 Documenting scripting language in application

Posted by AzureBlaze on 06 April 2014 - 12:12 AM

I was searching for something similar, but my final solution write a documented header for Doxygen to parse. Doxygen is quite forgiving about grammar rules such as missing return type for functions so I think it should work with most scripts by writing the document similar to c++ style.


for example:

#ifdef LUA_TABLE
//! Provides generic functions for table manipulation.
class table{
	//! Given an array where all elements are strings or numbers, returns table[i]..sep..table[i+1] ... sep..table[j].
	static concat (table [, sep [, i [, j]]]);

	//! Inserts element value at position pos in table, shifting up other elements to open space, if necessary.
	static insert (table, [pos,] value);

	//! Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.
	static maxn (table);

	//! Removes from table the element at position pos, shifting down other elements to close the space, if necessary.
	static remove (table [, pos]);

	//!Sorts table elements in a given order, in-place, from table[1] to table[n], where n is the length of the table.
	static sort (table [, comp]);


results in:




I also use the generated XML for autocomplete in my script editor


#5139596 0..99 or 0..100

Posted by AzureBlaze on 16 March 2014 - 08:49 PM

In my humble opinion the only sane way to draw a line is a function that takes a laser pointer and a unicorn. People who don't do it in MY way is silly, illogical and wrong and should all destruct in Turing's hell.


There is no right and wrong here, just matters of personal preference. It is done so because it is done so in the last few decades. people are used to this way and there are nearly no big enough incentives to change.


Also I only use drawline for debbuging. I simply don't care if the last pixel is drawn or not. I iterate through the edges and get a closed polygon, I'm happy enough with that.


Your opinion here is not going to change anything. Live with it, write your own engine, try to get a position in OpenGL or DirectX and let people hate you because you break their existing code.


Or wrap it up with a adapter funciton:

void SparkleDrawLine(Laser *laser, Unicorn &unicorn){
    DrawLine((int)laser & 0xffff,(int)laser >>16, unicorn.GetRainbowTurd().size , unicorn.GetRainbowTurd().weight);

#5134398 disasembly of some function

Posted by AzureBlaze on 25 February 2014 - 06:34 AM

The 0x004XXXXX after the semicolon is the virtual address of that instruction. The 4MB skip seems to be some kind of tradition, maybe to guarantee that you will get a segmentation fault when you try to access a struct/class member of a pointer to null.


after the "_" is hex dump of the instruction:


Bytes before the "." is the main opcode of the instruction. Addtional bytes before "," specifies how the instruction interacts with other data, like read from which register or dereference the memory address in some register with some offset. the rest after ","  is additional argument for the instruction.


so for:

mov     dword [esp+0CH], 48     ; 0040217F _ C7. 44 24, 0C, 00000030

0040217F is the address of the instruction, you could use "jmp 0040217F" to make it the next instruction to execute.

"C7." means "mov", note there are multiple forms of "mov" with different opcode to move different stuff around. Though I don't know why the disassembler put the "." there, C7 itself is not complete.

"C7. " combined with "44 24," means "move a const value into the address in esp plus some offset"

"0C" is  the offset

"00000030" is the const value to move in [esp + 0x0C].


stuffs after the ";" is comment used as reference of the corresponding machine code, normally you don't need to read it unless you are doing some really low level stuff or trying to make a assembler/disassembler.


If you want to know more about how to translate assembly into machine code you could read the manuals at


x86 machine language is really, really complicated, you might want to not go further than assembly.


Or, you can have some fun with


in Programming Assignment 9 you are required to write a x86/64 assembler, which is both fun and painful.

#5098958 Yiddish indentation

Posted by AzureBlaze on 05 October 2013 - 09:40 AM

It does look funny. But let's look at it from the other point of view. I wonder how easy it is for people used to right-to-left writing to read and write source code in "established" style, which is left-to-right and as far as I encountered mainly English (language keywords, identifiers). Could someone using right-to-left languages please comment on that ?

(To take it further: Imagine a world where all programming languages are written in Kanji or something wink.png )

Traditionally Chinese, Japanese and other Kanji-related languages are written vertically, top-to-down then right-to-left. Horizontal writings are were rarer but was also right-to-left (only used on horizontal stuffs like banners, but it was more like writing vertically but change to a new column every symbol because space ran out.). But after WW2 left-to-right while horizontal became dominant. Some Taiwanese newspaper still use right-to-left for their headlines, but I found them really hard to understand.


I think because nearly all dominant culture today use left-to-right systems, everyone is accustomed to this style so there should be no problem at all (people who use Arabic might correct me).


If these vertical cultures is dominant in a alternate universe, than instead of right-to-left, it would be top-down-right-left, which I think would be more efficient on today's wide screen monitors. No need to rotate your monitor any more, which could be good. Indenting vertically is almost done in the same way and there will always be only one truly correct indention style.


Welcome to the universe where the evil but more potent Chiang Kai-shek achieved world domination



By the way, there is Chinese Python.

#4950561 Supporting 100000 objects in box2d

Posted by AzureBlaze on 19 June 2012 - 07:00 AM

1) Can box2d be scaled to use more than 100000 bodies?
2) Can box2d be scaled to do collision detection of more that 100000 shapes?

If you mean at a reasonable frame rate, No. My Core 2 Duo 2.4GHz can't deal with more than a few hundred active bodies. I don't think there are any general purpose physics engine that can deal with 100k.

4) What 2d engine can be used for rendering more than 100000 characters?

This is more a hardware problem. My on-broad Intel HD Graphics 3000 can render around 8K 32*32 sprites with same texture at 60fps, while doing game logic and rendering simple background. With some decent graphic card you could do maybe like 50K simple sprites or particles, but 100K "characters" don't sound promising.

It could be possible if you came up with some clever optimization for your game, but I'll suggest you consider that do you really need 100K.