Beyond lua's God language, beyond lua's God Language

Source: Internet
Author: User
Tags ffi

Beyond lua's God language, beyond lua's God Language
God is a new-generation programming language based on lua and RPP.


Why?

1. Many people do not like lua syntax. The god syntax is more like C.

2. god supports metaprogramming, closures, and coroutine.

3. All features supported by lua god are also supported, and macros not supported by lua are also supported. Therefore, god is more powerful than lua.

4. god can use the lua library, or even allow mixed programming of god and lua.

5. god is one of the fastest scripting languages, and its performance is similar to that of C, because god is based on luaJIT

6. The god compiler has only 92 lines of code. This is the simplest compiler in the world. Even cainiao can understand and modify it.

7. The god is completely open-source, and the 92 lines of code cannot open the source.


Official Website: https://github.com/roundsheep/god




God-written console:


ffi=require('ffi')ffi.cdef[#pragma pack(1) typedef struct {int dwSize;int bVisible;}CONSOLE_CURSOR_INFO;int SetConsoleCursorInfo(int hConsoleOutput,CONSOLE_CURSOR_INFO* lpConsoleCursorInfo);int system(const char* s);typedef struct {unsigned short x;unsigned short y;}COORD;int SetConsoleCursorPosition(int hConsoleOutput,COORD dwCursorPosition);int GetStdHandle(int nStdHandle);int printf(const char* fmt,...);typedef unsigned short ushort;int SetConsoleTextAttribute(int h,ushort w);short GetAsyncKeyState(int vkey);int GetTickCount();]clear=function(v){var ifor(i=1,table.maxn(v)){v[i]=null}}exist=function(v,a){var ifor(i=1,table.maxn(v)){if(v[i]==a){return true}}return false}push=function(v,a){v[table.maxn(v)+1]=a}push_front=function(v,a){var count=#vvar ifor(i=count,1,-1){v[i+1]=v[i]}v[1]=a}food=function(){g_food=math.modf(math.random()*10000)%200+1if(exist(g_arr,g_food)){food()}}update=function(){var ifor(i=1,200){gotoxy(i%10*2,math.modf(i/10))if(exist(g_arr,i)){out('■')}elif(i==g_food){out('★')}else{out('  ')}}}gotoxy=function(x,y){var pos=ffi.new('COORD',[])pos.x=xpos.y=yffi.C.SetConsoleCursorPosition(g_std_out,pos)}out=function(s){ffi.C.printf(s)}init=function(){math.randomseed(os.time())g_std_out=ffi.C.GetStdHandle(-11)g_next=10clear(g_arr)push(g_arr,105)food()var cur_info=ffi.new('CONSOLE_CURSOR_INFO',[])cur_info.dwSize=1cur_info.bVisible=0ffi.C.SetConsoleCursorInfo(g_std_out,cur_info)ffi.C.system('mode con cols=20 lines=22')ffi.C.SetConsoleTextAttribute(g_std_out,0x0a)gotoxy(0,20)out(' ******************')}key=function(){var tempif(ffi.C.GetAsyncKeyState(0x26)!=0){temp=-10}elif(ffi.C.GetAsyncKeyState(0x28)!=0){temp=10}elif(ffi.C.GetAsyncKeyState(0x25)!=0){temp=-1}elif(ffi.C.GetAsyncKeyState(0x27)!=0){temp=1}else{return}if(table.maxn(g_arr)<2||g_arr[2]!=g_arr[1]+temp){g_next=temp}}check=function(){var temp=g_arr[1]+g_nextif(temp<1||temp>200||math.abs(temp%10-g_arr[1]%10)>1||exist(g_arr,temp)){return false}return true}g_arr=[]init()var start=ffi.C.GetTickCount()while(true){key()if(ffi.C.GetTickCount()-start<100){goto continue}start=ffi.C.GetTickCount()if(!check()){break}push_front(g_arr,g_arr[1]+g_next)if(g_food!=g_arr[1]){g_arr[#g_arr]=null}else{food()}update()::continue::}



Lua is in urgent need of help

Local time1 = OS. time ();
Local time2 = OS. time ();
Local timediff = OS. difftime (time2, time1 );
Local hour = math. floor (timediff/3600 );
Local minute = math. floor (timediff-hour * 3600)/60 );
Local second = timediff % 60;
Local result = string. format ("% d hour % d minute % d second", hour, minute, second );
Print (result );
..
P.S. OS. time returns seconds. Your 3605000 is not an hour .. 1000 hours

Lua language problems

You 'd better find a Chinese version of Programming in LUA, which is detailed in the c api section.

The meanings of these functions can be viewed in reference manual of lua:
Www.lua.org/manual/5.1/manual.html#3.7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.